Is there way to sort *.md files according to publish date value with bash script?

I am writing a blog and I am saving these blog posts with markdown file format. The file contains the release date and the update date. I can call the information I need, for example, the release date with the help of the lowdown tool. So far everything is going fine. but I couldn't find a way to do this when I want to sort by publish date for my index page.

Note: The date format i am using; YYYY-MM-DD

As an example of the result I am trying to reach;

(assuming we're looping through the directory containing the blog posts)

for post in *.md; do
    title=$(lowdown -X title $post)
    date=$(lowdown -X date $post)
    <h1>$date</h1>
    <h1>$title</h1>
done

The output gives natural order(i think).

2021-10-02 2th Post
2021-10-04 Last Post
...

My expectation is sort them with $date values.

2021-10-04  Last Post
2021-10-03  3th Post
2020-10-02  2th Post
2019-10-01  1th Post


from Recent Questions - Stack Overflow https://ift.tt/3xXf59Z
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation