Jekyll::Hostname

A jekyll plugin to grab the hostnames from a URL, meaning

This gem was originally authored to be used as a custom plugin for the static site of genicsblog.com

Installation

Add this line to your application’s Gemfile inside the jekyll_plugins group:

group :jekyll_plugins do
    # other gems
    gem "jekyll-hostname"
end

Then, enable the plugin by adding it to the plugins section in the _config.yml file:

plugins:
    # - other plugins
    - jekyll-hostname

And then execute:

bundle install

Usage

This plugin is essentially a filter and works on any valid URL string provided inside a liquid tag. Use it as below:

{% assign host = site.url | hostname %}
{% assign domain = post.source | hostname %}

The hostname filter extracts the root domain from the given url string(here site.url or page.source)

For example, for the following code:

{% assign domain = site.url | hostname %}
{% assign host = "https://genicsblog.com/author/gouravkhunger/" | hostname %}

the output for {{ domain }} and {{ host }} will be:

hostname.gourav.sh # {{ domain }}
genicsblog.com # {{ host }}