Better Way of Auto Generating ToC

When working on a project I keep documentation in a gh-pages branch and tend to organize each topic in a different markdown file.  Since I am always adding new markdown files as the project gets bigger, I generate a list of links to these files through a liquid for-loop in the file:

{% for file in site.static_files %}
{% if file.extname == ".md" %}
[{{ file.basename }}]({{site.baseurl}}/{{file.basename}}.html)
{% endif %}
{% endfor %}

This will generate a list of links such as:


I figure there’s got to be a better way to write


If you use:


 GitHub Pages will direct your browser to the vanilla markdown file and your browser will display only the text of the markdown file.  Yet when inserting a direct link through markdown to .md file, it will be generated as an HTML file, such as

(link)[] -> Links to link.html with styling applied

Is there a better way to generate a table of contents for all markdown files in your gh-pages directory?

To my knowledge, if you want the list of all Markdown files in your Pages site or even the list of all Markdown files in the root of your Pages site, that’s the way to do it. If you wanted to move your Markdown files down one level so that they could be addressed as a Collection, then there might be other options?