her.esy.fun/src/index.org

182 lines
6.9 KiB
Org Mode
Raw Normal View History

2019-07-07 16:11:45 +00:00
* Code magic :noexport:
2019-07-05 15:09:14 +00:00
#+TITLE: her.esy.fun
#+AUTHOR: Yann Esposito
#+EMAIL: yann.esposito@gmail.com
2019-07-07 16:11:45 +00:00
#+DATE: 2019-07-04
2019-07-05 15:09:14 +00:00
#+KEYWORDS: programming
#+DESCRIPTION:
#+LANGUAGE: en
#+LANG: en
#+OPTIONS: H:6
#+begin_src elisp :results none
2019-07-07 16:11:45 +00:00
(require 'org)
(require 'ox-publish)
(require 'ox-html)
(require 'org-element)
(require 'ox-rss)
(defun org-blog-prepare (project-plist)
"With help from `https://github.com/howardabrams/dot-files'.
2019-07-07 21:39:18 +00:00
Touch `index.org' to rebuilt it.
Argument `PROJECT-PLIST' contains information about the current project."
2019-07-07 16:11:45 +00:00
(let* ((base-directory (plist-get project-plist :base-directory))
(buffer (find-file-noselect (expand-file-name "index.org" base-directory) t)))
(with-current-buffer buffer
(set-buffer-modified-p t)
2019-07-07 21:39:18 +00:00
(save-buffer 0))))
2019-07-07 16:11:45 +00:00
(defvar org-blog-head
2019-07-07 21:39:18 +00:00
(concat
"<link rel=\"stylesheet\" type=\"text/css\" href=\"/assets/css/minimalist.css\"/>"
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">"
"<link rel=\"alternative\" type=\"application/rss+xml\" title=\"Subscribe to articles\" href=\"/archives.xml\" />"
"<link rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/favicon.ico\">"))
2019-07-07 16:11:45 +00:00
(defun org-blog-preamble (_plist)
"Pre-amble for whole blog."
2019-07-07 21:39:18 +00:00
"<strong><code>Her.esy.fun</code></strong>")
2019-07-07 16:11:45 +00:00
(defun menu ()
"Blog menu"
2019-07-07 21:39:18 +00:00
(concat
"<navigation>"
"<a href=\"/\">Home</a>"
"<a href=\"/archive.html\">Posts</a>"
"</navigation>"))
2019-07-07 16:11:45 +00:00
(defun get-from-info (info k)
(let ((i (car (plist-get info k))))
(when (and i (stringp i))
i)))
(defun org-blog-postamble (info)
"Post-amble for whole blog."
(concat "<footer>"
(when-let ((author (get-from-info info :author)))
(if-let ((email (plist-get info :email)))
(format "<p class=\"author\">Author: <a href=\"mailto:%s\">%s</a></p>" email author)
(format "<p class=\"author\">Author: %s</p>" author)))
(when-let ((date (get-from-info info :date)))
(format "<p class=\"date\">Created: %s</p>" date))
2019-07-07 21:39:18 +00:00
(when-let ((keywords (plist-get info :keywords)))
(format "<p class=\"keywords\">Keywords: <code>%s</code></p>" keywords))
(format "<p class=\"date\">Generated: %s</p>"
(format-time-string "%Y-%m-%d %H:%M:%S"))
2019-07-07 16:11:45 +00:00
(format (concat "<p class=\"creator\"> Generated with "
"<a href=\"https://www.gnu.org/software/emacs/\" target=\"_blank\" rel=\"noopener noreferrer\">Emacs %s</a>, "
"<a href=\"http://spacemacs.org\" target=\"_blank\" rel=\"noopener noreferrer\">Spacemacs %s</a>, "
"<a href=\"http://orgmode.org\" target=\"_blank\" rel=\"noopener noreferrer\">Org Mode %s</a>")
emacs-version spacemacs-version org-version)
2019-07-07 21:39:18 +00:00
"</footer>"
"<hr/>"
(menu)))
2019-07-07 16:11:45 +00:00
(defun org-blog-sitemap-format-entry (entry _style project)
"Return string for each ENTRY in PROJECT."
(when (s-starts-with-p "posts/" entry)
2019-07-07 21:39:18 +00:00
(format "@@html:<span class=\"archive-item\"><span class=\"archive-date\">@@ %s: @@html:</span>@@ [[file:%s][%s]] @@html:</span>@@"
(format-time-string "%Y-%m-%d"
2019-07-07 16:11:45 +00:00
(org-publish-find-date entry project))
entry
(org-publish-find-title entry project))))
(defun org-blog-sitemap-function (title list)
"Return sitemap using TITLE and LIST returned by `org-blog-sitemap-format-entry'."
2019-07-07 21:39:18 +00:00
(concat "#+TITLE: " title "\n"
"#+AUTHOR: Yann Esposito\n"
"#+EMAIL: yann.esposito@gmail.com\n"
2019-07-07 16:11:45 +00:00
"\n#+begin_archive\n"
(mapconcat (lambda (li)
(format "@@html:<li>@@ %s @@html:</li>@@" (car li)))
(seq-filter #'car (cdr list))
"\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
:exclude ".*drafts/.*"
:base-extension "org"
:publishing-directory ,publish-dir
:recursive t
:preparation-function org-blog-prepare
:publishing-function org-html-publish-to-html
:with-toc nil
:with-title t
:with-date t
:section-numbers nil
:html-doctype "html5"
:html-html5-fancy t
:html-head-include-default-style nil
:html-head-include-scripts nil
:htmlized-source t
:html-head-extra ,org-blog-head
:html-preamble org-blog-preamble
:html-postamble org-blog-postamble
:auto-sitemap t
:sitemap-filename "archive.org"
:sitemap-title "Blog Posts"
:sitemap-style list
:sitemap-sort-files anti-chronologically
:sitemap-format-entry org-blog-sitemap-format-entry
:sitemap-function org-blog-sitemap-function)
("assets"
:base-directory ,assets-dir
:base-extension ".*"
:publishing-directory ,publish-assets-dir
:publishing-function org-publish-attachment
:recursive t)
("rss"
:base-directory ,rss-dir
:base-extension "org"
:html-link-home ,domainname
:html-link-use-abs-url t
:rss-extension "xml"
:publishing-directory ,publish-rss-dir
:publishing-function (org-rss-publish-to-rss)
:exclude ".*"
:include ("archive.org")
:section-numbers nil
:table-of-contents nil)
("blog" :components ("orgfiles" "assets" "rss"))))
;; add target=_blank and rel="noopener noreferrer" to all links by default
2019-07-06 15:18:13 +00:00
(defun my-org-export-add-target-blank-to-http-links (text backend info)
"Add target=\"_blank\" to external links."
(when (and
(org-export-derived-backend-p backend 'html)
(string-match "href=\"http[^\"]+" text)
(not (string-match "target=\"" text))
(not (string-match (concat "href=\"" domainname "[^\"]*") text)))
(string-match "<a " text)
(replace-match "<a target=\"_blank\" rel=\"noopener noreferrer\" " nil nil text)))
(add-to-list 'org-export-filter-link-functions
'my-org-export-add-target-blank-to-http-links)
2019-07-05 15:09:14 +00:00
#+end_src
* Welcome!
[[https://her.esy.fun][her.esy.fun]]
This is a new take on my personal blog.
With a lot more minimalism in mind.
2019-07-05 21:29:02 +00:00
With [[http://orgmode.org][org-mode]]
2019-07-06 15:18:13 +00:00