about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2021-12-31 23:14:08 +0700
committerNguyễn Gia Phong <mcsinyx@disroot.org>2021-12-31 23:14:08 +0700
commitcb35d1b5811aac349fd4d09bc3c0d666bd7ebeae (patch)
tree242ca2b505ff2cc5635ceba6dd72624bf073a16e
parent3d1c6df4d779caf89590e7911e78c90c1473af4b (diff)
downloadsite-cb35d1b5811aac349fd4d09bc3c0d666bd7ebeae.tar.gz
Improve dependency injection
-rw-r--r--.builds/auto.yml2
-rw-r--r--.builds/shell.nix11
-rw-r--r--README.md2
-rw-r--r--_css/style.css12
-rw-r--r--_layout/page_foot.html2
-rw-r--r--_libs/formbox/comment.html3
-rwxr-xr-x_libs/formbox/format76
-rwxr-xr-x_libs/postprocess (renamed from _libs/minify)0
-rw-r--r--utils.jl3
9 files changed, 20 insertions, 91 deletions
diff --git a/.builds/auto.yml b/.builds/auto.yml
index c5b9a7b..34756e1 100644
--- a/.builds/auto.yml
+++ b/.builds/auto.yml
@@ -19,7 +19,7 @@ tasks:
   - build: |
       cd site
       nix-shell .builds/shell.nix --run 'julia --project=@. .builds/franklin.jl'
-      nix-shell -p python3Packages.css-html-js-minify --run _libs/minify
+      nix-shell -p python3Packages.css-html-js-minify --run _libs/postprocess
   - deploy: |
       tar -cvzf site.tar.gz -C site/__site .
       acurl -f https://pages.sr.ht/publish/cnx.srht.site -F content=@site.tar.gz
diff --git a/.builds/shell.nix b/.builds/shell.nix
index 3f21d40..b73cc6c 100644
--- a/.builds/shell.nix
+++ b/.builds/shell.nix
@@ -1,12 +1,15 @@
 with import <nixpkgs> {};
 mkShell {
   nativeBuildInputs = [
-    julia-bin nodejs nodePackages.katex
-  ] ++ (with python3Packages; [ bleach markdown ]);
+    julia-bin nodejs nodePackages.katex python3Packages.formbox
+  ];
 
   shellHook = ''
     npm install highlight.js # https://github.com/NixOS/nixpkgs/issues/152201
-    ln -fns ${nodePackages.katex}/lib/node_modules/katex/dist _libs/katex
-    ln -fs _libs/katex/{fonts,katex.min.css} _css
+    katex=${nodePackages.katex}/lib/node_modules/katex/dist
+    install -m 755 -d _css/fonts _libs/katex
+    install -m 644 $katex/katex.min.css _css
+    install -m 644 $katex/fonts/* _css/fonts
+    install -m 644 $katex/{katex.min.js,contrib/auto-render.min.js} _libs/katex
   '';
 }
diff --git a/README.md b/README.md
index 7030b3d..e639285 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@ This is my Franklin-generated static site, *without* client-side scripts.
 ## Building
 
     julia --project=@. .builds/franklin.jl
-    _libs/minify
+    _libs/postprocess
 
 ### Explicit dependencies
 
diff --git a/_css/style.css b/_css/style.css
index af502d7..fa15219 100644
--- a/_css/style.css
+++ b/_css/style.css
@@ -20,6 +20,7 @@
     --block-bg: var(--black);
     --fade-fg: var(--bright-black);
     --link-fg: var(--green);
+    --overlay-bg: #8881;
     --text-bg: #121212;
     --text-fg: var(--bright-white);
 }
@@ -42,7 +43,7 @@ html {
     font-size: min(max(100%, 2vw), 150%);
     margin: auto;
     max-width: 36rem;
-    scrollbar-color: var(--fade-fg) var(--block-bg);
+    scrollbar-color: var(--fade-fg) var(--overlay-bg);
 }
 
 body { margin: 0 1rem }
@@ -50,7 +51,7 @@ body { margin: 0 1rem }
 .franklin-content .row { display: block }
 
 /* Text geometry */
-.franklin-content p {
+p, details {
     hyphens: auto;
     line-height: 1.4rem;
     text-align: justify;
@@ -129,7 +130,7 @@ body { margin: 0 1rem }
 .note p:first-child { font-weight: bold }
 
 .franklin-content blockquote {
-    background: var(--block-bg);
+    background: var(--overlay-bg);
     border-left: 0.25rem solid var(--fade-fg);
 }
 
@@ -228,13 +229,14 @@ code, .hljs {
 .hljs-addition { color: var(--red) }
 
 .comment {
-    background-color: #8881;
+    background-color: var(--overlay-bg);
     clear: both;
     margin: 1ex 0;
     overflow: hidden;
     padding: 1ex;
 }
 .comment p { margin: 1ex }
+.comment blockquote, .comment .note { margin: -1ex -1ex 0 }
 
 .openring {
     display: flex;
@@ -244,7 +246,7 @@ code, .hljs {
 }
 .openring h3 { margin: 0 0 1ex }
 .openring article {
-    background: var(--block-bg);
+    background: var(--overlay-bg);
     display: flex;
     flex-direction: column;
     flex: 1 1 0;
diff --git a/_layout/page_foot.html b/_layout/page_foot.html
index f6745c4..bb10e5a 100644
--- a/_layout/page_foot.html
+++ b/_layout/page_foot.html
@@ -8,5 +8,5 @@
 {{comments_rendered}}
 <p>Follow the anchor in an author's name to reply via
   <a href=https://useplaintext.email>plaintext email</a>.  Markdown
-  inline markups, block quotes and code blocks are supported.</p>{{end}}
+  inline markups, block quotes, lists and code blocks are supported.</p>{{end}}
 {{insert footer.html}}
diff --git a/_libs/formbox/comment.html b/_libs/formbox/comment.html
index 60459d9..fe7aa6a 100644
--- a/_libs/formbox/comment.html
+++ b/_libs/formbox/comment.html
@@ -1,6 +1,7 @@
 <div class=comment>
   {body}
-  <p class=right>&mdash;{author},
+  <p class=right>&mdash;<a
+    href="mailto:~cnx/site@lists.sr.ht?{mailto_params}">{author}</a>,
     <a href="https://lists.sr.ht/~cnx/site/{message_id}"
        title="View source">{date}</a></p>
   {children}
diff --git a/_libs/formbox/format b/_libs/formbox/format
deleted file mode 100755
index bad40db..0000000
--- a/_libs/formbox/format
+++ /dev/null
@@ -1,76 +0,0 @@
-#!/usr/bin/env python
-# Format mbox as HTML/XML
-# Copyright (C) 2021  Nguyễn Gia Phong
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero 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 Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program.  If not, see <https://www.gnu.org/licenses/>.
-
-from argparse import ArgumentParser
-from email.header import decode_header
-from email.utils import parsedate_to_datetime
-from functools import partial
-from itertools import starmap
-from mailbox import mbox
-from pathlib import Path
-from urllib.parse import quote, unquote
-
-from bleach import clean, linkify
-from markdown import markdown
-
-sanitise = partial(clean, tags=('a', 'code', 'em', 'strong', 'sub', 'sup',
-                                'blockquote', 'p', 'pre', 'ul', 'ol', 'li'),
-                   protocols=('ftp', 'gemini', 'gopher', 'http', 'https',
-                              'irc', 'ircs', 'mailto', 'matrix', 'xmpp'))
-
-
-def extract(archive, parent):
-    """Recursively extract emails in reply to given message ID."""
-    for message_id, message in archive.copy().items():
-        # TODO: handle multipart
-        if message['In-Reply-To'] != parent: continue
-        archive.pop(message_id)
-        yield message, extract(archive, message_id)
-
-
-def decode(header):
-    """Return the decoded email header."""
-    for string, charset in decode_header(header):
-        encoding = 'utf-8' if charset is None else charset
-        yield string.decode(encoding)
-
-
-def render(template, forest, parent):
-    """Render the thread recursively based on given template."""
-    for self, children in forest:
-        message_id = self['Message-Id']
-        date = parsedate_to_datetime(self['Date']).date().isoformat()
-        author, address = decode(self['From'])
-        body = sanitise(linkify(markdown(self.get_payload(),
-                                         output_format='html5')))
-        rendered_children = render(template, children, message_id)
-        yield template.format(message_id=quote(message_id),
-                              date=date, author=author, body=body,
-                              children='\n'.join(rendered_children))
-
-
-if __name__ == '__main__':
-    parser = ArgumentParser()
-    parser.add_argument('mbox')
-    parser.add_argument('id', type=unquote)
-    parser.add_argument('template', type=Path)
-    args = parser.parse_args()
-
-    archive = {m['Message-Id']: m for m in mbox(args.mbox)}
-    template = args.template.read_text()
-    print(*render(template, extract(archive, args.id), args.id),
-          sep='', end='')
diff --git a/_libs/minify b/_libs/postprocess
index 8416d3b..8416d3b 100755
--- a/_libs/minify
+++ b/_libs/postprocess
diff --git a/utils.jl b/utils.jl
index a056c30..9c12c25 100644
--- a/utils.jl
+++ b/utils.jl
@@ -17,10 +17,9 @@ hfun_comments() = @sprintf("https://lists.sr.ht/~cnx/site?search=%s:%s",
 
 function render_comments(template)
   prefix = joinpath(path(:libs), "formbox")
-  format = joinpath(prefix, "format")
   mbox = joinpath(prefix, "mbox")
   template_path = joinpath(prefix, template)
-  readchomp(`$format $mbox $(message_id()) $template_path`)
+  readchomp(`formbox $mbox $(message_id()) $template_path`)
 end
 
 hfun_comments_rendered() = render_comments("comment.html")