From 366df8852f503523cc4f9046d82ba9a99dd51d7f Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 12 Feb 2023 12:13:49 +0530 Subject: new art: lapse --- docs/posts/static_sites_with_bash/index.html | 36 +++++++++++++++++++++------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'docs/posts/static_sites_with_bash') diff --git a/docs/posts/static_sites_with_bash/index.html b/docs/posts/static_sites_with_bash/index.html index 07313be..6921529 100644 --- a/docs/posts/static_sites_with_bash/index.html +++ b/docs/posts/static_sites_with_bash/index.html @@ -28,7 +28,7 @@ 23/11 — 2019
- 21.17 + 21.18 cm   @@ -42,12 +42,22 @@ Static Sites With Bash
-

After going through a bunch of static site generators (pelican, hugo, vite), I decided to roll my own. If you are more of the ‘show me the code’ kinda guy, here you go.

+

After going through a bunch of static site generators (pelican, hugo, vite), I decided to roll my +own. If you are more of the ‘show me the code’ kinda guy, here you go.

Text formatting

-

I chose to write in markdown, and convert to html with lowdown.

+

I chose to write in markdown, and convert to html with lowdown.

Directory structure

-

I host my site on GitHub pages, so docs/ has to be the entry point. Markdown formatted posts go into posts/, get converted into html, and end up in docs/index.html, something like this:

-
posts=$(ls -t ./posts)     # chronological order!
+

I host my site on GitHub pages, so docs/ has to be the +entry point. Markdown formatted posts go into posts/, get +converted into html, and end up in docs/index.html, +something like this:

+
posts=$(ls -t ./posts)     # chronological order!
 for f in $posts; do
     file="./posts/"$f      # `ls` mangled our file paths
     echo "generating post $file"
@@ -56,19 +66,27 @@
     echo -e "html" >> docs/index.html
 done

Assets

-

Most static site generators recommend dropping image assets into the site source itself. That does have it’s merits, but I prefer hosting images separately:

-
# strip file extension
+

Most static site generators recommend dropping image assets into the +site source itself. That does have it’s merits, but I prefer hosting +images separately:

+
# strip file extension
 ext="${1##*.}"
 
 # generate a random file name
-id=$( cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 2 | head -n 1 )
+id=$( cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 2 | head -n 1 )
 id="$id.$ext"
 
 # copy to my file host
 scp -P 443 "$1" emerald:files/"$id" 
 echo "https://u.peppe.rs/$id"

Templating

-

generate.sh brings the above bits and pieces together (with some extra cruft to avoid javascript). It uses sed to produce nice titles from the file names (removes underscores, title-case), and date(1) to add the date to each post listing!

+

generate.sh +brings the above bits and pieces together (with some extra cruft to +avoid javascript). It uses sed to produce nice titles from +the file names (removes underscores, title-case), and +date(1) to add the date to each post listing!

-- cgit v1.2.3