mirror of
https://git.sr.ht/~magic_rb/website
synced 2024-11-22 08:04:21 +01:00
Remove sensible heading links
Signed-off-by: Magic_RB <magic_rb@redalder.org>
This commit is contained in:
parent
6b441371bf
commit
d456ffa94d
80
make.el
80
make.el
|
@ -20,85 +20,7 @@
|
|||
TOC
|
||||
</a>"))
|
||||
|
||||
;; https://github.com/alphapapa/unpackaged.el#export-to-html-with-useful-anchors
|
||||
(advice-add #'org-export-get-reference :override #'unpackaged/org-export-get-reference)
|
||||
|
||||
(defun unpackaged/org-export-get-reference (datum info)
|
||||
"Like `org-export-get-reference', except uses heading titles instead of random numbers."
|
||||
(let ((cache (plist-get info :internal-references)))
|
||||
(or (car (rassq datum cache))
|
||||
(let* ((crossrefs (plist-get info :crossrefs))
|
||||
(cells (org-export-search-cells datum))
|
||||
;; Preserve any pre-existing association between
|
||||
;; a search cell and a reference, i.e., when some
|
||||
;; previously published document referenced a location
|
||||
;; within current file (see
|
||||
;; `org-publish-resolve-external-link').
|
||||
;;
|
||||
;; However, there is no guarantee that search cells are
|
||||
;; unique, e.g., there might be duplicate custom ID or
|
||||
;; two headings with the same title in the file.
|
||||
;;
|
||||
;; As a consequence, before re-using any reference to
|
||||
;; an element or object, we check that it doesn't refer
|
||||
;; to a previous element or object.
|
||||
(new (or (cl-some
|
||||
(lambda (cell)
|
||||
(let ((stored (cdr (assoc cell crossrefs))))
|
||||
(when stored
|
||||
(let ((old (org-export-format-reference stored)))
|
||||
(and (not (assoc old cache)) stored)))))
|
||||
cells)
|
||||
(when (org-element-property :raw-value datum)
|
||||
;; Heading with a title
|
||||
(unpackaged/org-export-new-title-reference datum cache))
|
||||
;; NOTE: This probably breaks some Org Export
|
||||
;; feature, but if it does what I need, fine.
|
||||
(org-export-format-reference
|
||||
(org-export-new-reference cache))))
|
||||
(reference-string new))
|
||||
;; Cache contains both data already associated to
|
||||
;; a reference and in-use internal references, so as to make
|
||||
;; unique references.
|
||||
(dolist (cell cells) (push (cons cell new) cache))
|
||||
;; Retain a direct association between reference string and
|
||||
;; DATUM since (1) not every object or element can be given
|
||||
;; a search cell (2) it permits quick lookup.
|
||||
(push (cons reference-string datum) cache)
|
||||
(plist-put info :internal-references cache)
|
||||
reference-string))))
|
||||
|
||||
(defun unpackaged/org-export-new-title-reference (datum cache)
|
||||
"Return new reference for DATUM that is unique in CACHE."
|
||||
(cl-macrolet ((inc-suffixf (place)
|
||||
`(progn
|
||||
(string-match (rx bos
|
||||
(minimal-match (group (1+ anything)))
|
||||
(optional "--" (group (1+ digit)))
|
||||
eos)
|
||||
,place)
|
||||
;; HACK: `s1' instead of a gensym.
|
||||
(-let* (((s1 suffix) (list (match-string 1 ,place)
|
||||
(match-string 2 ,place)))
|
||||
(suffix (if suffix
|
||||
(string-to-number suffix)
|
||||
0)))
|
||||
(setf ,place (format "%s--%s" s1 (cl-incf suffix)))))))
|
||||
(let* ((title (org-element-property :raw-value datum))
|
||||
(ref (url-hexify-string (substring-no-properties title)))
|
||||
(parent (org-element-property :parent datum)))
|
||||
(while (--any (equal ref (car it))
|
||||
cache)
|
||||
;; Title not unique: make it so.
|
||||
(if parent
|
||||
;; Append ancestor title.
|
||||
(setf title (concat (org-element-property :raw-value parent)
|
||||
"--" title)
|
||||
ref (url-hexify-string (substring-no-properties title))
|
||||
parent (org-element-property :parent parent))
|
||||
;; No more ancestors: add and increment a number.
|
||||
(inc-suffixf ref)))
|
||||
ref)))
|
||||
;; DOES NOT WORK https://github.com/alphapapa/unpackaged.el#export-to-html-with-useful-anchors
|
||||
|
||||
(defvar org-publish-project-alist)
|
||||
(setq org-publish-project-alist
|
||||
|
|
Loading…
Reference in a new issue