about summary refs log tree commit diff
path: root/doc/web.nix
blob: cfc77cb0eb8bb25b4901088bbea63f8177ef1180 (plain) (blame)
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
{ pkgs ? (import <nixpkgs> {}) }:

let
  manPages = [
    { name = "bs-renderflipdot"; section = 1; }
  ];

  readmeDeps = [
    "bs-renderflipdot.c"
    "doc/flipdot-render.png"
  ];

  lib = pkgs.lib;
  root = ./..;
  repoRoot = builtins.path {
    name = "buchstabensuppe-src";
    path = root;
    filter = pkgs.nix-gitignore.gitignoreFilter
      (builtins.readFile ./../.gitignore) root;
  };

  # TODO: man inclusion -Oman
  buildManPage = { name, section }:
    let
      out = "$out/man/${name}.${toString section}.html";
    in ''
      echo ${lib.escapeShellArg (commonHead 1 "${name}(${toString section})")} \
        > ${out}
      echo "<main>" >> ${out}
      ${pkgs.mandoc}/bin/mandoc -Thtml -Ofragment \
        ${repoRoot}/doc/man/${name}.${toString section} \
        >> ${out}
      echo "</main></body></html>" >> ${out}
    '';

  readme = pkgs.runCommandLocal "README.html" {} ''
    echo ${lib.escapeShellArg (commonHead 1 "buchstabensuppe/README")} > $out
    echo "<body><main>" >> $out
    ${pkgs.lowdown}/bin/lowdown ${repoRoot}/README.md >> $out
    echo "</main></body></html>" >> $out
  '';

  normalize = pkgs.fetchurl {
    url = "https://necolas.github.io/normalize.css/8.0.1/normalize.css";
    sha256 = "04jmvybwh2ks4dlnfa70sb3a3z3ig4cv0ya9rizjvm140xq1h22q";
  };

  style = pkgs.writeText "style.css" ''
    body {
      font-size: 1em;
      font-family: serif;
      background-color: #efefef;
      line-height: 1.5;
    }

    h1, h2, h3, h4, h5, h6 {
      font-family: 'Source Sans Pro', 'Open Sans', sans-serif;
    }

    a:link, a:visited {
      color: #3e7eff;
    }

    header, main, footer {
      margin-top: 0;
      margin-bottom: 0;
      margin-left: auto;
      margin-right: auto;
      max-width: 800px;
      background-color: white;
      padding: 5px 10px;
    }

    /* markdown */

    pre {
      background-color: #efefef;
      overflow: auto;
      padding: 10px;
    }

    img {
      max-width: 100%;
    }

    blockquote {
      border-left: 5px solid #efefef;
      margin-left: 0;
      padding-left: 10px;
    }

    /* man page related */
    table.head, table.foot {
      width: 100%;
    }

    table.head {
      padding-bottom: 20px;
    }

    table.foot {
      padding-top: 20px;
    }

    table.head td, table.foot td {
      text-align: center;
      padding: 0;
    }

    table.head td:nth-last-child(1),
    table.foot td:nth-last-child(1) {
      text-align: right;
    }

    table.head td:nth-child(1),
    table.foot td:nth-child(1) {
      text-align: left;
    }
  '';

  commonHead = depth: title:
    let
      styleDir = lib.concatStrings (builtins.genList (x: "../") depth);
    in ''
    <!doctype html>
    <html lang="en">
      <head>
        <meta charset="utf-8">
        <title>${title}</title>
        <link rel="stylesheet" type="text/css" href="${styleDir}style.css">
      </head>
  '';

  index = pkgs.writeText "index.html" ''
      ${commonHead 0 "buchstabensuppe"}
      <body>
        <header>
          <h1>buchstabensuppe</h1>
          <nav>
            <ul>
              <li>
                <a href="https://code.sterni.lv/buchstabensuppe/">
                  Source (Mirror)
                </a>
              </li>
              <li>
                <a href="https://github.com/sternenseemann/buchstabensuppe">
                  Source (Github)
                </a>
              </li>
            </ul>
          </nav>
        </header>
        <main>
          <section>
            <h2>description</h2>
            <p>
              buchstabensuppe is a simple font rendering library intended
              for rendering fonts for binary black and white displays
              with low resolutions, for example
              <a href="https://wiki.openlab-augsburg.de/Flipdots">
                OpenLab's flipdot display
              </a>. The goal is to implement font rendering that
              is adequate for the situation and as correct as possible
              (e. g. do text shaping, …).
            </p>
            <p>
              Documentation is still a bit sparse, but shall be improved.
              For now most information is in the
              <a href="readme/README.html">README</a>.
            </p>
          </section>
          </section>
          <section>
            <h2>man pages</h2>

            <ul>
              ${lib.concatMapStrings ({ name, section }: ''
                  <li>
                    <a href="man/${name}.${toString section}.html">
                      ${name}(${toString section})
                    </a>
                  </li>
                '') manPages}
            </ul>
          </section>
        </main>
      </body>
    </html>
  '';

in

pkgs.runCommandLocal "buchstabensuppe-web" {} ''
  mkdir -p $out/man
  mkdir -p $out/readme
  cat ${normalize} ${style} > $out/style.css
  cp ${index} $out/index.html

  ${lib.concatMapStrings buildManPage manPages}

  cp ${readme} $out/readme/README.html

  ${lib.concatMapStrings (dep: ''
      mkdir -p "$(dirname "$out/readme/${dep}")"
      cp "${repoRoot}/${dep}" "$out/readme/${dep}"
    '') readmeDeps}
''