From ce02550fb5b428bac213986a26307f342c0fa7dc Mon Sep 17 00:00:00 2001 From: Magic_RB Date: Sat, 2 Sep 2023 15:06:32 +0200 Subject: [PATCH] Add org extra blocks support Signed-off-by: Magic_RB --- flake.nix | 97 ++++++++++++++++++++++++++++++++++++-------- home/contact.org | 3 +- home/index.org | 9 ++-- lisp/extra-blocks.el | 37 +++++++++++++++++ make.el | 58 +++++--------------------- templates/index.html | 15 +------ 6 files changed, 132 insertions(+), 87 deletions(-) create mode 100644 lisp/extra-blocks.el diff --git a/flake.nix b/flake.nix index 90dedfb..8217dc9 100644 --- a/flake.nix +++ b/flake.nix @@ -8,6 +8,14 @@ web-mode = { url = "github:fxbois/web-mode"; flake = false; }; hcl-mode = { url = "github:purcell/emacs-hcl-mode"; flake = false; }; yaml-mode = { url = "github:yoshiki/yaml-mode"; flake = false; }; + nix-mode = { url = "github:NixOS/nix-mode"; flake = false; }; + magit = { url = "github:magit/magit"; flake = false; }; + compat = { url = "github:emacs-straight/compat"; flake = false; }; + dash = { url = "github:magnars/dash.el"; flake = false; }; + s-el = { url = "github:magnars/s.el"; flake = false; }; + dockerfile-mode = { url = "github:spotify/dockerfile-mode"; flake = false; }; + org-special-block-extras = { url = "github:alhassy/org-special-block-extras"; flake = false; }; + lf = { url = "github:alhassy/lf"; flake = false; }; }; outputs = { self @@ -19,11 +27,47 @@ , web-mode , hcl-mode , yaml-mode + , nix-mode + , magit + , compat + , dash + , s-el + , dockerfile-mode + , org-special-block-extras + , lf , ... }@inputs: let + inherit (nixpkgs.lib) + genAttrs + concatMapStringsSep; + supportedSystems = [ "x86_64-linux" "i686-linux" "aarch64-linux" ]; - forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system); + forAllSystems = f: genAttrs supportedSystems (system: f system); + packages = [ + "modus-themes" + "org-thtml" + "emacs-htmlize" + "web-mode" + "hcl-mode" + "modus-themes" + "yaml-mode" + "nix-mode" + "magit" + "compat" + "dash" + "s-el" + "dockerfile-mode" + "org-special-block-extras" + "lf" + ]; + loadPackages = pkgs: + pkgs.writeText "packages.el" + (concatMapStringsSep "\n" (x: '' + (if (file-exists-p "${inputs.${x}}/lisp") + (add-to-list 'load-path "${inputs.${x}}/lisp") + (add-to-list 'load-path "${inputs.${x}}")) + '') packages); site = pkgs: which: pkgs.stdenv.mkDerivation { name = which; @@ -33,26 +77,23 @@ buildPhase = '' export TMPDIR="$(mktemp -d)" HOME=$(pwd)/tmp - emacs -nw --fg-daemon & + emacs -nw --fg-daemon --debug-init & 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 $'(add-to-list \'load-path "${yaml-mode}")' + emacsclient -e $'(load-file "${loadPackages pkgs}")' + + emacsclient -e $'(add-to-list \'load-path "'"$(pwd)"'/lisp")' emacsclient -e '(load-file "./make.el")' emacsclient -e '(magic_rb/publish-website "${which}")' - emacsclient -e '(kill-emacs)' + emacsclient -e '(kill-emacs)' find public_html -name 'sitemap.*' -exec rm {} \; ''; installPhase = '' - mkdir -p $out + mkdir -p $out cp -r public_html/* $out ''; }; @@ -74,7 +115,7 @@ website = forAllSystems (system: let - pkgs = import nixpkgs { inherit system; }; + pkgs = import nixpkgs { inherit system; }; in pkgs.runCommandNoCC "website" {} '' @@ -86,20 +127,28 @@ generateCss = forAllSystems (system: let - pkgs = import nixpkgs { inherit system; }; + pkgs = import nixpkgs { inherit system; }; script = pkgs.writeText "init.el" '' - (add-to-list 'load-path "${modus-themes}") - (add-to-list 'load-path "${emacs-htmlize}") + (load-file "${loadPackages pkgs}") + + (require 'nix-mode) + (require 'web-mode) + (require 'hcl-mode) + (require 'yaml-mode) (require 'org) (require 'ox) (require 'ox-html) (require 'modus-themes) - (load-theme 'modus-operandi t nil) - + (defface modus-themes-cyan-subtle + '((t :inherit modus-themes-subtle-cyan)) + "") + + (load-theme 'modus-vivendi t nil) + (org-html-htmlize-generate-css) (with-current-buffer "*html*" (write-file (getenv "OUTFILE"))) @@ -110,9 +159,9 @@ pkgs.writeShellScript "generate-css" '' export PATH=$PATH:${pkgs.emacs}/bin - + export OUTFILE="$(mktemp)" TMPDIR="$(mktemp -d)" HOME=$TMPDIR - emacs -l ${script} + emacs -l ${builtins.trace "modus: ${modus-themes}" script} --debug-init mv $OUTFILE ./assets/css/org.css @@ -123,5 +172,17 @@ defaultPackage = forAllSystems (system: self.website.${system} ); + + devShells = forAllSystems (system: + let pkgs = import nixpkgs { inherit system; }; + in + { + default = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ + httplz + ]; + }; + } + ); }; } diff --git a/home/contact.org b/home/contact.org index 5b1e083..2e0dd18 100644 --- a/home/contact.org +++ b/home/contact.org @@ -1,2 +1,3 @@ -- Discord: =Magic_RB#6785= +- Discord: =magic_rb.#0= +- Matrix: =@magic_rb:matrix.redalder.org= - PGP: =0F49 1A57 B4DF 4313 6CD4 AB6B F07E 558C D1E6 999F= diff --git a/home/index.org b/home/index.org index f16e0f3..caffbc9 100644 --- a/home/index.org +++ b/home/index.org @@ -1,7 +1,4 @@ -#+ATTR_CTAG: project -#+ATTR_CLINK: https://github.com/MagicRB/NixNG -#+ATTR_CIMAGE: /icons/nix-ng-greener-no-gradient.svg -#+BEGIN_SRC fundamental +#+begin_card NixNG :link "https://github.com/nix-community/NixNG" :image "/icons/nix-ng-greener-no-gradient.svg" A NixOS derivative with simpler design, currently replacing systemd with runit, - aiming to deliver lighter systems and containers. -#+END_SRC + aiming to deliver lighter systems and containers. TEST +#+end_card diff --git a/lisp/extra-blocks.el b/lisp/extra-blocks.el new file mode 100644 index 0000000..1dbf382 --- /dev/null +++ b/lisp/extra-blocks.el @@ -0,0 +1,37 @@ +(require 'org-special-block-extras) + +(org-defblock note + (title) + "Test" + (format + (pcase backend + (`html "
+ + + %s + + %s +
")) + title contents)) + +(org-defblock + card (name "Card" link "" image "") + "Card" + (cl-case backend + ((html templated-html) + (concat + "" + "
" + " " + "
" + "
" + "

" name "

" + "

" + " " contents + "

" + "
" + "
" + "
")) + (t "ERROR"))) + +(provide 'extra-blocks) diff --git a/make.el b/make.el index bc6278b..5473b95 100644 --- a/make.el +++ b/make.el @@ -16,9 +16,14 @@ (unless (file-exists-p d) (make-directory d))) -(require 'web-mode) -(require 'hcl-mode) -(require 'yaml-mode) +(require 'org-special-block-extras) +(add-hook #'org-mode-hook #'org-special-block-extras-mode) + +(defun my-org--support-special-blocks-with-args (backend) + (let ((fbackend (if (equal backend '(templated-html)) 'html backend))) + `(,fbackend))) +(advice-add 'org--support-special-blocks-with-args :filter-args #'my-org--support-special-blocks-with-args) + (ignore-errors (require 'ox-thtml)) ;; https://alhassy.github.io/AlBasmala.html#Floating-TOC @@ -29,6 +34,8 @@ TOC ")) +(require 'extra-blocks) + ;; DOES NOT WORK https://github.com/alphapapa/unpackaged.el#export-to-html-with-useful-anchors (setq org-export-with-sub-superscripts '{} @@ -41,51 +48,6 @@ (defvar magic_rb/asset-include "\\(ttf\\|svg\\|jpg\\|gif\\|png\\|css\\|js\\|el\\|nb\\|ipynb\\|pdf\\|xml\\)") -(cl-defstruct (magic_rb/card (:constructor magic_rb/card-create) - (:copier nil)) - link image description) - -(defun magic_rb/cards-with-tag (tag) - (let ((symbol 'src-block) - (path buffer-file-name)) - (mapcar - (lambda (object) - (magic_rb/card-create - :link (car (org-element-property :attr_clink object)) - :image (car (org-element-property :attr_cimage object)) - :description (org-element-property :value object))) - (with-temp-buffer - (insert-file-contents path) - - (org-element-map (org-element-parse-buffer) symbol - (lambda (object) - (if (string-equal (car (org-element-property :attr_ctag object)) tag) - object - nil)) nil nil nil t))))) - -(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) diff --git a/templates/index.html b/templates/index.html index dffade4..0c242b6 100644 --- a/templates/index.html +++ b/templates/index.html @@ -10,20 +10,7 @@ Open Source and Mental Health
-{{:each (magic_rb/cards-with-tag "project")}} - -
- -
-
-

NixNG

-

- {{magic_rb/card-description item}} -

-
-
-
-{{:endeach}} + {{contents}}