Blog Reverse Sort with Mkdocs

The current implementation of Mkdocs, is that if you do not provide a navigation path in the mkdocs.yml file, that it will build the website based on the file structure. When it comes to providing documentation, this is perfectly fine. However, when it comes to blogging, this presents a problem.

Most blogging tools, have the most recent content listed first and the oldest last. The only way that I have been able to find out how to do this is to list the pages of the site in the navigation in reverse order.

I currently name my files with the following format:

yyyy-mm-dd-title

where "yyyy" is the year, "mm" is the month, "dd" is the day, and "title" is the title of the post.

In Linux based systems, you can list the files by filename and they will sort in order. Since I want the files to be listed in reverse order, I run the below command from the docs directory.

find . | sort -r | sed "s|\./|  - blog/|g"

I get an output similar to the following:

  - blog/2019-11-24-takeaways-from-christopher-robin-movie.md
  - blog/2019-09-05-copying-infested-code.md
  - blog/2019-07-23-markdown-my-words.md
  - blog/2019-07-04-when-deploying-before-testing.md
  - blog/2019-07-03-squirrels-taught-me-about-women-and-food.md

With this output, I am able to copy and paste it directly into the mkdocs.yml file. At the writing of this post, I have not been able to figure out how to do grouping with a command line, so I have to manually group the files by year.

Updated: 2020-07-15 | Posted: 2019-12-20