How to get domain name from URL?

For example, I have this URL

https://www.example.com/a/c/d/e/g

and I only want

example.com

How to do that?


Here’s what I did

Hey, you can use the plugin I made for this functionality: jekyll-hostname.

After installation it’s as easy as:

{% assign host = "https://www.example.com/a/c/d/e/g" | hostname %}
{{ host }} {% comment %} Renders example.com {% endcomment %}

I hope this helps!