View Markdown button on posts page

I’m having a brain freeze :frowning: Currently there is a More/Less button on blog posts:

Pippim post need edit button for admin

Next to the “More”/“Less” button I’d like to place a “Markdown” button so the user (OK well me) can view how the Kramdown is setup for this page.

I’m having trouble wrapping my head around how the Markdown button needs to create the Liquid//Kramdown in order to open the _posts/ file in GitHub Repo in a new window / tab in the browser.

Here’s the live link to the recorded .gif example above

In URL-Speak the link is:

In G-H-Pages-Speak the link is:

In Jekyll-Speak the link is:


Because there were over 1000 _posts I had to divide them into the years 2016 to 2022 otherwise GitHub wouldn’t display all the files (the maximum in GitHub is 1,000 displayable filenames per directory)…

I’ve looked at slugify: pretty but that didn’t help much. How do I get Liquid to return the GitHub Repo Post filename URL from the Jekyll Post filename?

Hopefully I am not missing anything and this is an easy fix.

In your _config.yml, add a variable that represents your GitHub Pages code link. In my case, I am calling it code_url, but you can call it anything.

Anywhere in your _config.yml file, put the following two lines:

# Link to content on the repo

(note: you may or may not have to add a / at the end of that line… you will have to test.

Now, in your code, you will use assign to prepend the code_url. Here is an example that gets all the posts in your site and adds a direct link to the GitHub repo markdown file:

{% for post in site.posts %}
    title: {{ post.title }}
    {% assign repo_url = post.url | prepend: site.code_url %}
    repo_url: {{ repo_url }}
{% endfor %}

Thank you for your answer. I’ll try a variation of your code and report back.