Compare commits
No commits in common. "982ef99a2f6c9e105d0e4e22f308d43e36ed5457" and "17e18872bfaedf4781743b663501c2d5bedc0458" have entirely different histories.
982ef99a2f
...
17e18872bf
@ -15,4 +15,6 @@ mkdir $out
|
||||
cp -r public/$publicPath/* $out/
|
||||
|
||||
# Render math in HTML and XML files.
|
||||
find $out/ -regex "$out/.*\.html" | xargs katex-html
|
||||
node $server &
|
||||
sleep 1
|
||||
find $out/ -regex "$out/.*\.html" | xargs ruby $converter
|
||||
|
36
build/convert.rb
Normal file
36
build/convert.rb
Normal file
@ -0,0 +1,36 @@
|
||||
require "open3"
|
||||
require "nokogiri"
|
||||
require "net/http"
|
||||
require "json"
|
||||
|
||||
def render_cached(cache, display, string, render_comment = nil)
|
||||
cache.fetch(string) do |new|
|
||||
puts " Rendering #{render_comment || new}"
|
||||
res = Net::HTTP.post URI("http://localhost:8000/render"),
|
||||
{ :equations => [ { :str => string, :display => display } ] }.to_json,
|
||||
"Content-Type" => "application/json"
|
||||
cache[string] = JSON.parse(res.body)[0]
|
||||
end
|
||||
end
|
||||
|
||||
def perform_katex_sub(inline_cache, display_cache, content)
|
||||
rendered = content.gsub /\\\(((?:[^\\]|\\[^\)])*)\\\)/ do |match|
|
||||
render_cached(inline_cache, false, $~[1])
|
||||
end
|
||||
rendered = rendered.gsub /\$\$((?:[^\$]|$[^\$])*)\$\$/ do |match|
|
||||
render_cached(display_cache, true, $~[1], "display")
|
||||
end
|
||||
return rendered
|
||||
end
|
||||
|
||||
files = ARGV[0..-1]
|
||||
inline_cache, display_cache = {}, {}
|
||||
|
||||
files.each do |file|
|
||||
puts "Rendering file: #{file}"
|
||||
document = Nokogiri::HTML.parse(File.open(file))
|
||||
document.search('//*[not(ancestor-or-self::code)]/text()').each do |t|
|
||||
t.replace(perform_katex_sub(inline_cache, display_cache, t.content))
|
||||
end
|
||||
File.write(file, document.to_html(encoding: 'UTF-8'))
|
||||
end
|
11
build/katexserver.js
Normal file
11
build/katexserver.js
Normal file
@ -0,0 +1,11 @@
|
||||
const katex = require('katex');
|
||||
const express = require('express');
|
||||
const bodyParser = require('body-parser');
|
||||
|
||||
app = express();
|
||||
app.use(bodyParser.json());
|
||||
app.post('/render', (req, res) => {
|
||||
res.send(req.body.equations.map(eq =>
|
||||
katex.renderToString(eq.str, { throwOnError: false, displayMode: eq.display })));
|
||||
});
|
||||
app.listen(8000);
|
102
flake.lock
generated
102
flake.lock
generated
@ -52,106 +52,7 @@
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-utils_2": {
|
||||
"locked": {
|
||||
"lastModified": 1648297722,
|
||||
"narHash": "sha256-W+qlPsiZd8F3XkzXOzAoR+mpFqzm3ekQkJNa+PIh1BQ=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "0f8662f1319ad6abf89b3380dd2722369fc51ade",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-utils_3": {
|
||||
"locked": {
|
||||
"lastModified": 1648297722,
|
||||
"narHash": "sha256-W+qlPsiZd8F3XkzXOzAoR+mpFqzm3ekQkJNa+PIh1BQ=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "0f8662f1319ad6abf89b3380dd2722369fc51ade",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"katex-html": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils_2",
|
||||
"katex-server": "katex-server",
|
||||
"nixpkgs": "nixpkgs_2"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1648430978,
|
||||
"narHash": "sha256-12Bj/RX6rb5ooHHeqIBLa2kizGW9syFyUOQVDzVzGzI=",
|
||||
"ref": "master",
|
||||
"rev": "fc26bcf07b5d22cbd4f378130a8fd6d8b0ede9ce",
|
||||
"revCount": 6,
|
||||
"type": "git",
|
||||
"url": "https://dev.danilafe.com/Nix-Configs/katex-html"
|
||||
},
|
||||
"original": {
|
||||
"type": "git",
|
||||
"url": "https://dev.danilafe.com/Nix-Configs/katex-html"
|
||||
}
|
||||
},
|
||||
"katex-server": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils_3",
|
||||
"nixpkgs": "nixpkgs"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1648429554,
|
||||
"narHash": "sha256-jNRd9gzrOIYlvuVr/Je2Uh6/FXRoGwAIjgVHhf2NOoE=",
|
||||
"ref": "master",
|
||||
"rev": "a277542d9b7eb23806b123aed41a0bd441ff669b",
|
||||
"revCount": 4,
|
||||
"type": "git",
|
||||
"url": "https://dev.danilafe.com/Nix-Configs/katex-server"
|
||||
},
|
||||
"original": {
|
||||
"type": "git",
|
||||
"url": "https://dev.danilafe.com/Nix-Configs/katex-server"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1648425779,
|
||||
"narHash": "sha256-0tcpEiiq3f3Hh77ax7QFuF15AnPaBIdDSbvrCUeyb9k=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "1edfe6d91bd8348cfccacd72e82d1d06ad470117",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1648425779,
|
||||
"narHash": "sha256-0tcpEiiq3f3Hh77ax7QFuF15AnPaBIdDSbvrCUeyb9k=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "1edfe6d91bd8348cfccacd72e82d1d06ad470117",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_3": {
|
||||
"locked": {
|
||||
"lastModified": 1634881110,
|
||||
"narHash": "sha256-glFqhVeqPuT99vfKrOH7lmJDrgwP99KJJSFpgpyvbko=",
|
||||
@ -171,8 +72,7 @@
|
||||
"blog-source": "blog-source",
|
||||
"blog-source-localized": "blog-source-localized",
|
||||
"flake-utils": "flake-utils",
|
||||
"katex-html": "katex-html",
|
||||
"nixpkgs": "nixpkgs_3"
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -2,7 +2,6 @@
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
katex-html.url = "git+https://dev.danilafe.com/Nix-Configs/katex-html";
|
||||
blog-source = {
|
||||
flake = false;
|
||||
url = "https://dev.danilafe.com/Web-Projects/blog-static.git";
|
||||
@ -18,18 +17,12 @@
|
||||
};
|
||||
};
|
||||
|
||||
outputs = { self, blog-source, blog-source-localized, nixpkgs, flake-utils, katex-html }:
|
||||
outputs = { self, blog-source, blog-source-localized, nixpkgs, flake-utils }:
|
||||
{
|
||||
buildersFor = system: import ./lib.nix {
|
||||
inherit blog-source blog-source-localized;
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
katex-html = katex-html.defaultPackage.${system};
|
||||
};
|
||||
nixosModule = (import ./module.nix);
|
||||
packages.x86_64-linux.blog-debug = (import ./lib.nix {
|
||||
inherit blog-source blog-source-localized;
|
||||
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||
katex-html = katex-html.defaultPackage."x86_64-linux";
|
||||
}).english { host = "danilafe.com"; };
|
||||
};
|
||||
}
|
||||
|
6
lib.nix
6
lib.nix
@ -1,4 +1,4 @@
|
||||
{ blog-source, blog-source-localized, pkgs, katex-html }:
|
||||
{ blog-source, blog-source-localized, pkgs }:
|
||||
|
||||
with pkgs;
|
||||
|
||||
@ -16,8 +16,10 @@ let
|
||||
publicPath = settings.path;
|
||||
extraFlags = if settings.drafts then " -D " else "";
|
||||
builder = ./build/builder.sh;
|
||||
converter = ./build/convert.rb;
|
||||
server = ./build/katexserver.js;
|
||||
buildInputs = [
|
||||
hugo nodejs katex-html
|
||||
hugo nodejs
|
||||
requiredPackages."katex-0.11.1"
|
||||
requiredPackages.express
|
||||
requiredPackages.body-parser
|
||||
|
Loading…
Reference in New Issue
Block a user