diff options
| author | historia <gravel.justness270@slmail.me> | 2024-10-09 21:02:56 -0400 |
|---|---|---|
| committer | historia <gravel.justness270@slmail.me> | 2024-10-09 21:02:56 -0400 |
| commit | e5fb80009b6c248a41e47eeb9a11f506bb85047b (patch) | |
| tree | 39a0635a511c103a8c75185edaaa798de6d8442e | |
| parent | 85cc20507d3541b62d06ec60ad0dc719b6244966 (diff) | |
| download | ssg-blog-e5fb80009b6c248a41e47eeb9a11f506bb85047b.tar.gz | |
refactor: removed title argument to simplify code
| -rw-r--r-- | README.md | 24 | ||||
| -rw-r--r-- | example/dst/404.html | 2 | ||||
| -rw-r--r-- | example/dst/Articles/an-interesting-article/index.html | 2 | ||||
| -rw-r--r-- | example/dst/Articles/another-interesting-article/index.html | 2 | ||||
| -rw-r--r-- | example/dst/Articles/article3.html | 2 | ||||
| -rw-r--r-- | example/dst/Lists/board-games.html | 2 | ||||
| -rw-r--r-- | example/dst/Lists/movies.html | 2 | ||||
| -rw-r--r-- | example/dst/about.html | 2 | ||||
| -rw-r--r-- | example/dst/hed | 28 | ||||
| -rw-r--r-- | example/dst/index.html | 2 | ||||
| -rw-r--r-- | example/dst/style.css | 2 | ||||
| -rw-r--r-- | example/example.webp | bin | 0 -> 15022 bytes | |||
| -rw-r--r-- | example/src/_header.html | 2 | ||||
| -rw-r--r-- | example/src/style.css | 2 | ||||
| -rwxr-xr-x | ssg-blog | 59 |
15 files changed, 45 insertions, 88 deletions
@@ -1,16 +1,17 @@ # ssg-blog -This is a modification to the simple static site generator '[ssg](https://romanzolotarev.com/bin/ssg)' by Roman Zolotarev. This generates a minimal blog index page with category headings. +This is a modification to the simple static site generator '[ssg](https://romanzolotarev.com/bin/ssg)' by Roman Zolotarev. This generates a minimal blog index page with category headings and posts sorted by date using YAML frontmatter in markdown files. + + # Install / Usage See [https://romansolotarev.com/ssg.html](https://romanzolotarev.com/ssg.html) for documentation on ssg -In short: 1. Install [lowdown](https://kristaps.bsd.lv/lowdown/) -2. Copy the `ssg` script somewhere in your path, e.g. `/usr/bin/` -3. `chmod +x /usr/bin/ssg` -4. `ssg src dst 'my-website-name' 'https://my-website.net'` +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'` 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: @@ -23,12 +24,17 @@ date: 2024-10-09 ## 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). Note how articles can be nested in subdirectories or not and that the articles titled index.md get links created without .html appended. This was the command used to generate the example output: +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: ``` -./ssg-blog example/src example/dst 'example-site-name' 'https://example.org' +./ssg-blog example/src example/dst 'https://example.org' ``` +Note a few things about the output: +1. Markdown files can be nested in subdirectories or not. +2. Files named index.md will get have a link generated without <filename>.html at the end. +3. Files outside subdirectories (e.g. about.md) will be rendered but won't show up on the index. + ## Change how categories are sorted The category headings are sorted alphabetically. If you want to change this, you have to edit the `sort` on this line: @@ -37,6 +43,10 @@ The category headings are sorted alphabetically. If you want to change this, you 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. Now `render_html_file` just outputs the header file, output from lowdown, then the footer file with no modifications. + # Alternatives You might also be interested in the similar fork [fmash16/ssg5](https://github.com/fmash16/ssg5) which generates a more traditional blog with pagination, keywords, and post previews. diff --git a/example/dst/404.html b/example/dst/404.html index b56836c..4a91725 100644 --- a/example/dst/404.html +++ b/example/dst/404.html @@ -22,7 +22,7 @@ </a> <div id="navigation"> <a href="https://example.org/">Home</a> - -<a href="https://codeberg.org">Repos</a> - +<a href="https://codeberg.org/">Repos</a> - <a href="https://example.org/about.html">About</a> </div> </div> diff --git a/example/dst/Articles/an-interesting-article/index.html b/example/dst/Articles/an-interesting-article/index.html index 412e359..8e65041 100644 --- a/example/dst/Articles/an-interesting-article/index.html +++ b/example/dst/Articles/an-interesting-article/index.html @@ -22,7 +22,7 @@ </a> <div id="navigation"> <a href="https://example.org/">Home</a> - -<a href="https://codeberg.org">Repos</a> - +<a href="https://codeberg.org/">Repos</a> - <a href="https://example.org/about.html">About</a> </div> </div> diff --git a/example/dst/Articles/another-interesting-article/index.html b/example/dst/Articles/another-interesting-article/index.html index 31ef880..010c0f1 100644 --- a/example/dst/Articles/another-interesting-article/index.html +++ b/example/dst/Articles/another-interesting-article/index.html @@ -22,7 +22,7 @@ </a> <div id="navigation"> <a href="https://example.org/">Home</a> - -<a href="https://codeberg.org">Repos</a> - +<a href="https://codeberg.org/">Repos</a> - <a href="https://example.org/about.html">About</a> </div> </div> diff --git a/example/dst/Articles/article3.html b/example/dst/Articles/article3.html index e34e43a..75783b7 100644 --- a/example/dst/Articles/article3.html +++ b/example/dst/Articles/article3.html @@ -22,7 +22,7 @@ </a> <div id="navigation"> <a href="https://example.org/">Home</a> - -<a href="https://codeberg.org">Repos</a> - +<a href="https://codeberg.org/">Repos</a> - <a href="https://example.org/about.html">About</a> </div> </div> diff --git a/example/dst/Lists/board-games.html b/example/dst/Lists/board-games.html index 1693d1b..5a54f33 100644 --- a/example/dst/Lists/board-games.html +++ b/example/dst/Lists/board-games.html @@ -22,7 +22,7 @@ </a> <div id="navigation"> <a href="https://example.org/">Home</a> - -<a href="https://codeberg.org">Repos</a> - +<a href="https://codeberg.org/">Repos</a> - <a href="https://example.org/about.html">About</a> </div> </div> diff --git a/example/dst/Lists/movies.html b/example/dst/Lists/movies.html index a3499e5..dc7fc57 100644 --- a/example/dst/Lists/movies.html +++ b/example/dst/Lists/movies.html @@ -22,7 +22,7 @@ </a> <div id="navigation"> <a href="https://example.org/">Home</a> - -<a href="https://codeberg.org">Repos</a> - +<a href="https://codeberg.org/">Repos</a> - <a href="https://example.org/about.html">About</a> </div> </div> diff --git a/example/dst/about.html b/example/dst/about.html index 51897a4..89a14bf 100644 --- a/example/dst/about.html +++ b/example/dst/about.html @@ -22,7 +22,7 @@ </a> <div id="navigation"> <a href="https://example.org/">Home</a> - -<a href="https://codeberg.org">Repos</a> - +<a href="https://codeberg.org/">Repos</a> - <a href="https://example.org/about.html">About</a> </div> </div> diff --git a/example/dst/hed b/example/dst/hed deleted file mode 100644 index d90b226..0000000 --- a/example/dst/hed +++ /dev/null @@ -1,28 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> -<head> - <meta charset="UTF-8"> - <link rel="icon" type="image/png" href="https://example.org/favicon.png"> - <link rel="stylesheet" href="style.css"> - <title>Example</title> -</head> -<body> -<div class="container"> -<a id="header" href="https://example.org"> -<pre> - -▄███▄ ▄ ██ █▀▄▀█ █ ▄▄ █ ▄███▄ -█▀ ▀ ▀▄ █ █ █ █ █ █ █ █ █ █▀ ▀ -██▄▄ █ ▀ █▄▄█ █ ▄ █ █▀▀▀ █ ██▄▄ -█▄ ▄▀ ▄ █ █ █ █ █ █ ███▄ █▄ ▄▀ -▀███▀ █ ▀▄ █ █ █ ▀ ▀███▀ - ▀ █ ▀ ▀ - ▀ -</pre> -</a> -<div id="navigation"> -<a href="https://example.org/">Home</a> - -<a href="https://codeberg.org">Repos</a> - -<a href="https://example.org/about.html">About</a> -</div> -</div> diff --git a/example/dst/index.html b/example/dst/index.html index 8deec2f..86ad95d 100644 --- a/example/dst/index.html +++ b/example/dst/index.html @@ -22,7 +22,7 @@ </a> <div id="navigation"> <a href="https://example.org/">Home</a> - -<a href="https://codeberg.org">Repos</a> - +<a href="https://codeberg.org/">Repos</a> - <a href="https://example.org/about.html">About</a> </div> </div> diff --git a/example/dst/style.css b/example/dst/style.css index 4489ae8..5080521 100644 --- a/example/dst/style.css +++ b/example/dst/style.css @@ -46,7 +46,7 @@ a:hover, a:focus { } li + li { - margin-top:1em; + margin-top:0.2em; } ul img { diff --git a/example/example.webp b/example/example.webp Binary files differnew file mode 100644 index 0000000..d9153d9 --- /dev/null +++ b/example/example.webp diff --git a/example/src/_header.html b/example/src/_header.html index d90b226..a0923f4 100644 --- a/example/src/_header.html +++ b/example/src/_header.html @@ -22,7 +22,7 @@ </a> <div id="navigation"> <a href="https://example.org/">Home</a> - -<a href="https://codeberg.org">Repos</a> - +<a href="https://codeberg.org/">Repos</a> - <a href="https://example.org/about.html">About</a> </div> </div> diff --git a/example/src/style.css b/example/src/style.css index 4489ae8..5080521 100644 --- a/example/src/style.css +++ b/example/src/style.css @@ -46,7 +46,7 @@ a:hover, a:focus { } li + li { - margin-top:1em; + margin-top:0.2em; } ul img { @@ -20,12 +20,12 @@ main() { test -n "$1" || usage test -n "$2" || usage test -n "$3" || usage - test -n "$4" || usage test -d "$1" || no_dir "$1" test -d "$2" || no_dir "$2" src=$(readlink_f "$1") dst=$(readlink_f "$2") + base_url="$3" IGNORE=$( if ! test -f "$src/.ssgignore"; then @@ -40,8 +40,6 @@ main() { # files - title="$3" - h_file="$src/_header.html" f_file="$src/_footer.html" test -f "$f_file" && FOOTER=$(cat "$f_file") && export FOOTER @@ -64,11 +62,11 @@ main() { if echo "$fs" | grep -q '\.md$'; then if test -x "$(which lowdown 2>/dev/null)"; then echo "$fs" | grep '\.md$' | - render_md_files_lowdown "$src" "$dst" "$title" + render_md_files_lowdown "$src" "$dst" else if test -x "$(which Markdown.pl 2>/dev/null)"; then echo "$fs" | grep '\.md$' | - render_md_files_Markdown_pl "$src" "$dst" "$title" + render_md_files_Markdown_pl "$src" "$dst" else echo "couldn't find lowdown nor Markdown.pl" exit 3 @@ -77,7 +75,7 @@ main() { fi echo "$fs" | grep '\.html$' | - render_html_files "$src" "$dst" "$title" + render_html_files "$src" "$dst" echo "$fs" | grep -Ev '\.md$|\.html$' | (cd "$src" && cpio -pu "$dst") @@ -86,20 +84,20 @@ main() { printf '[ssg] ' >&2 print_status 'file, ' 'files, ' "$fs" >&2 + #index + + render_index + # sitemap - base_url="$4" date=$(date +%Y-%m-%d) urls=$(list_pages "$src") test -n "$urls" && render_sitemap "$urls" "$base_url" "$date" >"$dst/sitemap.xml" - render_index - print_status 'url' 'urls' "$urls" >&2 echo >&2 - } readlink_f() { @@ -126,7 +124,7 @@ print_status() { } usage() { - echo "usage: ${0##*/} src dst title base_url" >&2 + echo "usage: ${0##*/} src dst base_url" >&2 exit 1 } @@ -168,7 +166,7 @@ list_affected_files() { render_html_files() { while read -r f; do - render_html_file "$3" <"$1/$f" >"$2/$f" + render_html_file <"$1/$f" >"$2/$f" done } @@ -180,8 +178,7 @@ render_md_files_lowdown() { --html-no-skiphtml \ --parse-no-metadata \ --parse-no-autolink | - render_html_file "$3" \ - >"$2/${f%\.md}.html" + render_html_file >"$2/${f%\.md}.html" done } @@ -189,38 +186,16 @@ render_md_files_Markdown_pl() { while read -r f; do sed '1 { /^---/ { :a N; /\n---/! ba; d} }' "$1/$f" | Markdown.pl | - render_html_file "$3" \ - >"$2/${f%\.md}.html" + render_html_file >"$2/${f%\.md}.html" done } render_html_file() { - # h/t Devin Teske - awk -v title="$1" ' - { body = body "\n" $0 } - END { - body = substr(body, 2) - if (body ~ /<\/?[Hh][Tt][Mm][Ll]/) { - print body - exit - } - if (match(body, /<[[:space:]]*[Hh]1(>|[[:space:]][^>]*>)/)) { - t = substr(body, RSTART + RLENGTH) - sub("<[[:space:]]*/[[:space:]]*[Hh]1.*", "", t) - gsub(/^[[:space:]]*|[[:space:]]$/, "", t) - if (t) title = t " — " title - } - n = split(ENVIRON["HEADER"], header, /\n/) - for (i = 1; i <= n; i++) { - if (match(tolower(header[i]), "<title></title>")) { - head = substr(header[i], 1, RSTART - 1) - tail = substr(header[i], RSTART + RLENGTH) - print head "<title>" title "</title>" tail - } else print header[i] - } - print body - print ENVIRON["FOOTER"] - }' + { + echo "$HEADER" + cat - + echo "$FOOTER" + } } list_pages() { |
