使用自定义Hugo主题后调整ox-hugo导出
2023年11月17日 2023年11月17日
说明
- 不需要修改图片格式
- 笔记分区名称发生改变
- 仍需在图片链接开头加上
/
注释修改图片格式函数
- my/replace-pic-link-format
- my/amend-pic-link
- my/amend-pic-link-for-all
在图片链接开头加上/
替换markdown文件图片链接格式
1(defun my/amend-pic-link-file (file) 2 (interactive) 3 (with-current-buffer (find-file-noselect file) 4 (beginning-of-buffer) 5 (while (re-search-forward (rx "{{" "< figure src=\"" (group (0+ (not "\""))) "\" width=\"" (group (0+ (not "\""))) "\" >}}") nil t) 6 (let ((src (string-join (mapcar #'string (match-string 1)))) 7 (width (string-join (mapcar #'string (match-string 2))))) 8 (replace-match (format (concat "{{" "< figure src=\"/%s\" width=\"%s\">}}") src width)) 9 ) 10 ) 11 (save-buffer) 12 (kill-buffer) 13 ) 14 )
替换子树导出文件图片链接格式
1(defun my/amend-pic-link-file-name (export-name) 2 (interactive) 3 (my/amend-pic-link-file (concat (my/subtree-path-str export-name) ".md")) 4 )
替换文件内所有子树导出文件图片链接格式
1(defun my/amend-pic-link-pack () 2 (interactive) 3 (beginning-of-buffer) 4 (while (re-search-forward (rx ":" "EXPORT_FILE_NAME" ": " (group (0+ (not "\n"))) "\n") nil t) 5 (my/amend-pic-link-file-name (string-join (mapcar #'string (match-string 1)))) 6 ) 7 )
修改导出函数
不再调用修改图片格式函数
- 注释之前的定义
- my/ox-hugo-export-subtree
- my/ox-hugo-export-all-subtrees
- my/ox-hugo-export-subtree
- 重新定义
导出子树
光标所在子树
1(defun my/ox-hugo-export-subtree () 2 (interactive) 3 (save-excursion 4 (outline-next-heading) 5 (when (re-search-backward (rx ":" "EXPORT_FILE_NAME" ": " (group (0+ (not "\n"))) "\n") nil t) 6 (let* ((export-name (string-join (mapcar #'string (match-string 1)))) 7 (subtree (my/copy-org-subtree)) 8 (options (my/copy-org-options)) 9 (weight (my/compute-weight)) 10 (slotlist '()) 11 (slotlist (my/compute-subtree-path export-name)) 12 (slot) 13 (section) 14 (cur-level)) 15 (with-temp-buffer 16 (insert options) 17 (insert subtree) 18 (org-mode) 19 (my/delete-timestamp-link) 20 (my/replace-ue-project-file-link) 21 (my/replace-ue-engine-file-link) 22 (my/replace-roam-link) 23 (pop slotlist) 24 (setq slotlist (reverse slotlist)) 25 (pop slotlist) 26 (setq slotlist (reverse slotlist)) 27 (dolist (item slotlist) 28 (setq slot (concat slot "/" item)) 29 ) 30 (beginning-of-buffer) 31 (when (re-search-forward (rx "+" "HUGO_SECTION" ": " (group (0+ (not "\n")))) nil t) 32 (setq section (string-join (mapcar #'string (match-string 1)))) 33 (replace-match (format (concat "+" "HUGO_SECTION" ": %s") (concat section slot))) 34 ) 35 (beginning-of-buffer) 36 (when (re-search-forward (rx "EXPORT_HUGO_WEIGHT" ": " (group (0+ (not "\n")))) nil t) 37 (replace-match (format (concat "EXPORT_HUGO_WEIGHT" ": %s") weight)) 38 ) 39 (beginning-of-buffer) 40 (outline-next-heading) 41 (setq cur-level (funcall outline-level)) 42 (while (/= 1 cur-level) 43 (org-shiftmetaleft) 44 (setq cur-level (funcall outline-level)) 45 ) 46 (org-hugo-export-wim-to-md) 47 (my/amend-pic-link-file-name export-name) 48 ) 49 ) 50 ) 51 ) 52 ) 53(global-set-key (kbd "C-c h s") 'my/ox-hugo-export-subtree)
文件内所有子树
1(defun my/ox-hugo-export-all-subtrees () 2 (interactive) 3 (save-excursion 4 (let ((buf-content (buffer-string))) 5 (with-temp-buffer 6 (insert buf-content) 7 (org-mode) 8 (my/delete-timestamp-link) 9 (my/replace-ue-project-file-link) 10 (my/replace-ue-engine-file-link) 11 (my/replace-roam-link) 12 (org-hugo-export-wim-to-md :all-subtrees) 13 (my/amend-pic-link-pack) 14 ) 15 ) 16 ) 17 ) 18(global-set-key (kbd "C-c h a") 'my/ox-hugo-export-all-subtrees)
修改Roam笔记路径前缀
1;; (setq my/roam-prefix "hugo/content/")