Skip to content

Conversation

@mrled
Copy link

@mrled mrled commented May 2, 2025

Hello,

I added a sorting method based on weight in the frontmatter of Hugo markdown files.

Weight is a concept in Hugo that affects the order of items in a list. Normally items might be ordered alphabetically or by creation date, and weight allows overriding that order.

This is just a proof of concept. It only supports Markdown files with .md suffix and YAML frontmatter. I'm interested in taking this further depending on feedback.

A future version could improve by:

  • Supporting all of Hugo's frontmatter types, including TOML and JSON
  • Supporting all of Hugo's content formats (possibly starting with just Markdown and HTML which are built in) and file extensions (markdown, md, mdown, htm, html)
  • Allow sorting by content date, which is especially useful for blogs; a robust implementation would understand multiple types of dates
  • Parsing frontmatter via a real parser instead of regex - although I'm torn on this, as real parsers have the disadvantage of requiring libraries.

Add a configMode configuration parameter to select between .order and
Hugo weights

In Hugo mode, read YAML frontmatter in Markdown files to find the
weight key.

In a directory where weight is present, sort by weight first, and any
files without a weight parameter sorted alphabetically after.

The special Hugo _index.md file is always displayed first in a
directory.

Sort directories based on the weight of its _index.md files, if
specified.
@mrled mrled force-pushed the add-hugo-weight-sort branch from ef129a7 to 0451373 Compare May 2, 2025 22:11
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

Successfully merging this pull request may close these issues.

1 participant