Merge pull request 'htmlize-highlighting' (#2) from htmlize-highlighting into master

https://knowyourmeme.com/memes/obama-awards-obama-a-medal

Reviewed-on: https://gitea.redalder.org/Magic_RB/website/pulls/2
This commit is contained in:
Magic_RB 2021-06-10 16:29:28 +00:00
commit 86c26238a7
9 changed files with 1645 additions and 44 deletions

View file

@ -1,2 +0,0 @@
all:
emacs --script make.el

View file

@ -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.

1287
assets/css/org.css Normal file

File diff suppressed because it is too large Load diff

View file

@ -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"
}
}
},

121
flake.nix
View file

@ -1,36 +1,49 @@
{
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);
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 ];
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
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 {} \;
'';
@ -40,12 +53,72 @@
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
''
);
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}
);
};
}

96
make.el
View file

@ -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,14 +32,42 @@
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\\)")
(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 +86,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 +99,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 +117,7 @@
;; Contact
("contact"
("redalder-contact"
:base-directory ,(expand-file-name "./home")
:recursive nil
:base-extension "org"
@ -96,7 +129,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 +140,48 @@
: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"))))
(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

102
nixng/examples/apache.org Normal file
View file

@ -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

26
templates/example.html Normal file
View file

@ -0,0 +1,26 @@
<!doctype html>
<html lang="en">
{{:include "head.html"}}
<body>
{{:include "navbar.html"}}
<div id="organizer">
<div class="sidebar">{{org-html-toc 2 info}}</div>
<div id="content" class="textual">
{{:if with-title}}<h1>{{title}}</h1>{{:endif}}
<pre>
{{magic_rb/source-with-name "example" 'src-block :value}}
</pre>
<pre>
{{magic_rb/source-with-name "command-docker" 'src-block :value}}
</pre>
<pre>
{{magic_rb/source-with-name "command-podman" 'src-block :value}}
</pre>
</div>
<div class="sidebar"></div>
</div>
</body>
</html>

View file

@ -2,6 +2,7 @@
<title>{{title}}</title>
<link rel="stylesheet" href="/css/style.css"/>
<link rel="stylesheet" href="/css/org.css"/>
<link rel="icon" href="/icons/favicon-512x512.png" type="image/png" sizes="512x512">
</head>