aboutsummaryrefslogtreecommitdiff
path: root/docs/posts/static_sites_with_bash/index.html
blob: 961c3c5138b8bf0222903e6cb134d703db890500 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!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">
          <a href="/" class="post-end-link">⟵ Back</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>
              &nbsp
              &nbsp
              <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 &#8216;show me the code&#8217; 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=&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>

<h3 id="Assets">Assets</h3>

<p>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>

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