diff options
| author | historia <[not public]> | 2025-03-29 18:51:09 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2025-03-29 18:51:09 -0400 |
| commit | 8b8344809224b26d43269579ab221298d5dcbb49 (patch) | |
| tree | 7b1a1bdaf1256312b8a4baa335a6bb3b917f27fd | |
| parent | b81022054df182715fce4111925dd8e81c1040bf (diff) | |
| download | ssg-blog-8b8344809224b26d43269579ab221298d5dcbb49.tar.gz | |
feat: don't include page on index if no date frontmatter
| -rw-r--r-- | README.md | 6 | ||||
| -rwxr-xr-x | ssg-blog | 6 |
2 files changed, 7 insertions, 5 deletions
@@ -13,7 +13,7 @@ See [https://romansolotarev.com/ssg.html](https://romanzolotarev.com/ssg.html) f 3. `chmod +x /usr/bin/ssg-blog` 4. `ssg-blog src dst 'https://my-website.net'` -ssg-blog checks for subdirectories in the src directory, each of which becomes a category heading (non-recursively). It will generate a sorted list of links to any .md file in those directory (including nested directories). Each .md file requires frontmatter including the title and a YYYY-MM-DD date like this to be included in the index page: +ssg-blog checks for subdirectories in the src directory, each of which becomes a category heading (non-recursively). It will generate a sorted list of links to any .md file in those directory (including nested directories). Each .md file may include frontmatter with the title and a YYYY-MM-DD date like this to be included in the index page: ```markdown --- @@ -23,7 +23,9 @@ publish: false --- ``` -If you add `publish: false` to the frontmatter, the post will not show up in the index (it will still be rendered and appear in the sitemap). This field is optional otherwise. +If a file has no frontmatter, no `date`, or `publish: false`, the page won't be included in the index. It will still be rendered in sitemap.xml. + +Setting `publish: true` is optional and equivalent to not having `publish` at all. ## Example @@ -217,11 +217,11 @@ render_index() { find "$category_dir" -type f \( -name "*.md" -o -name "index.md" \) ! -path "*/.*" | while read -r article; do publish=$(sed -n '/^publish: /s/^publish: //p' "$article" | head -n 1) - if [ "$publish" = "false" ]; then - continue - fi title=$(sed -n '/^title: /s/title: //p' "$article" | head -n 1) date=$(sed -n '/^date: /s/date: //p' "$article" | head -n 1) + if [ "$publish" = "false" ] || [ -z "$date" ]; then + continue + fi article_url="${article#"$src"}" article_url="${article_url%.md}.html" if [ "${article_url##*/}" = "index.html" ]; then |
