aboutsummaryrefslogtreecommitdiff
path: root/docs/posts/static_sites_with_bash/index.html
blob: 31a5278ddd99da62247241be469f724609e5e169 (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!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="date">
            23/11 — 2019
            <div class="stats">
              <span class="stats-number">
                21.17
              </span>
              <span class="stats-unit">cm</span>
              &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&#47;</code> has to be the entry point. Markdown formatted posts
go into <code>posts&#47;</code>, get converted into html, and end up in
<code>docs&#47;index.html</code>, something like this:</p>

<pre><code>posts=$(ls -t .&#47;posts)     # chronological order!
for f in $posts; do
    file=&#34;.&#47;posts&#47;&#34;$f      # `ls` mangled our file paths
    echo &#34;generating post $file&#34;

    html=$(lowdown &#34;$file&#34;)
    echo -e &#34;html&#34; &#62;&#62; docs&#47;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=&#34;${1##*.}&#34;

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

# copy to my file host
scp -P 443 &#34;$1&#34; emerald:files&#47;&#34;$id&#34; 
echo &#34;https:&#47;&#47;u.peppe.rs&#47;$id&#34;
</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=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 [email protected] or [email protected].</p>
    </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>