<!DOCTYPE html> <html lang="en"> <head> <link rel="stylesheet" href="/style.css"> <meta charset="UTF-8"> <meta name="viewport" content="initial-scale=1"> <meta content="#ffffff" name="theme-color"> <meta name="HandheldFriendly" content="true"> <meta property="og:title" content="nerdypepper"> <meta property="og:type" content="website"> <meta property="og:description" content="a static site {for, by, about} me "> <meta property="og:url" content="https://peppe.rs"> <link rel="icon" type="image/x-icon" href="/favicon.png"> <title>Static Sites With Bash · peppe.rs</title> <body> <div class="posts"> <div class="post"> <a href="/" class="post-end-link">⟵ Back</a> <a class="stats post-end-link" href="https://raw.githubusercontent.com/nerdypepper/site/master/posts/static_sites_with_bash.md ">View Raw</a> <div class="separator"></div> <div class="date"> 23/11 — 2019 <div class="stats"> <span class="stats-number"> 21.17 </span> <span class="stats-unit">cm</span>   <span class="stats-number"> 1.5 </span> <span class="stats-unit">min</span> </div> </div> <span class="post-title"> Static Sites With Bash </span> <div class="post-text"> <p>After going through a bunch of static site generators (<a href="https://blog.getpelican.com/">pelican</a>, <a href="https://gohugo.io">hugo</a>, <a href="https://github.com/icyphox/vite">vite</a>), I decided to roll my own. If you are more of the ‘show me the code’ kinda guy, <a href="https://github.com/nerdypepper/site">here</a> you go.</p> <h3 id="Text%20formatting">Text formatting</h3> <p>I chose to write in markdown, and convert to html with <a href="https://kristaps.bsd.lv/lowdown/">lowdown</a>.</p> <h3 id="Directory%20structure">Directory structure</h3> <p>I host my site on GitHub pages, so <code>docs/</code> has to be the entry point. Markdown formatted posts go into <code>posts/</code>, get converted into html, and end up in <code>docs/index.html</code>, something like this:</p> <pre><code>posts=$(ls -t ./posts) # chronological order! for f in $posts; do file="./posts/"$f # `ls` mangled our file paths echo "generating post $file" html=$(lowdown "$file") echo -e "html" >> docs/index.html done </code></pre> <h3 id="Assets">Assets</h3> <p>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:</p> <pre><code># 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="$id.$ext" # copy to my file host scp -P 443 "$1" emerald:files/"$id" echo "https://u.peppe.rs/$id" </code></pre> <h3 id="Templating">Templating</h3> <p><a href="https://github.com/NerdyPepper/site/blob/master/generate.sh"><code>generate.sh</code></a> brings the above bits and pieces together (with some extra cruft to avoid javascript). It uses <code>sed</code> to produce nice titles from the file names (removes underscores, title-case), and <code>date(1)</code> to add the date to each post listing!</p> </div> <div class="separator"></div> <div class=intro> Hi. <a href=https://peppe.rs/index.xml class=feed-button>Subscribe</a> <p>I'm Akshay, I go by nerd or nerdypepper on the internet.</p> <p> I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. I write open-source stuff to pass time. I also design fonts: scientifica, curie. Things I find cool usually end up here. </p> <p>Get in touch at nerd@irc.rizon.net or nerdypepper@chat.freenode.net.</p> </div> <div class="separator"></div> <a href="/" class="post-end-link">⟵ Back</a> <a class="stats post-end-link" href="https://raw.githubusercontent.com/nerdypepper/site/master/posts/static_sites_with_bash.md ">View Raw</a> </div> </div> </body> </html>