aboutsummaryrefslogtreecommitdiff
path: root/docs/posts/static_sites_with_bash/index.html
blob: 06051474a36338d33a567f24b09ea73ffe292be1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!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://nerdypepper.tech">
    <body>
      <div class="posts">
        <div class="post">
          <div class="date">
            23/11 2019
            <span class="commit-hash">
              <a href="https://github.com/nerdypepper/site/blob/master/posts/static_sites_with_bash.md
" style="text-decoration: none">
                d1faa7e
              </a>
            </span>
          </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 &#8216;show me the code&#8217; kinda guy,
<a href="https://github.com/nerdypepper/site">here</a> you go.</p>

<p><strong>Text formatting</strong>: I chose to write in markdown, and convert
to html with <a href="https://kristaps.bsd.lv/lowdown/">lowdown</a>.</p>

<p><strong>Directory structure</strong>: 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=&quot;./posts/&quot;$f      # `ls` mangled our file paths
    echo &quot;generating post $file&quot;

    html=$(lowdown &quot;$file&quot;)
    echo -e &quot;html&quot; &gt;&gt; docs/index.html
done
</code></pre>

<p><strong>Assets</strong>: Most static site generators recommend dropping image
assets into the site source itself. That does have it&#8217;s
merits, but I prefer hosting images separately:</p>

<pre><code># strip file extension
ext=&quot;${1##*.}&quot;

# generate a random file name
id=$( cat /dev/urandom | tr -dc &#39;a-zA-Z0-9&#39; | fold -w 2 | head -n 1 )
id=&quot;$id.$ext&quot;

# copy to my file host
scp -P 443 &quot;$1&quot; emerald:files/&quot;$id&quot; 
echo &quot;https://files.nerdypepper.tech/$id&quot;
</code></pre>

<p><strong>Templating</strong>:
<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>
          <a href="/" class="post-end-link">⟵ Back</a>
          <div class="separator"></div>
        </div>
      </div>
    </body>
</html>