From 2edfef83b3c9e7b4d0b24b4090e3bee80a30c1a3 Mon Sep 17 00:00:00 2001 From: Magic_RB Date: Mon, 17 May 2021 00:20:40 +0200 Subject: [PATCH 1/2] Multisite start Signed-off-by: Magic_RB --- Makefile | 2 - flake.nix | 42 ++++++++++++---- make.el | 81 +++++++++++++++++++++++++----- nixng/examples/apache.org | 102 ++++++++++++++++++++++++++++++++++++++ templates/example.html | 26 ++++++++++ 5 files changed, 227 insertions(+), 26 deletions(-) delete mode 100644 Makefile create mode 100644 nixng/examples/apache.org create mode 100644 templates/example.html diff --git a/Makefile b/Makefile deleted file mode 100644 index fef355d..0000000 --- a/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -all: - emacs --script make.el diff --git a/flake.nix b/flake.nix index 8d4b229..c8bbb1e 100644 --- a/flake.nix +++ b/flake.nix @@ -15,13 +15,9 @@ let supportedSystems = [ "x86_64-linux" "i686-linux" "aarch64-linux" ]; forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system); - - in - { - - website = pkgs: - pkgs.stdenv.mkDerivation { - name = "magic_rb-website"; + site = pkgs: which: + pkgs.stdenv.mkDerivation { + name = which; version = "0.1"; src = ./.; nativeBuildInputs = [ pkgs.emacs ]; @@ -30,7 +26,7 @@ cp ${org-thtml}/ox-thtml.el ./ox-thtml.el cp ${emacs-htmlize}/htmlize.el ./htmlize.el mkdir tmp && export HOME=$(pwd)/tmp - emacs --script ./make.el + emacs --script ./make.el -- ${which} find public_html -name 'sitemap.*' -exec rm {} \; ''; @@ -40,12 +36,36 @@ cp -r public_html/* $out ''; }; - - defaultPackage = forAllSystems (system: + in + { + redalder = forAllSystems (system: let pkgs = import nixpkgs { inherit system; }; in - self.website pkgs + site pkgs "redalder.org" + ); + + nixng = forAllSystems (system: + let + pkgs = import nixpkgs { inherit system; }; + in + site pkgs "nixng.org" + ); + + website = forAllSystems (system: + let + pkgs = import nixpkgs { inherit system; }; + in + pkgs.runCommandNoCC "website" {} + '' + mkdir -p $out/ + ln -s ${self.redalder.${system}} $out/redalder + ln -s ${self.nixng.${system}} $out/nixng + '' + ); + + defaultPackage = forAllSystems (system: + self.website.${system} ); }; } diff --git a/make.el b/make.el index 8ef1079..38769b7 100644 --- a/make.el +++ b/make.el @@ -30,11 +30,39 @@ ;; org-html-htmlize-output-type 'inline-css ) +(defvar magic_rb/asset-include + "\\(ttf\\|svg\\|jpg\\|gif\\|png\\|css\\|js\\|el\\|nb\\|ipynb\\|pdf\\|xml\\)") + +(defun magic_rb/source-with-name (name symbol property) + "" + (string-trim + (org-element-property + property + (car (let ((path buffer-file-name)) + (with-temp-buffer + (insert-file-contents path) + (org-element-map (org-element-parse-buffer) symbol + (lambda (object) + (let ((block-name (org-element-property :name object))) + (if (string-equal block-name name) + object + nil)))))))))) + +;; (org-element-map (org-element-parse-buffer) 'paragraph +;; (lambda (paragraph) +;; (let ((parent (org-element-property :parent paragraph))) +;; (and (eq (org-element-type parent) 'section) +;; (let ((first-child (car (org-element-contents parent)))) +;; (eq first-child paragraph)) +;; ;; Return value. +;; paragraph)))) + + (defvar org-publish-project-alist) (setq org-publish-project-alist `( ;; Blog - ("blog-content" + ("redalder-blog-content" :base-directory ,(expand-file-name "./blog/") :base-extension "org" :publishing-directory ,(expand-file-name "./public_html/blog") @@ -53,7 +81,7 @@ :sitemap-title "Magic_RB's blog" :sitemap-filename "sitemap.inc" :sitemap-sort-files anti-chronologically) - ("blog-index" + ("redalder-blog-index" :base-directory ,(expand-file-name "./blog/") :root-directory ,(expand-file-name "./blog/") :recursive t @@ -66,12 +94,12 @@ :with-date nil :html-template ,(templated-html-load-template "./templates/blog-index.html") :publishing-function org-html-publish-to-templated-html) - ("blog" - :components ("blog-content" "blog-index")) + ("redalder-blog" + :components ("redalder-blog-content" "redalder-blog-index")) ;; Homepage - ("homepage" + ("redalder-homepage" :base-directory ,(expand-file-name "./home") :recursive nil :base-extension "org" @@ -84,7 +112,7 @@ ;; Contact - ("contact" + ("redalder-contact" :base-directory ,(expand-file-name "./home") :recursive nil :base-extension "org" @@ -96,7 +124,7 @@ :publishing-function org-html-publish-to-templated-html) ;; Links - ("links" + ("redalder-links" :base-directory ,(expand-file-name "./home") :recursive nil :base-extension "org" @@ -107,19 +135,46 @@ :html-template ,(templated-html-load-template "./templates/empty.html") :publishing-function org-html-publish-to-templated-html) - ;; Static images and css and js - ("assets" + ;; Static images and css and js for redalder.org + ("redalder-assets" :base-directory ,(expand-file-name "./assets/") :publishing-directory ,(expand-file-name "./public_html/") :recursive t - :base-extension "\\(ttf\\|svg\\|jpg\\|gif\\|png\\|css\\|js\\|el\\|nb\\|ipynb\\|pdf\\|xml\\)" + :base-extension ,magic_rb/asset-include + :publishing-function org-publish-attachment) + + + ("nixng-examples" + :base-directory ,(expand-file-name "./nixng/examples/") + :base-extension "org" + :publishing-directory ,(expand-file-name "./public_html/") + :html-template ,(templated-html-load-template "./templates/example.html") + :publishing-function org-html-publish-to-templated-html) + + ;; Static images and css and js for nixng.org + ("nixng-assets" + :base-directory ,(expand-file-name "./assets/") + :publishing-directory ,(expand-file-name "./public_html/") + :recursive t + :base-extension ,magic_rb/asset-include :publishing-function org-publish-attachment) ;; top-level trigger - ("publish" - :components ("blog" "assets" "homepage" "contact" "links")))) + ("redalder-publish" + :components ("redalder-blog" + "redalder-assets" + "redalder-homepage" + "redalder-contact" + "redalder-links")) -(org-publish "publish" t) + ("nixng-publish" + :components ("nixng-assets" + "nixng-examples")))) + +(cond ((member "redalder.org" command-line-args-left) + (org-publish "redalder-publish" t)) + ((member "nixng.org" command-line-args-left) + (org-publish "nixng-publish"))) (provide 'make) ;;; make.el ends here diff --git a/nixng/examples/apache.org b/nixng/examples/apache.org new file mode 100644 index 0000000..f5ff7dd --- /dev/null +++ b/nixng/examples/apache.org @@ -0,0 +1,102 @@ +#+NAME: example +#+BEGIN_SRC nix :exports none +nglib: +(nglib "x86_64-linux").makeSystem { + system = "x86_64-linux"; + name = "nixng-apache"; + config = ({ pkgs, config, ... }: + let + ids = config.ids; + in + { + config = { + dumb-init = { + enable = true; + type.services = {}; + }; + init.services.apache2 = { + shutdownOnExit = true; + ensureSomething.link."documentRoot" = { + src = "${pkgs.apacheHttpd}/htdocs"; + dst = "/var/www"; + }; + }; + services.apache2 = { + enable = true; + envsubst = true; + configuration = [ + { + LoadModule = [ + [ "mpm_event_module" "modules/mod_mpm_event.so" ] + [ "log_config_module" "modules/mod_log_config.so" ] + [ "unixd_module" "modules/mod_unixd.so" ] + [ "authz_core_module" "modules/mod_authz_core.so" ] + [ "dir_module" "modules/mod_dir.so" ] + [ "mime_module" "modules/mod_mime.so" ] + ]; + } + { + Listen = "0.0.0.0:80"; + + ServerRoot = "/var/www"; + ServerName = "blowhole"; + PidFile = "/httpd.pid"; + + DocumentRoot = "/var/www"; + + User = "www-data"; + Group = "www-data"; + } + + { + ErrorLog = "/dev/stderr"; + TransferLog = "/dev/stdout"; + + LogLevel = "info"; + } + + { + AddType = [ + [ "image/svg+xml" "svg" "svgz" ] + ]; + AddEncoding = [ "gzip" "svgz" ]; + + TypesConfig = "${pkgs.apacheHttpd}/conf/mime.types"; + } + + { + Directory = { + "/" = { + Require = [ "all" "denied" ]; + Options = "SymlinksIfOwnerMatch"; + }; + }; + + VirtualHost = { + "*:80" = { + Directory = { + "/var/www" = { + Require = [ "all" "granted" ]; + Options = [ "-Indexes" "+FollowSymlinks" ]; + DirectoryIndex = "\${DIRECTORY_INDEX:-index.html}"; + }; + }; + }; + }; + } + ]; + }; + }; + }); +} +#+END_SRC + +#+NAME: command-docker +#+BEGIN_SRC fundamental + nix run git+https://gitea.redalder.org/Magic_RB/NixNG?rev=d5146db73cfd31712950608560a387ad71243cee#nginxSystem.config.system.build.ociImage.stream && ./result | docker load +#+END_SRC + +#+NAME: command-podman +#+BEGIN_SRC fundamental + nix run git+https://gitea.redalder.org/Magic_RB/NixNG?rev=d5146db73cfd31712950608560a387ad71243cee#nginxSystem.config.system.build.ociImage.stream && ./result | podman load +#+END_SRC diff --git a/templates/example.html b/templates/example.html new file mode 100644 index 0000000..a70bc1d --- /dev/null +++ b/templates/example.html @@ -0,0 +1,26 @@ + + + {{:include "head.html"}} + + {{:include "navbar.html"}} +
+ +
+ {{:if with-title}}

{{title}}

{{:endif}} + +
+{{magic_rb/source-with-name "example" 'src-block :value}}
+		
+ +
+{{magic_rb/source-with-name "command-docker" 'src-block :value}}
+		
+ +
+{{magic_rb/source-with-name "command-podman" 'src-block :value}}
+		
+
+ +
+ + From f34d6fa4fa45da97d0fe391cf9eb301266b85a33 Mon Sep 17 00:00:00 2001 From: Magic_RB Date: Mon, 24 May 2021 00:10:12 +0200 Subject: [PATCH 2/2] Htmlize code block highlighting Signed-off-by: Magic_RB --- README.md | 1 + assets/css/org.css | 1287 +++++++++++++++++++++++++++++++++++++++++++ flake.lock | 53 +- flake.nix | 81 ++- make.el | 23 +- templates/head.html | 1 + 6 files changed, 1423 insertions(+), 23 deletions(-) create mode 100644 assets/css/org.css diff --git a/README.md b/README.md index d9bfd3b..b4fa3b0 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # website +To update the `org.css` file, you need to run `nix build .#generateCss.x86_64-linux && ./result` in the project root. This is only necessary when `modus-themes` is updated, not when a new major mode is added. diff --git a/assets/css/org.css b/assets/css/org.css new file mode 100644 index 0000000..27630c2 --- /dev/null +++ b/assets/css/org.css @@ -0,0 +1,1287 @@ + diff --git a/flake.lock b/flake.lock index 04ee96b..9fd3f5e 100644 --- a/flake.lock +++ b/flake.lock @@ -16,6 +16,38 @@ "type": "github" } }, + "hcl-mode": { + "flake": false, + "locked": { + "lastModified": 1594425120, + "narHash": "sha256-Ai3OpQPmEQg96Q4JRJJM7vUY8G23l0FUGb1lQsU7SRY=", + "owner": "purcell", + "repo": "emacs-hcl-mode", + "rev": "e12b1df2ca28d2b06c471cd709c038a2dc0bcdbd", + "type": "github" + }, + "original": { + "owner": "purcell", + "repo": "emacs-hcl-mode", + "type": "github" + } + }, + "modus-themes": { + "flake": false, + "locked": { + "lastModified": 1621753731, + "narHash": "sha256-HFYsSPJWAY2/lYk8u1UxHMoe2l8taI6BvDZDfIO0pnE=", + "owner": "protesilaos", + "repo": "modus-themes", + "rev": "11006063c2f294adad827d42ab04ee239e85eb64", + "type": "github" + }, + "original": { + "owner": "protesilaos", + "repo": "modus-themes", + "type": "github" + } + }, "nixng": { "inputs": { "nixpkgs": "nixpkgs" @@ -78,9 +110,28 @@ "root": { "inputs": { "emacs-htmlize": "emacs-htmlize", + "hcl-mode": "hcl-mode", + "modus-themes": "modus-themes", "nixng": "nixng", "nixpkgs": "nixpkgs_2", - "org-thtml": "org-thtml" + "org-thtml": "org-thtml", + "web-mode": "web-mode" + } + }, + "web-mode": { + "flake": false, + "locked": { + "lastModified": 1612115905, + "narHash": "sha256-wZ+Sneh+vulcSs+n9fXHG321k9BauBiQvVJ6zw+cWrM=", + "owner": "fxbois", + "repo": "web-mode", + "rev": "8ef47935d638902ba35a557cae5edd6ab6ab1346", + "type": "github" + }, + "original": { + "owner": "fxbois", + "repo": "web-mode", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index c8bbb1e..74dac44 100644 --- a/flake.nix +++ b/flake.nix @@ -1,17 +1,24 @@ { inputs = { nixpkgs.url = "nixpkgs"; - org-thtml = { - url = "github:juanjosegarciaripoll/org-thtml"; - flake = false; - }; - emacs-htmlize = { - url = "github:hniksic/emacs-htmlize"; - flake = false; - }; + + org-thtml = { url = "github:juanjosegarciaripoll/org-thtml"; flake = false; }; + emacs-htmlize = { url = "github:hniksic/emacs-htmlize"; flake = false; }; + modus-themes = { url = "github:protesilaos/modus-themes"; flake = false; }; + web-mode = { url = "github:fxbois/web-mode"; flake = false; }; + hcl-mode = { url = "github:purcell/emacs-hcl-mode"; flake = false; }; }; - outputs = { self, nixpkgs, nixng, org-thtml, emacs-htmlize, ... }@inputs: + outputs = { self + , nixpkgs + , nixng + , org-thtml + , emacs-htmlize + , modus-themes + , web-mode + , hcl-mode + , ... + }@inputs: let supportedSystems = [ "x86_64-linux" "i686-linux" "aarch64-linux" ]; forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system); @@ -20,13 +27,23 @@ name = which; version = "0.1"; src = ./.; - nativeBuildInputs = [ pkgs.emacs ]; + nativeBuildInputs = [ pkgs.utillinux pkgs.emacs ]; buildPhase = '' - cp ${org-thtml}/ox-thtml.el ./ox-thtml.el - cp ${emacs-htmlize}/htmlize.el ./htmlize.el - mkdir tmp && export HOME=$(pwd)/tmp - emacs --script ./make.el -- ${which} + export TMPDIR="$(mktemp -d)" HOME=$(pwd)/tmp + emacs -nw --fg-daemon & + + timeout 10 bash -c 'until [ -e $TMPDIR/emacs$(id -u) ] ; do sleep 0.1 ; done' + + emacsclient -e $'(add-to-list \'load-path "${org-thtml}")' + emacsclient -e $'(add-to-list \'load-path "${modus-themes}")' + emacsclient -e $'(add-to-list \'load-path "${emacs-htmlize}")' + emacsclient -e $'(add-to-list \'load-path "${web-mode}")' + emacsclient -e $'(add-to-list \'load-path "${hcl-mode}")' + + emacsclient -e '(load-file "./make.el")' + emacsclient -e '(magic_rb/publish-website "${which}")' + emacsclient -e '(kill-emacs)' find public_html -name 'sitemap.*' -exec rm {} \; ''; @@ -64,6 +81,42 @@ '' ); + generateCss = forAllSystems (system: + let + pkgs = import nixpkgs { inherit system; }; + + script = pkgs.writeText "init.el" + '' + (add-to-list 'load-path "${modus-themes}") + (add-to-list 'load-path "${emacs-htmlize}") + + (require 'org) + (require 'ox) + (require 'ox-html) + (require 'modus-themes) + + (load-theme 'modus-operandi t nil) + + (org-html-htmlize-generate-css) + (with-current-buffer "*html*" + (write-file (getenv "OUTFILE"))) + + (kill-emacs) + ''; + in + pkgs.writeShellScript "generate-css" + '' + export PATH=$PATH:${pkgs.emacs}/bin + + export OUTFILE="$(mktemp)" TMPDIR="$(mktemp -d)" HOME=$TMPDIR + emacs -l ${script} + + mv $OUTFILE ./assets/css/org.css + + rm -r $TMPDIR + '' + ); + defaultPackage = forAllSystems (system: self.website.${system} ); diff --git a/make.el b/make.el index 38769b7..d9aca9b 100644 --- a/make.el +++ b/make.el @@ -3,9 +3,10 @@ ;;; ;;; Code: -(load-file "./ox-thtml.el") -;; (load-file "./htmlize.el") +(package-initialize) + (require 'org) + (require 'ox) (require 'ox-html) @@ -13,6 +14,10 @@ (unless (file-exists-p d) (make-directory d))) +(require 'web-mode) +(require 'hcl-mode) +(ignore-errors (require 'ox-thtml)) + ;; https://alhassy.github.io/AlBasmala.html#Floating-TOC (advice-add 'org-html--translate :before-until 'display-toc-as-toc) (defun display-toc-as-toc (phrase info) @@ -27,9 +32,9 @@ org-export-headline-levels 6 ; emacs-htmlize does not work when Emacs is ran in =script= mode unfortunately ;; org-html-html5-fancy t - ;; org-html-htmlize-output-type 'inline-css - ) + org-html-htmlize-output-type 'css) + (defvar magic_rb/asset-include "\\(ttf\\|svg\\|jpg\\|gif\\|png\\|css\\|js\\|el\\|nb\\|ipynb\\|pdf\\|xml\\)") @@ -171,10 +176,12 @@ :components ("nixng-assets" "nixng-examples")))) -(cond ((member "redalder.org" command-line-args-left) - (org-publish "redalder-publish" t)) - ((member "nixng.org" command-line-args-left) - (org-publish "nixng-publish"))) +(defun magic_rb/publish-website (website) + "Publish WEBSITE." + (cond ((string= website "redalder.org") + (org-publish "redalder-publish" t)) + ((string= website "nixng.org") + (org-publish "nixng-publish")))) (provide 'make) ;;; make.el ends here diff --git a/templates/head.html b/templates/head.html index a50544b..4fa8203 100644 --- a/templates/head.html +++ b/templates/head.html @@ -2,6 +2,7 @@ {{title}} +