Mike Gerwitz

Free Software Hacker+Activist

aboutsummaryrefslogtreecommitdiffstats
blob: 83a38f0f4a39e9eea666f9c10b07cbbb74853d11 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
# Generate index HTML page
#
#  Copyright (C) 2019 Mike Gerwitz
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# The index page consists of post abstracts, some static text, and the
# static header and footer.  All post metadata files must have been built,
# along with `post/list'.
#
# This script includes the static body (see `main').
##

set -euo pipefail


# Get the file name of the Nth most recent post.  This relies on the
# existence of `post/list'.
pnfile()
{
  local -ri n=${1?Missing relative post number}

  sed "${n}q;d" post/list
}


# Read field FIELD from post metadata recfile FILE.
pmeta()
{
  local -r file=${1?Missing file name}
  local -r field=${2?Missing field name}

  recsel -P "$field" "$file"
}


# Process each numeric argument using `abstract'.  Each argument must be a
# relative post number (see `pnfile').
abstracts()
{
  while [ $# -gt 0 ]; do
    abstract "$1"
    shift
  done
}


# Generate HTML for relative post number N (see `pnfile').
abstract()
{
  local -ri n=${1?Missing relative post number}

  local file title date slug body
  file=$( pnfile "$n" )
  title=$( pmeta "$file" subject )
  date=$( pmeta "$file" date )
  slug=$( pmeta "$file" slug )
  body=$( pmeta "$file" abstract )

  cat <<EOF
<article class="abstract">
  <h2 class="title"><a href="/$slug">$title</a></h2>
  $body
  <p class="date">Posted on $date.
    <a href="/$slug">Read more &raquo;</a>
  </p>
</article>
EOF
}


# Generate index HTML page.
# TODO: Factor out static sections.
main()
{
  src/mkheader index

  cat <<EOF
<h1 id="latest-posts">Latest Posts</h1>
<section class="asideable" aria-labelledby="latest-posts">
  $( abstracts {1..2} )
</section>

<aside>
  <ul class="links">
    <li><a class="box free-sw" href="#">What is Free/Libre Software?</a></li>
    <li><a class="box eff-privacy" href="#">EFF on Privacy</a></li>
  </ul>
</aside>

<section class="highlight">
  <h1 class="title">The Surreptitious Assault on Privacy, Security,
    and Freedom</h1>

  <aside>
    Each of these essential rights are being surreptitiously
    assaulted; only the most technical among us even know what to look
    for, let alone how to defend ourselves. Governments, corporations,
    and groups of ill-minded individuals are spying and preying upon
    both users and bystanders with unprecedented frequency and
    breadth.
  </aside>

  <a href="#" class="lp-watch">Watch LibrePlanet&nbsp;2017 Talk</a>
  <br clear="both" />
</section>

<section class="compact sm">
  <h1 id="older-posts">Older Posts</h1>

  $( abstracts {3..8} )

  <a class="view-all" href="/posts">View all posts</a>
</section>
EOF

  cat src/footer.tpl.htm
}


main "$@"