Retrieving the filename from jekyll #633

bhardin opened this Issue Aug 30, 2012 · 13 comments


None yet

7 participants

bhardin commented Aug 30, 2012

I have searched for a liquid tag that does this. I know their is page.url is there a filename equivalent?



I'd like this as well: be able to access a page's filename from within the page itself. My goal: to link back to the page's github repo location.

bhardin commented Nov 12, 2012

@dogweather You can hack it to get it working... This is what I did:

<a href="{{ | date: "%Y-%m-%d" }}-{{ page.title | remove: " -" | replace: " ", "-" | downcase }}.md"
kizu commented Dec 25, 2012

+1 here, right now I need to use some hakety hacks to get the desired filename:

{% assign filename = page.url %}
{% for item in page.categories %}
    {% capture remove %}{{ item }}/{% endcapture %}
    {% capture filename %}{{ filename | remove:remove }}{% endcapture %}
{% endfor %}

{% capture filename %}{% unless filename == '/en/' or filename == '/index.html' %}_posts/{% endunless %}{% if page.categories contains 'en' %}en/{% endif %}{{ | date: "%Y-%m-%d-" }}{% if filename == '/en/' %}index_{% endif %}{{ filename | remove:'/' | remove_first:'.html' }}{% unless filename == '/en/' or filename == '/index.html' %}.md{% else %}.html{% endunless %}{% endcapture %}

'cause I have /:categories/:title permalink I need to remove all the categories from the page.url at first, then there are a lot of things happen at the capture, 'cause I have multilingual blog and have both .md and .html pages here. And I think I'll tweak this code a bit more in the future, so having a way to retrieve the page's initial url would be really helpful.

parkr commented Dec 26, 2012

I can't think of any reason why you should be linking to the filename or need to extract any information that isn't already available to you. Can you provide me with a use case? I don't understand why you're doing that, @kizu.

kizu commented Dec 26, 2012

@parkr The reason is to provide a link to the source file on each page, so it would be easy for anyone to go and fork the page to fix or add something. It's somewhat popular — I've seen people making it a few times, like here(see “Jekyll” and “Liquid” sections) or there

bhardin commented Dec 27, 2012

This is the same use case I had. I use it on Example:

dhcole commented Mar 5, 2013

Pulled this out into a separate plugin:

Our use case is that we want to link multilingual posts by file name ( and This makes allows us to keep the title and url free to be translated, but still have a way to link posts. We can use the post_url filter to figure out translated post's url.

guileen commented Mar 18, 2013

👍 for filename

guileen commented Mar 18, 2013

I use this

{% assign filename = page.url | replace_first: '/', '' | replace: '/', '-'  | replace: '.html', '.md' %}
<a href="{{filename}}">View on github</a>
<a href="{{filename}}">History</a>

My use case: Making Jekyll into an un-wiki: each page has a link to its github edit location. For example:

guileen commented Mar 18, 2013

@dogweather How do you generate the Edit link of tutorial page? I didn't found the code in your repo


It looks good, doesn't it? :-) But it's an ugly hack:

In each page's header, I add a filename attribute with the file's path. E.g.

layout: page
title: "Tutorials"
verbose_title: "Wikified Ruby and Rails Tutorial Listing"
description: "Tutorials and guides for learning Ruby and Rails"
filename: "pages/"

Then, my html template pulls that out:

<a href="{{page.filename}}" class="btn">Edit</a>

@parkr parkr closed this in d64fd1e Apr 12, 2013
@bamos bamos referenced this issue in bamos/ Dec 6, 2014
@bamos bamos Link to every post's source. 7a65d36
@i2000s i2000s referenced this issue Jul 21, 2016

post['name'] and changes #5121

8 of 17 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment