diff options
Diffstat (limited to 'docs/posts/static_sites_with_bash.html')
-rw-r--r-- | docs/posts/static_sites_with_bash.html | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/docs/posts/static_sites_with_bash.html b/docs/posts/static_sites_with_bash.html new file mode 100644 index 0000000..70eda1a --- /dev/null +++ b/docs/posts/static_sites_with_bash.html | |||
@@ -0,0 +1,74 @@ | |||
1 | <!DOCTYPE html> | ||
2 | <html lang="en"> | ||
3 | <head> | ||
4 | <link rel="stylesheet" href="/style.css"> | ||
5 | <meta charset="UTF-8"> | ||
6 | <meta name="viewport" content="initial-scale=1"> | ||
7 | <meta content="#ffffff" name="theme-color"> | ||
8 | <meta name="HandheldFriendly" content="true"> | ||
9 | <meta property="og:title" content="nerdypepper"> | ||
10 | <meta property="og:type" content="website"> | ||
11 | <meta property="og:description" content="a static site {for, by, about} me "> | ||
12 | <meta property="og:url" content="https://nerdypepper.tech"> | ||
13 | <body> | ||
14 | <div class="post posts"> | ||
15 | <div class="date">23/11 2019</div> | ||
16 | <span style="font-size: 2rem; font-weight: 600"> | ||
17 | Static Sites With Bash | ||
18 | </span> | ||
19 | <div class="post-text"> | ||
20 | <p>After going through a bunch of static site generators | ||
21 | (<a href="https://blog.getpelican.com/">pelican</a>, | ||
22 | <a href="https://gohugo.io">hugo</a>, | ||
23 | <a href="https://github.com/icyphox/vite">vite</a>), I decided to roll | ||
24 | my own. If you are more of the ‘show me the code’ kinda guy, | ||
25 | <a href="https://github.com/nerdypepper/site">here</a> you go.</p> | ||
26 | |||
27 | <p><strong>Text formatting</strong>: I chose to write in markdown, and convert | ||
28 | to html with <a href="https://kristaps.bsd.lv/lowdown/">lowdown</a>.</p> | ||
29 | |||
30 | <p><strong>Directory structure</strong>: I host my site on GitHub pages, so | ||
31 | <code>docs/</code> has to be the entry point. Markdown formatted posts | ||
32 | go into <code>posts/</code>, get converted into html, and end up in | ||
33 | <code>docs/index.html</code>, something like this:</p> | ||
34 | |||
35 | <pre><code>posts=$(ls -t ./posts) # chronological order! | ||
36 | for f in $posts; do | ||
37 | file="./posts/"$f # `ls` mangled our file paths | ||
38 | echo "generating post $file" | ||
39 | |||
40 | html=$(lowdown "$file") | ||
41 | echo -e "html" >> docs/index.html | ||
42 | done | ||
43 | </code></pre> | ||
44 | |||
45 | <p><strong>Assets</strong>: Most static site generators recommend dropping image | ||
46 | assets into the site source itself. That does have it’s | ||
47 | merits, but I prefer hosting images separately:</p> | ||
48 | |||
49 | <pre><code># strip file extension | ||
50 | ext="${1##*.}" | ||
51 | |||
52 | # generate a random file name | ||
53 | id=$( cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 2 | head -n 1 ) | ||
54 | id="$id.$ext" | ||
55 | |||
56 | # copy to my file host | ||
57 | scp -P 443 "$1" emerald:files/"$id" | ||
58 | echo "https://files.nerdypepper.tech/$id" | ||
59 | </code></pre> | ||
60 | |||
61 | <p><strong>Templating</strong>: | ||
62 | <a href="https://github.com/NerdyPepper/site/blob/master/generate.sh"><code>generate.sh</code></a> | ||
63 | brings the above bits and pieces together (with some extra | ||
64 | cruft to avoid javascript). It uses <code>sed</code> to produce nice | ||
65 | titles from the file names (removes underscores, | ||
66 | title-case), and <code>date(1)</code> to add the date to each post | ||
67 | listing!</p> | ||
68 | |||
69 | </div> | ||
70 | <a href="/index.html" class="post-end-link">‹ Back</a> | ||
71 | <div class="separator"></div> | ||
72 | </div> | ||
73 | </body> | ||
74 | </html> | ||