From b81022054df182715fce4111925dd8e81c1040bf Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Mon, 18 Nov 2024 16:46:57 -0500 Subject: feat: automatically populate with blog post name --- README.md | 6 +++--- ssg-blog | 22 ++++++++++++---------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index ad37768..f394d21 100644 --- a/README.md +++ b/README.md @@ -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 needs 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 requires frontmatter including the title and a YYYY-MM-DD date like this to be included in the index page: ```markdown --- @@ -23,7 +23,7 @@ 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) +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. ## Example @@ -48,7 +48,7 @@ find "$src" -mindepth 1 -maxdepth 1 -type d ! -path "*/.*" | sort | # Differences from ssg -The title argument from ssg is unnecessary so I've removed it. `render_html_file` used it to modify the first `<h1>` tag and auto-populate the `<title>` if none is specified, which is functionality I've never needed. +The title argument from ssg is unnecessary so I've removed it. `render_html_file` used it to modify the first `<h1>` tag and auto-populate the `<title>` if none is specified, which is functionality I've never needed. Instead I check the frontmatter of each blog post and update the `<title>` tag with the `title:` field. # Alternatives diff --git a/ssg-blog b/ssg-blog index 3361b03..9ea93d0 100755 --- a/ssg-blog +++ b/ssg-blog @@ -172,21 +172,23 @@ render_html_files() { render_md_files_lowdown() { while read -r f; do - sed '1 { /^---/ { :a N; /\n---/! ba; d} }' "$1/$f" | - lowdown \ - --html-no-escapehtml \ - --html-no-skiphtml \ - --parse-no-metadata \ - --parse-no-autolink | - render_html_file >"$2/${f%\.md}.html" + title=$(sed -n '/^title: /s/^title: //p' "$1/$f" | head -n 1) + content=$(sed '1 { /^---/ { :a N; /\n---/! ba; d} }' "$1/$f") + html_content=$(echo "$content" | lowdown --html-no-escapehtml --html-no-skiphtml --parse-no-metadata --parse-no-autolink) + echo "$HEADER" | sed "s|<title>.*|$title|" > "$2/${f%\.md}.html" + echo "$html_content" >> "$2/${f%\.md}.html" + echo "$FOOTER" >> "$2/${f%\.md}.html" done } render_md_files_Markdown_pl() { while read -r f; do - sed '1 { /^---/ { :a N; /\n---/! ba; d} }' "$1/$f" | - Markdown.pl | - render_html_file >"$2/${f%\.md}.html" + title=$(sed -n '/^title: /s/^title: //p' "$1/$f" | head -n 1) + content=$(sed '1 { /^---/ { :a N; /\n---/! ba; d} }' "$1/$f") + html_content=$(echo "$content" | Markdown.pl) + echo "$HEADER" | sed "s|.*|$title|" > "$2/${f%\.md}.html" + echo "$html_content" >> "$2/${f%\.md}.html" + echo "$FOOTER" >> "$2/${f%\.md}.html" done } -- cgit v1.2.3