pandoc-rss
pandoc-rss copied to clipboard
Feature request: sort items by date in the generated feed
I've got dozens of markdown files I'd like to have by reverse date order in the generated feed. Maybe a flag to either sort by ascending/descending, or just the order specified when running the command.
Feed items are generated in the order specified on the command-line. For example,
pandoc-rss a.md b.md c.md d.md
will generate feed items for a, b, c and d—in that order. So you'd have to find a way to list your markdown files in reverse chronological order before passing them to pandoc-rss.
Bit of a hack, but this should do the trick as long as your markdown file names contain no tabs or spaces:
for i in ./*.md; do
printf '%s ' "$i"
pandoc --template=share/pandoc-rss/data/templates/date.value "$i"
done | while IFS=' ' read i d; do
printf '%s\t%s\n' "$(date -d "$d" +%Y%m%d%T)" "$i"
done | LANG= sort -r | cut -f2
It works by printing the date of each markdown file next to its filename—as shown below—then piping through sort(1) with the reverse flag -r.
2021053100:00:00 ./a.md
2021060100:00:00 ./b.md
2021060200:00:00 ./c.md
2021060300:00:00 ./d.md
It would be nice if pandoc-rss could take care of it though. I may have a go at refactoring it to make that possible. In any case, is it not the feed reader that is responsible for sorting items chronologically? I know mine does.