From 690878ddf95c14dffab96bbea287c7391633449f Mon Sep 17 00:00:00 2001 From: k4i Date: Wed, 18 Jan 2023 22:42:48 +0800 Subject: [PATCH] update writing guide --- content-org/all-posts.en.org | 69 ++++++++++++++++- .../writing-guide--org-plus-ox-hugo/index.md | 75 +++++++++++++++++-- 2 files changed, 133 insertions(+), 11 deletions(-) diff --git a/content-org/all-posts.en.org b/content-org/all-posts.en.org index 7378b1e..e3470ca 100644 --- a/content-org/all-posts.en.org +++ b/content-org/all-posts.en.org @@ -67,7 +67,7 @@ So instead of editing ~.md~ files under ~content~ folder, now I write ~.org~ fil ** Create new post -Invoking org-capture-templates function, and choose hugo post template, as shown in Figure [[fig:org-capture-template-ox-hugo]] +Invoking org-capture-templates (=SPC o c=) function, and choose hugo post template, as shown in Figure [[fig:org-capture-template-ox-hugo]] #+CAPTION: creating new post with org-capture-template #+NAME: fig:org-capture-template-ox-hugo @@ -85,6 +85,46 @@ As in [[https://ox-hugo.scripter.co/doc/custom-front-matter/][ox-hugo: Custom Fr :END: #+end_src +some important front matters can be stored in your org capture template, here's my template: + +#+begin_src emacs-lisp + (defun org-hugo-new-subtree-post-capture-template () + "Returns `org-capture' template string for new Hugo post. + See `org-capture-templates' for more information." + (let* (;; http://www.holgerschurig.de/en/emacs-blog-from-org-to-hugo/ + (date (format-time-string (org-time-stamp-format :long :inactive) (org-current-time))) + (title (read-from-minibuffer "Post Title: ")) ;Prompt to enter the post title + (fname (org-hugo-slug title))) + (mapconcat #'identity + `( + ,(concat "\n* TODO " title " :@cat:tag:") + ":PROPERTIES:" + ,(concat ":EXPORT_HUGO_BUNDLE: " fname) + ":EXPORT_FILE_NAME: index" + ,(concat ":EXPORT_DATE: " date) ;Enter current date and time + ":EXPORT_HUGO_CUSTOM_FRONT_MATTER: :image \"/images/icons/tortoise.png\"" + ":EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :libraries '(mathjax)" + ":EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :description \"this is a description\"" + ":END:" + "%?\n") + "\n"))) + (with-eval-after-load 'org-capture + (setq hugo-content-org-dir "~/git-repo/blog/blog-src/content-org") + (add-to-list 'org-capture-templates + `("pe" + "Hugo Post (en)" + entry + (file ,(expand-file-name "all-posts.en.org" hugo-content-org-dir)) + (function org-hugo-new-subtree-post-capture-template))) + (add-to-list 'org-capture-templates + `("pz" + "Hugo Post (zh)" + entry + (file ,(expand-file-name "all-posts.zh.org" hugo-content-org-dir)) + (function org-hugo-new-subtree-post-capture-template))) + (add-to-list 'org-capture-templates '("p" "Hugo Post"))) +#+end_src + ** Code Inline code with '\equal' or '\tilde': ==echo 123==, ~~echo 456~~ @@ -117,6 +157,16 @@ You can add caption and name (for referencing purpose: as in figure [[fig:gopher [[../static/images/icons/gopher001.png]] #+end_src +You can also paste images from clipboard with org-download[fn:org-download]. I've bind =C-M-y= to paste images, and the pasted image will be stored under path =../static/images/posts/=. + +You can customize with the =.dir-locals.el= file: + +#+begin_src emacs-lisp + ((org-mode . ((org-download-timestamp . "") + (org-download-heading-lvl . 0) + (org-download-image-dir . "../static/images/posts")))) +#+end_src + ** Math Support (with MathJax) We need to have MathJax library in our front matter. @@ -163,7 +213,7 @@ It seems that zzo theme does not support math equation referencing and numbering *** Plantuml -use plantuml[fn:plantuml] to draw... +use plantuml[fn:plantuml] to draw, then =C-c C-c= to tangle the image manually (or just org export if you don't need to customize any attributes), then you can add some attributes to the result (width, name, caption, etc.). #+begin_src plantuml :file "../static/images/posts/Writing-Guide-Org/first.svg" title Authentication Sequence @@ -173,6 +223,11 @@ use plantuml[fn:plantuml] to draw... Bob->Alice: Authentication Response #+end_src +#+CAPTION: this is first.svg +#+NAME: first-svg +#+RESULTS: +[[file:../static/images/posts/Writing-Guide-Org/first.svg]] + ** Presentation ** Shortcodes @@ -360,7 +415,13 @@ Some Markdown Contents ** References -You can refer to something in the footnote like ox-hugo[fn:ox-hugo]. +#+begin_src org + You can refer to something in the footnote like ox-hugo[fn:ox-hugo] + ,* Footnotes + [fn:ox-hugo] [[https://ox-hugo.scripter.co/][ox-hugo official site]] +#+end_src + +You can refer to something in the footnote like ox-hugo[fn:ox-hugo] * DONE Org Notes :@notes:org: CLOSED: [2021-12-06 Mon 21:37] @@ -3699,6 +3760,8 @@ Here's a snippet of my i3 configuration. Complete configuration is stored at my * Footnotes +[fn:org-download] [[https://github.com/abo-abo/org-download][org-download]] facilitates moving images from point A to B. + [fn:plantuml] [[https://plantuml.com/][plantuml official site]] [fn:zzo-docs] [[https://zzo-docs.vercel.app/zzo/shortcodes/][zzo-docs on shortcodes]] diff --git a/content/en/posts/writing-guide--org-plus-ox-hugo/index.md b/content/en/posts/writing-guide--org-plus-ox-hugo/index.md index 736ca55..9fe9e95 100644 --- a/content/en/posts/writing-guide--org-plus-ox-hugo/index.md +++ b/content/en/posts/writing-guide--org-plus-ox-hugo/index.md @@ -16,7 +16,7 @@ So instead of editing `.md` files under `content` folder, now I write `.org` fil ## Create new post {#create-new-post} -Invoking org-capture-templates function, and choose hugo post template, as shown in Figure [1](#figure--fig:org-capture-template-ox-hugo) +Invoking org-capture-templates (`SPC o c`) function, and choose hugo post template, as shown in Figure [1](#figure--fig:org-capture-template-ox-hugo) @@ -35,6 +35,46 @@ As in [ox-hugo: Custom Front-matter Parameters](https://ox-hugo.scripter.co/doc/ :END: ``` +some important front matters can be stored in your org capture template, here's my template: + +```emacs-lisp +(defun org-hugo-new-subtree-post-capture-template () + "Returns `org-capture' template string for new Hugo post. + See `org-capture-templates' for more information." + (let* (;; http://www.holgerschurig.de/en/emacs-blog-from-org-to-hugo/ + (date (format-time-string (org-time-stamp-format :long :inactive) (org-current-time))) + (title (read-from-minibuffer "Post Title: ")) ;Prompt to enter the post title + (fname (org-hugo-slug title))) + (mapconcat #'identity + `( + ,(concat "\n* TODO " title " :@cat:tag:") + ":PROPERTIES:" + ,(concat ":EXPORT_HUGO_BUNDLE: " fname) + ":EXPORT_FILE_NAME: index" + ,(concat ":EXPORT_DATE: " date) ;Enter current date and time + ":EXPORT_HUGO_CUSTOM_FRONT_MATTER: :image \"/images/icons/tortoise.png\"" + ":EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :libraries '(mathjax)" + ":EXPORT_HUGO_CUSTOM_FRONT_MATTER+: :description \"this is a description\"" + ":END:" + "%?\n") + "\n"))) +(with-eval-after-load 'org-capture + (setq hugo-content-org-dir "~/git-repo/blog/blog-src/content-org") + (add-to-list 'org-capture-templates + `("pe" + "Hugo Post (en)" + entry + (file ,(expand-file-name "all-posts.en.org" hugo-content-org-dir)) + (function org-hugo-new-subtree-post-capture-template))) + (add-to-list 'org-capture-templates + `("pz" + "Hugo Post (zh)" + entry + (file ,(expand-file-name "all-posts.zh.org" hugo-content-org-dir)) + (function org-hugo-new-subtree-post-capture-template))) + (add-to-list 'org-capture-templates '("p" "Hugo Post"))) +``` + ## Code {#code} @@ -68,6 +108,16 @@ You can add caption and name (for referencing purpose: as in figure [2](#figure- [[../static/images/icons/gopher001.png]] ``` +You can also paste images from clipboard with org-download[^fn:1]. I've bind `C-M-y` to paste images, and the pasted image will be stored under path `../static/images/posts/`. + +You can customize with the `.dir-locals.el` file: + +```emacs-lisp +((org-mode . ((org-download-timestamp . "") + (org-download-heading-lvl . 0) + (org-download-image-dir . "../static/images/posts")))) +``` + ## Math Support (with MathJax) {#math-support--with-mathjax} @@ -117,9 +167,11 @@ It seems that zzo theme does not support math equation referencing and numbering ### Plantuml {#plantuml} -use plantuml[^fn:1] to draw... +use plantuml[^fn:2] to draw, then `C-c C-c` to tangle the image manually (or just org export if you don't need to customize any attributes), then you can add some attributes to the result (width, name, caption, etc.). + + -{{< figure src="/images/posts/Writing-Guide-Org/first.svg" >}} +{{< figure src="/images/posts/Writing-Guide-Org/first.svg" caption="Figure 3: this is first.svg" >}} ## Presentation {#presentation} @@ -127,7 +179,7 @@ use plantuml[^fn:1] to draw... ## Shortcodes {#shortcodes} -> zoo-docs[^fn:2] on short codes +> zoo-docs[^fn:3] on short codes to use shortcodes as you do in markdown, put it after `#+html:`. Like this: @@ -351,8 +403,15 @@ func main() { ## References {#references} -You can refer to something in the footnote like ox-hugo[^fn:3]. +```org +You can refer to something in the footnote like ox-hugo[fn:ox-hugo] +* Footnotes +[fn:ox-hugo] [[https://ox-hugo.scripter.co/][ox-hugo official site]] +``` + +You can refer to something in the footnote like ox-hugo[^fn:4] -[^fn:1]: [plantuml official site](https://plantuml.com/) -[^fn:2]: [zzo-docs on shortcodes](https://zzo-docs.vercel.app/zzo/shortcodes/) -[^fn:3]: [ox-hugo official site](https://ox-hugo.scripter.co/) \ No newline at end of file +[^fn:1]: [org-download](https://github.com/abo-abo/org-download) facilitates moving images from point A to B. +[^fn:2]: [plantuml official site](https://plantuml.com/) +[^fn:3]: [zzo-docs on shortcodes](https://zzo-docs.vercel.app/zzo/shortcodes/) +[^fn:4]: [ox-hugo official site](https://ox-hugo.scripter.co/) \ No newline at end of file