jekyll - Is there a liquid filter to limit a url to the domain name only? -
i'm wondering if there liquid filter limit url domain name only.
for example, let's wanted have link article called "the greatest article ever" , url unwieldily http://example.com/long/ugly/directory/123948/name. let's had both of these values in yaml metadata in array "title:" , "url:" respectively, , desired output this:
<div class="cool-articles"> <a href="http://example.com/long/ugly/directory/123948/name"> greatest article ever </a> <span>example.com</span> </div>
how might use liquid limit array-item.url domain name only?
i've been searching through liquid docs nice filter it, i've found remove (which can nix "http://") nothing strip out domain name.
anyone have thoughts?
thanks!
well, can try split url on slashes (after removing "http://") , first element of resulting array. example:
{{ url | remove:'http://' | split:'/' | first }}
i didn't test it, should work reasonably part. pipeline in place, need construct output said:
<div class="cool-articles"> <a href="{{ url }}"> {{ title }} </a> <span>{{ url | remove:'http://' | split:'/' | first }}</span> </div>
i hope helps. :)
Comments
Post a Comment