From 527c9862b0cc50e711dcf3e27be9eb957c4f3278 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Tue, 5 Nov 2024 18:54:07 -0500 Subject: feat: hide posts by using publish: false in frontmatter --- README.md | 5 ++++- ssg-blog | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ea3d2e1..052036e 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ This is a modification to the simple static site generator '[ssg](https://romanz See [https://romansolotarev.com/ssg.html](https://romanzolotarev.com/ssg.html) for documentation on ssg -1. Install [lowdown](https://kristaps.bsd.lv/lowdown/) +1. Install [lowdown](https://kristaps.bsd.lv/lowdown/) and cpio 2. Copy the `ssg-blog` script somewhere in your path, e.g. `/usr/bin/` 3. `chmod +x /usr/bin/ssg-blog` 4. `ssg-blog src dst 'https://my-website.net'` @@ -19,9 +19,12 @@ ssg-blog checks for subdirectories in the src directory, each of which becomes a --- title: My Blog Post date: 2024-10-09 +publish: false --- ``` +If you add `pubish: false` to the frontmatter, the post will not show up in the index (it will still be rendered and appear in the sitemap) + ## Example There is an example directory in this repo to show you how to set up the files (src) and what the output looks like (dst). This was the command used to generate the example output: diff --git a/ssg-blog b/ssg-blog index d70c5bb..3361b03 100755 --- a/ssg-blog +++ b/ssg-blog @@ -204,7 +204,6 @@ list_pages() { sed 's#^./##;s#.md$#.html#;s#/index.html$#/#' } - render_index() { output="$dst/index.html" echo "$HEADER" > "$output" @@ -215,16 +214,18 @@ 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) - article_url="${article#"$src"}" article_url="${article_url%.md}.html" if [ "${article_url##*/}" = "index.html" ]; then article_url="${article_url%/index.html}/" fi article_url="${article_url#/}" - echo "$date|$title|$article_url" >> "/tmp/articles_$category.txt" done @@ -241,7 +242,6 @@ render_index() { echo "$FOOTER" >> "$output" } - render_sitemap() { urls="$1" base_url="$2" -- cgit v1.2.3