Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: sort items by date in the generated feed #1

Open
jcollas opened this issue Jun 3, 2021 · 1 comment
Open

Feature request: sort items by date in the generated feed #1

jcollas opened this issue Jun 3, 2021 · 1 comment

Comments

@jcollas
Copy link

jcollas commented Jun 3, 2021

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.

@chambln
Copy link
Owner

chambln commented Jun 3, 2021

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.

chambln added a commit that referenced this issue Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants