Add org extra blocks support

Signed-off-by: Magic_RB <magic_rb@redalder.org>
This commit is contained in:
Magic_RB 2023-09-02 15:06:32 +02:00
parent 9a678533ce
commit ce02550fb5
No known key found for this signature in database
GPG key ID: 08D5287CC5DDCA0E
6 changed files with 132 additions and 87 deletions

View file

@ -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
];
};
}
);
};
}

View file

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

View file

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

37
lisp/extra-blocks.el Normal file
View file

@ -0,0 +1,37 @@
(require 'org-special-block-extras)
(org-defblock note
(title)
"Test"
(format
(pcase backend
(`html "<details class=\"note\">
<summary>
<i class=\"fa-regular fa-comment\"></i>
%s
</summary>
%s
</details>"))
title contents))
(org-defblock
card (name "Card" link "" image "")
"Card"
(cl-case backend
((html templated-html)
(concat
"<a class=\"card-link\" href=\"" link "\">"
" <div class=\"card-entry\">"
" <img src=\"" image "\" class=\"card-icon\"/>"
" <div class=\"card-separator\"></div>"
" <div class=\"card-body\">"
" <h4 class=\"card-heading\">" name "</h4>"
" <p class=\"card-content\">"
" " contents
" </p>"
" </div>"
" </div>"
"</a>"))
(t "ERROR")))
(provide 'extra-blocks)

58
make.el
View file

@ -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
</a>"))
(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)

View file

@ -10,20 +10,7 @@
Open Source and Mental Health
</a>
<div class="card-toplevel">
{{:each (magic_rb/cards-with-tag "project")}}
<a class="card-link" href="{{magic_rb/card-link item}}">
<div class="card-entry">
<img src="{{magic_rb/card-image item}}" class="card-icon"/>
<div class="card-separator"></div>
<div class="card-body">
<h4 class="card-heading"> NixNG </h4>
<p class="card-content">
{{magic_rb/card-description item}}
</p>
</div>
</div>
</a>
{{:endeach}}
{{contents}}
</div>
</div>
<div class="sidebar"></div>