Skip to content

Commit 4dac6d8

Browse files
committed
feat: adjust notes dir
1 parent 53074af commit 4dac6d8

1 file changed

Lines changed: 51 additions & 80 deletions

File tree

README.org

Lines changed: 51 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,12 @@ from: https://github.com/doomemacs/doomemacs/blob/master/lisp/doom-start.el
440440
;; 外部配置文件目录
441441
(defconst my-etc-dir (expand-file-name "etc" user-emacs-directory))
442442

443-
;; 存放代码的目录
444443
(if sys-is-windows
445-
(defconst my-code-dir (expand-file-name "D:/Code"))
446-
(defconst my-code-dir (expand-file-name "~/Code")))
444+
(defconst my-dir-prefix (expand-file-name "D:/"))
445+
(defconst my-dir-prefix (expand-file-name "~")))
446+
447+
;; 存放代码的目录
448+
(defconst my-code-dir (expand-file-name "Code" my-dir-prefix))
447449

448450
;; 开源代码
449451
(defconst my-code-opensource-dir (expand-file-name "Github" my-code-dir))
@@ -454,35 +456,17 @@ from: https://github.com/doomemacs/doomemacs/blob/master/lisp/doom-start.el
454456
;; 个人项目代码
455457
(defconst my-code-project-dir (expand-file-name "Project" my-code-dir))
456458

457-
;; 练习代码或实例代码,这里面一般根据语言再分一层
458-
(defconst my-code-demo-dir (expand-file-name "Demo" my-code-dir))
459-
460459

461460
;; 数据目录
462-
(if sys-is-windows
463-
(defconst my-docs-dir (expand-file-name "D:/Docs"))
464-
(if sys-is-wsl2
465-
(defconst my-docs-dir (expand-file-name "/mnt/d/Docs"))
466-
(defconst my-docs-dir (expand-file-name "~/Docs"))))
461+
(defconst my-docs-dir (expand-file-name "Docs" my-dir-prefix))
467462

468463
;; 笔记目录
469464
(defconst my-notes-dir (expand-file-name "Notes" my-docs-dir))
470465

471-
;; 博客相关目录
472-
(if sys-is-windows
473-
(defconst my-blogs-dir (expand-file-name "D:/BaiduSyncdisk/Blogs"))
474-
(if sys-is-wsl2
475-
(defconst my-blogs-dir (expand-file-name "/mnt/d/BaiduSyncdisk/Blogs"))
476-
(defconst my-blogs-dir (expand-file-name "~/BaiduSyncdisk/Blogs"))))
477-
(defconst my-blogs-org-dir (expand-file-name "org" my-blogs-dir))
478-
(defconst my-blogs-image-dir (expand-file-name "images" my-blogs-dir))
479-
480-
;; Org 相关目录
481-
(if sys-is-windows
482-
(defconst my-org-dir (expand-file-name "Org" my-docs-dir))
483-
(if sys-is-wsl2
484-
(defconst my-org-dir (expand-file-name "Org" my-docs-dir))
485-
(defconst my-org-dir (expand-file-name "Org" my-docs-dir))))
466+
(defconst my-notes-image-dir (expand-file-name "Images" my-notes-dir))
467+
468+
(defconst my-org-dir (expand-file-name "Org" my-docs-dir))
469+
486470
;; 私有文件目录
487471
(defconst my-private-dir (expand-file-name "Private" my-org-dir))
488472

@@ -2505,20 +2489,14 @@ ref:https://github.com/manateelazycat/toggle-one-window
25052489
*** denote
25062490

25072491
#+begin_src elisp
2508-
(use-package denote
2509-
:ban minimal?
2510-
:straight t
2511-
:custom
2512-
(denote-directory my-notes-dir)
2513-
:config
2514-
(defun denote-blog ()
2515-
"Create blog for publish."
2516-
(declare (interactive-only t))
2517-
(interactive)
2518-
(let ((denote-directory my-blogs-org-dir)
2519-
(denote-prompts '(title))
2520-
(denote-org-front-matter
2521-
"#+title: %1$s
2492+
(use-package denote
2493+
:ban minimal?
2494+
:straight t
2495+
:custom
2496+
(denote-directory my-notes-dir)
2497+
:config
2498+
(setq denote-org-front-matter
2499+
"#+title: %1$s
25222500
,#+date: %2$s
25232501
,#+author: xhcoding
25242502
,#+identifier: %4$s
@@ -2527,46 +2505,39 @@ ref:https://github.com/manateelazycat/toggle-one-window
25272505
,#+hugo_categories: %3$s
25282506
,#+hugo_draft: false
25292507

2530-
"
2531-
))
2532-
(call-interactively #'denote-open-or-create)))
2533-
2534-
(defun denote-blog-image-insert (file)
2535-
"Insert image file to blog."
2536-
(declare (interactive-only t))
2537-
(interactive "fImage file: ")
2538-
(let* ((blog-file-title (denote-retrieve-filename-title (buffer-file-name)))
2539-
(blog-image-dir (concat (expand-file-name blog-file-title my-blogs-image-dir) "/"))
2540-
(blog-image-ext (concat "." (file-name-extension file)))
2541-
(blog-default-image-title (concat blog-file-title (format-time-string "-%H%M%S")))
2542-
(blog-image-title (read-string "Image title: " "" nil blog-default-image-title))
2543-
(blog-image-new-name (denote-format-file-name blog-image-dir (denote-retrieve-filename-identifier (buffer-file-name)) nil blog-image-title blog-image-ext nil)))
2544-
(unless (file-directory-p blog-image-dir)
2545-
(make-directory blog-image-dir t))
2546-
(copy-file file blog-image-new-name)
2547-
(insert (format "[[file:%s]]" (file-relative-name blog-image-new-name (file-name-directory (buffer-file-name)))))))
2548-
(defun my-denote-blog-link-ol-export (link description format)
2549-
""
2550-
(let* ((denote-directory my-blogs-org-dir)
2551-
(path-id (denote-link--ol-resolve-link-to-target link :path-id))
2552-
(path (file-relative-name (car path-id))))
2553-
(format "[%s](%s)" description (concat my-hugo-post-url (file-name-sans-extension (downcase path))))))
2554-
2555-
(with-eval-after-load 'org
2556-
(org-link-set-parameters "denote" :export #'my-denote-blog-link-ol-export))
2508+
")
2509+
(defun denote-blog-image-insert (file)
2510+
"Insert image file to blog."
2511+
(declare (interactive-only t))
2512+
(interactive "fImage file: ")
2513+
(let* ((blog-file-title (denote-retrieve-filename-title (buffer-file-name)))
2514+
(blog-image-dir (concat (expand-file-name blog-file-title my-notes-image-dir) "/"))
2515+
(blog-image-ext (concat "." (file-name-extension file)))
2516+
(blog-default-image-title (concat blog-file-title (format-time-string "-%H%M%S")))
2517+
(blog-image-title (read-string "Image title: " "" nil blog-default-image-title))
2518+
(blog-image-new-name (denote-format-file-name blog-image-dir (denote-retrieve-filename-identifier (buffer-file-name)) nil blog-image-title blog-image-ext nil)))
2519+
(unless (file-directory-p blog-image-dir)
2520+
(make-directory blog-image-dir t))
2521+
(copy-file file blog-image-new-name)
2522+
(insert (format "[[file:%s]]" (file-relative-name blog-image-new-name (file-name-directory (buffer-file-name)))))))
2523+
(defun my-denote-blog-link-ol-export (link description format)
2524+
""
2525+
(let* ((denote-directory my-notes-dir)
2526+
(path-id (denote-link--ol-resolve-link-to-target link :path-id))
2527+
(path (file-relative-name (car path-id))))
2528+
(format "[%s](%s)" description (concat my-hugo-post-url (file-name-sans-extension (downcase path))))))
25572529

2530+
(with-eval-after-load 'org
2531+
(org-link-set-parameters "denote" :export #'my-denote-blog-link-ol-export))
25582532

2559-
)
2533+
2534+
)
25602535
#+end_src
25612536

25622537
*** hugo 配置
25632538

25642539
#+begin_src emacs-lisp
2565-
(if sys-is-windows
2566-
(defconst my-hugo-root-dir (expand-file-name "D:/Blog"))
2567-
(if sys-is-wsl2
2568-
(defconst my-hugo-root-dir (expand-file-name "/mnt/d/Blog"))
2569-
(defconst my-hugo-root-dir (expand-file-name "~/Blog"))))
2540+
(defconst my-hugo-root-dir (expand-file-name "Blog" my-dir-prefix))
25702541
(defconst my-hugo-image-url "https://images.xhcoding.cn/blog")
25712542

25722543
(defconst my-hugo-post-url "https://xhcoding.cn/post/")
@@ -2583,12 +2554,12 @@ ref:https://github.com/manateelazycat/toggle-one-window
25832554
:config
25842555
(defun my-hugo--blogs-image-path-p (raw-path)
25852556
(let ((file-path (expand-file-name raw-path)))
2586-
(equal (string-match-p (regexp-quote (expand-file-name my-blogs-image-dir)) file-path) 0)))
2557+
(equal (string-match-p (regexp-quote (expand-file-name my-notes-image-dir)) file-path) 0)))
25872558

25882559
;; D:/Data/Blogs/images/1.png ==> https://images.xhcoding.cn/blog/1.png
25892560
(defun my-hugo--image-path-to-url (raw-path)
25902561
(let ((file-path (expand-file-name raw-path)))
2591-
(concat my-hugo-image-url (string-trim-left file-path my-blogs-image-dir))))
2562+
(concat my-hugo-image-url (string-trim-left file-path my-notes-image-dir))))
25922563

25932564
;; D:/Data/Blogs/images/1.png ==> https://images.xhcoding.cn/blog/1.png
25942565
(defun my-hugo*convert-path-to-url (args)
@@ -2625,10 +2596,10 @@ ref:https://github.com/manateelazycat/toggle-one-window
26252596
(defun my/hugo-export-all-blogs ()
26262597
"Export all blogs."
26272598
(interactive)
2628-
(dolist (file (directory-files my-blogs-org-dir))
2599+
(dolist (file (directory-files my-notes-dir))
26292600
(when (string-equal "org" (file-name-extension file))
26302601
(with-temp-buffer
2631-
(find-file (expand-file-name file my-blogs-org-dir))
2602+
(find-file (expand-file-name file my-notes-org-dir))
26322603
(org-hugo-export-to-md)))))
26332604

26342605
)
@@ -2639,7 +2610,7 @@ ref:https://github.com/manateelazycat/toggle-one-window
26392610
:defer t
26402611
:config
26412612
(setq easy-hugo-basedir (expand-file-name my-hugo-root-dir)
2642-
easy-hugo-postdir (expand-file-name my-blogs-org-dir)
2613+
easy-hugo-postdir (expand-file-name my-notes-dir)
26432614
easy-hugo-org-header t
26442615
easy-hugo-github-deploy-script "deploy.bat"))
26452616

@@ -2671,7 +2642,7 @@ ref:https://github.com/manateelazycat/toggle-one-window
26712642
org-download-display-inline-images 'posframe
26722643
org-download-abbreviate-filename-function 'expand-file-name))
26732644

2674-
(setq-default org-download-image-dir my-blog-img-dir
2645+
(setq-default org-download-image-dir my-notes-image-dir
26752646
org-download-heading-lvl nil)
26762647

26772648

@@ -2717,7 +2688,7 @@ ref:https://github.com/manateelazycat/toggle-one-window
27172688
(url-generic-parse-url link)))))
27182689
(org-file-path (buffer-file-name))
27192690
(org-file-name (file-name-sans-extension (file-name-nondirectory org-file-path)))
2720-
(dirname (expand-file-name org-file-name my-blog-img-dir)))
2691+
(dirname (expand-file-name org-file-name my-notes-image-dir)))
27212692
(when (and (featurep 'org-roam) (string-prefix-p org-roam-directory org-file-path))
27222693
(setq dirname (expand-file-name
27232694
(substring org-file-name (+ 1 (string-match-p "-" org-file-name)))

0 commit comments

Comments
 (0)