From 89bb239365bdfdef8827251748e6a36d741fdf63 Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Tue, 28 Dec 2021 23:13:42 +0700 Subject: Fix all HTML and RSS compliance issues (hopefully!) --- .build.jl | 6 ------ .build.yml | 24 ------------------------ .builds/auto.yml | 25 +++++++++++++++++++++++++ .builds/franklin.jl | 6 ++++++ .builds/shell.nix | 12 ++++++++++++ .gitignore | 2 +- README.md | 5 +++-- _libs/minify | 39 +++++++++++++++++++++++++++++++++++++++ blog/2020/gsoc/article/5.md | 2 +- blog/2020/gsoc/article/7.md | 4 ++-- blog/2020/gsoc/index.md | 1 + config.md | 4 ++-- shell.nix | 12 ------------ utils.jl | 2 +- 14 files changed, 93 insertions(+), 51 deletions(-) delete mode 100644 .build.jl delete mode 100644 .build.yml create mode 100644 .builds/auto.yml create mode 100644 .builds/franklin.jl create mode 100644 .builds/shell.nix create mode 100755 _libs/minify delete mode 100644 shell.nix diff --git a/.build.jl b/.build.jl deleted file mode 100644 index 52bbec3..0000000 --- a/.build.jl +++ /dev/null @@ -1,6 +0,0 @@ -import Pkg -Pkg.instantiate() - -using Franklin -optimize(clear=true, no_fail_prerender=false, - suppress_errors=false, fail_on_warning=true) diff --git a/.build.yml b/.build.yml deleted file mode 100644 index 80bd57b..0000000 --- a/.build.yml +++ /dev/null @@ -1,24 +0,0 @@ -image: nixos/unstable -oauth: lists.sr.ht/EMAILS:RO pages.sr.ht/PAGES:RW -packages: - - nixos.jq - - nixos.openring -sources: - - https://git.sr.ht/~cnx/site -environment: - NODE: node -tasks: - - inject: | - curl https://fediring.net/ring.json | - jq -r 'map(.host)|until(.[0]=="cnx.srht.site";.[1:]+.[:1])|.[-1,1]'\ - > site/_libs/fediring - openring -n 4 -l 192 -S site/_libs/openring/sources\ - < site/_libs/openring/in.html > site/_libs/openring/out.html - acurl https://lists.sr.ht/query/list/5261.mbox -o site/_libs/formbox/mbox - - build: | - cd site - nix-shell --run 'julia --project=@. .build.jl' - rm -r __site/libs - - 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/auto.yml b/.builds/auto.yml new file mode 100644 index 0000000..c5b9a7b --- /dev/null +++ b/.builds/auto.yml @@ -0,0 +1,25 @@ +image: nixos/unstable +oauth: lists.sr.ht/EMAILS:RO pages.sr.ht/PAGES:RW +packages: + - nixos.jq + - nixos.openring + - nixos.python3 +sources: + - https://git.sr.ht/~cnx/site +environment: + NODE: node +tasks: + - inject: | + curl https://fediring.net/ring.json | + jq -r 'map(.host)|until(.[0]=="cnx.srht.site";.[1:]+.[:1])|.[-1,1]'\ + > site/_libs/fediring + openring -n 4 -l 192 -S site/_libs/openring/sources\ + < site/_libs/openring/in.html > site/_libs/openring/out.html + acurl https://lists.sr.ht/query/list/5261.mbox -o site/_libs/formbox/mbox + - 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 + - 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/franklin.jl b/.builds/franklin.jl new file mode 100644 index 0000000..c090540 --- /dev/null +++ b/.builds/franklin.jl @@ -0,0 +1,6 @@ +import Pkg +Pkg.instantiate() + +using Franklin +optimize(clear=true, minify=false, no_fail_prerender=false, + suppress_errors=false, fail_on_warning=true) diff --git a/.builds/shell.nix b/.builds/shell.nix new file mode 100644 index 0000000..3f21d40 --- /dev/null +++ b/.builds/shell.nix @@ -0,0 +1,12 @@ +with import {}; +mkShell { + nativeBuildInputs = [ + julia-bin nodejs nodePackages.katex + ] ++ (with python3Packages; [ bleach markdown ]); + + 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 + ''; +} diff --git a/.gitignore b/.gitignore index 0a3ca5a..5c6f140 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ _css/katex.min.css _libs/fediring _libs/formbox/mbox _libs/highlight/ -_libs/katex/ +_libs/katex _libs/openring/out.html node_modules/ package-lock.json diff --git a/README.md b/README.md index f780ddf..7030b3d 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,8 @@ This is my Franklin-generated static site, *without* client-side scripts. ## Building - julia --project=@. .build.jl + julia --project=@. .builds/franklin.jl + _libs/minify ### Explicit dependencies @@ -17,7 +18,7 @@ The following are needed to run the command above: * [css-html-js-minify](https://pypi.org/p/css-html-js-minify) KaTex has to installed to `_css` and `_libs` similar -to what done in `.build.yml`. Furthermore, adjacent sites +to what done in `.builds/auto.yml`. Furthermore, adjacent sites in the [Fediring](https://fediring.net) needs to present in `_libs/fediring` and `_libs/openring/out.html` needs to be generated using [openring](https://sr.ht/~sircmpwn/openring). Live-rendering diff --git a/_libs/minify b/_libs/minify new file mode 100755 index 0000000..67634a3 --- /dev/null +++ b/_libs/minify @@ -0,0 +1,39 @@ +#!/usr/bin/env python +# Minify HTML and CSS, patch HTML and remove JS +# 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 . + +import re +from contextlib import suppress +from pathlib import Path +from shutil import rmtree + +from css_html_js_minify import html_minify, process_single_css_file + +FOOTNOTES_START = re.compile('(

)?\s*\s*(

)?') + + +def fix_footnotes(html): + """Work around https://github.com/tlienart/Franklin.jl/issues/936""" + return FOOTNOTES_START.sub('', html)) + + +site = Path(__file__).parent.parent / '__site' +process_single_css_file(site/'css'/'style.css', overwrite=True) +for html in site.rglob('*.html'): + print('Minifying and fixing up', html) + html.write_text(fix_footnotes(html_minify(html.read_text()))) +with suppress(FileNotFoundError): rmtree(site/'libs') diff --git a/blog/2020/gsoc/article/5.md b/blog/2020/gsoc/article/5.md index cdcc509..bd9d7e6 100644 --- a/blog/2020/gsoc/article/5.md +++ b/blog/2020/gsoc/article/5.md @@ -4,7 +4,7 @@ date = Date(2020, 8, 3) tags = ["gsoc", "pip", "python"] +++ -Sorting Things Out +# Sorting Things Out Hi! I really hope that everyone reading this is still doing okay, and if that isn't the case, I wish you a good day! diff --git a/blog/2020/gsoc/article/7.md b/blog/2020/gsoc/article/7.md index 4e2073b..6deebb9 100644 --- a/blog/2020/gsoc/article/7.md +++ b/blog/2020/gsoc/article/7.md @@ -4,13 +4,13 @@ date = Date(2020, 8, 31) tags = ["gsoc", "pip", "python"] +++ +# Outro + > Steamed fish was amazing, matter of fact\ > Let me get some jerk chicken to go\ > Grabbed me one of them lemon pie theories\ > And let me get some of them benchmarks you theories too -# Outro - \toc ## The Look diff --git a/blog/2020/gsoc/index.md b/blog/2020/gsoc/index.md index b05c908..0606c13 100644 --- a/blog/2020/gsoc/index.md +++ b/blog/2020/gsoc/index.md @@ -2,6 +2,7 @@ rss = "GSoC 2020 final report" date = Date(2020, 8, 31) rss_pubdate = date # work around Franklin issue GH-797 +fd_full_url = "https://cnx.srht.site/blog/2020/gsoc/index.html" tags = ["fun", "gsoc", "packaging", "pip"] internship = "https://summerofcode.withgoogle.com/archive/2020/projects/6238594655584256" benchmark = "/blog/2020/gsoc/article/7/#the_benchmark" diff --git a/config.md b/config.md index 077fcfb..a77b1f7 100644 --- a/config.md +++ b/config.md @@ -7,8 +7,8 @@ website_url = "https://cnx.srht.site" date_format = "yyyy-mm-dd" mintoclevel = 2 generate_rss = true -ignore = [".build.jl", ".build.yml", "Manifest.toml", "Project.toml", - "node_modules/", "package-lock.json", "shell.nix"] +ignore = [".builds/", "Manifest.toml", "Project.toml", + "node_modules/", "package-lock.json"] +++ \newcommand{\R}{\mathbb R} diff --git a/shell.nix b/shell.nix deleted file mode 100644 index 50d4e3e..0000000 --- a/shell.nix +++ /dev/null @@ -1,12 +0,0 @@ -with import {}; -mkShell { - nativeBuildInputs = [ - julia-bin nodejs nodePackages.katex python3 - ] ++ (with python3Packages; [ bleach css-html-js-minify markdown ]); - - 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 - ''; -} diff --git a/utils.jl b/utils.jl index 62dce1d..a056c30 100644 --- a/utils.jl +++ b/utils.jl @@ -20,7 +20,7 @@ function render_comments(template) format = joinpath(prefix, "format") mbox = joinpath(prefix, "mbox") template_path = joinpath(prefix, template) - readchomp(`python3 $format $mbox $(message_id()) $template_path`) + readchomp(`$format $mbox $(message_id()) $template_path`) end hfun_comments_rendered() = render_comments("comment.html") -- cgit 1.4.1