From ef2986c5db20e8fbc1f8c6c2efb82120368639b7 Mon Sep 17 00:00:00 2001 From: "Yann Esposito (Yogsototh)" Date: Sun, 21 Jul 2019 22:11:08 +0200 Subject: [PATCH] wip --- src/posts/2019-07-04-static-org-publish.org | 58 ++++++++++++--------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/src/posts/2019-07-04-static-org-publish.org b/src/posts/2019-07-04-static-org-publish.org index cf9717a..caced81 100644 --- a/src/posts/2019-07-04-static-org-publish.org +++ b/src/posts/2019-07-04-static-org-publish.org @@ -4,7 +4,10 @@ #+DATE: 2019-07-04 #+KEYWORDS: programming, blog, org-mode -tl;dr: [[#solution][For the impatient]] +#+begin_quote +/tl;dr/: [[#solution][Full code for the impatient↓]]. Read the full blog post to have all the details. +#+end_quote + This is the first article using my new blog system. @@ -53,13 +56,11 @@ You can add a task quite easily while doing other work in emacs. * How? +** Basic Blog + I have a code block in my =index.org= page that I do not export containing the elisp code I use to load all the information needed by =org-publish=. - -#+begin_src elisp :results none -...#+begin_src elisp :results none -...#+end_src -#+end_src +Do not export an org-mode subtree you can simply tag it with =:noexport:=. =org-publish= suppose that you'll export one html page per org file. You need to provide a minimum set of information: @@ -67,12 +68,17 @@ You need to provide a minimum set of information: - base directory that should contain your org files - publish directory, where you will export the html from the org files -#+begin_src elisp :results none +A very basic publish rule would be: + +#+begin_src org +,* Magic Script :noexport: +,#+begin_src elisp :results none (setq org-publish-project-alist '(("orgfiles" :base-directory "/users/me/blog/src" :publishing-directory "/users/me/blog/_site" :recursive t))) +,#+end_src #+end_src So now, if you put org files in the base directory it will copy @@ -94,6 +100,7 @@ Notice, org-publish does what you expect and do not re-export all files each time but only the one that have changed. #+end_quote +** Relative Paths A first issue with this is that I don't want to put that in my emacs preferences. @@ -118,18 +125,15 @@ Now anyone can clone the repository. Open my =index.org= file, and execute the code in it by =C-e C-e= and then will be able to publish the website locally in the =_site= directory. -Until there this is nice +** Assets -But generally you want a bit more features than that for a blog. +Generally you want a bit more features than that for publishing a blog. Typically you would like to have a common template, an header, some CSS. For that you need to work a bit more. First, important thing, add an org publish section to publish your assets (CSS, images, etc...) - -asdf - #+begin_src elisp (setq base-dir (concat (projectile-project-root) "src")) (setq publish-dir (concat (projectile-project-root) "_site")) @@ -158,7 +162,20 @@ asdf :CUSTOM_ID: solution :END: -#+begin_src elisp :results none +#+begin_src org +,* Exec the script with ~C-c C-c~ :noexport: +,#+begin_src elisp :results none + ;; Global variables + (setq domainname "https://her.esy.fun") + (setq base-dir (concat (projectile-project-root) "src")) + (setq publish-dir (concat (projectile-project-root) "_site")) + (setq assets-dir (concat base-dir "/assets")) + (setq publish-assets-dir (concat publish-dir "/assets")) + (setq rss-dir base-dir) + (setq publish-rss-dir publish-dir) + (setq css-name "minimalist.css") + + (require 'org) (require 'ox-publish) (require 'ox-html) @@ -177,7 +194,7 @@ asdf (defvar org-blog-head (concat - "" + "" "" "" "")) @@ -194,7 +211,6 @@ asdf " | ") "")) - (defun str-time-to-year-float (date-str) (/ (float-time (apply 'encode-time @@ -204,7 +220,7 @@ asdf (defvar blog-creation-date "2019-07-01") - (defun y-date (date-str) + (defun delta-date (date-str) "Number of year since the begining of this blog" (let ((y (- (str-time-to-year-float date-str) (str-time-to-year-float blog-creation-date)))) @@ -250,7 +266,7 @@ asdf (obfuscate-html author)) (format "
Author: %s
" author))) (when-let ((date (get-from-info info :date))) - (format "
Created: %s (%s)
" date (y-date date))) + (format "
Created: %s (%s)
" date (delta-date date))) (when-let ((keywords (plist-get info :keywords))) (format "
Keywords: %s
" keywords)) (format "
Generated: %s
" @@ -286,13 +302,6 @@ asdf "\n") "\n#+end_archive\n")) - (setq base-dir (concat (projectile-project-root) "src")) - (setq publish-dir (concat (projectile-project-root) "_site")) - (setq assets-dir (concat base-dir "/assets")) - (setq publish-assets-dir (concat publish-dir "/assets")) - (setq rss-dir base-dir) - (setq publish-rss-dir publish-dir) - (setq domainname "https://her.esy.fun") (setq org-publish-project-alist `(("orgfiles" :base-directory ,base-dir @@ -361,5 +370,6 @@ asdf (add-to-list 'org-export-filter-link-functions 'my-org-export-add-target-blank-to-http-links) +,#+end_src #+end_src