mirror of
https://github.com/SqrtMinusOne/sqrtminusone.github.io.git
synced 2025-12-10 15:53:03 +03:00
fix: slugs
This commit is contained in:
parent
d234d2df93
commit
8ed5a5305f
1 changed files with 30 additions and 0 deletions
|
|
@ -31,8 +31,38 @@
|
|||
:ensure t)
|
||||
|
||||
(setq org-make-toc-link-type-fn #'org-make-toc--link-entry-org)
|
||||
|
||||
(defvar-local my/org-hugo-heading-slugs nil)
|
||||
|
||||
(defun my/increase-slug (string)
|
||||
(if (string-match (rx "-" (1+ num) eos) string)
|
||||
(replace-match
|
||||
(concat
|
||||
"-"
|
||||
(thread-first
|
||||
(match-string 0 string)
|
||||
(substring 1)
|
||||
(string-to-number)
|
||||
(+ 1)
|
||||
(number-to-string)))
|
||||
t t string)
|
||||
(concat string "-" "1")))
|
||||
|
||||
(defun my/org-hugo-get-heading-slug (element info)
|
||||
(let* ((title (org-export-data-with-backend
|
||||
(org-element-property :title element) 'md info))
|
||||
(slug (org-string-nw-p (org-hugo-slug title :allow-double-hyphens))))
|
||||
(unless my/org-hugo-heading-slugs
|
||||
(setq my/org-hugo-heading-slugs (make-hash-table :test 'equal)))
|
||||
(unless (or (null slug) (string-empty-p slug))
|
||||
(while (gethash slug my/org-hugo-heading-slugs)
|
||||
(setq slug (my/increase-slug slug)))
|
||||
(puthash slug t my/org-hugo-heading-slugs))
|
||||
slug))
|
||||
|
||||
(setq org-hugo-anchor-functions '(org-hugo-get-page-or-bundle-name
|
||||
org-hugo-get-custom-id
|
||||
my/org-hugo-get-heading-slug
|
||||
org-hugo-get-md5))
|
||||
|
||||
(setq org-hugo-section "configs")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue