I'm trying to extract the file name from a url on Jekyll using this ruby snippet:
{% assign filename = page.url.split('/')[-1] | replace: '.html', '.md' %}
If I just use:
{% assign filename = page.url | replace: '.html', '.md' %}
I get back the url with the replaced file type but my .split('/')[-1]
doesn't seem to work.
I tried running the following in standalone ruby to ensure my syntax was right, and it returned bird
as expected:
"cat/dog/bird".split('/')[-1]
Why doesn't the same syntax work in my Jekyll instance? Is it that page.url
isn't a string, or something else?