mostly working now

This commit is contained in:
Yann Esposito (Yogsototh) 2019-07-07 18:11:45 +02:00
parent a3775b87db
commit f2b5d8dbd1
Signed by untrusted user who does not match committer: yogsototh
GPG key ID: 7B19A4C650D59646
4 changed files with 163 additions and 219 deletions

View file

@ -2,5 +2,5 @@
#+begin_archive #+begin_archive
@@html:<li>@@ @@html:<span class="archive-item"><span class="archive-date">@@ jul 06, 2019 @@html:</span>@@ [[file:posts/2019-07-04-org-publish.org][Static blog with org-mode]] @@html:</span>@@ @@html:</li>@@ @@html:<li>@@ @@html:<span class="archive-item"><span class="archive-date">@@ Jul 05, 2019 @@html:</span>@@ [[file:posts/2019-07-04-org-publish.org][org-publish]] @@html:</span>@@ @@html:</li>@@
#+end_archive #+end_archive

View file

@ -42,12 +42,13 @@ hr {
line-height: 0; line-height: 0;
overflow: hidden; overflow: hidden;
border: 0; border: 0;
margin-bottom: 20px; margin: 20px 0;
} }
hr:after { hr:after {
content: "----------------------------------------------------------------------------------------------------"; content: "----------------------------------------------------------------------------------------------------";
font-family: monospace; font-family: monospace;
position: absolute; position: absolute;
opacity: 0.3;
top: 0; top: 0;
left: 0; left: 0;
font-size: 14px; font-size: 14px;
@ -120,3 +121,5 @@ h6 { color: #859900;}
img { max-width: 100%; img { max-width: 100%;
max-height: 800px; max-height: 800px;
margin: 20px auto; } margin: 20px auto; }
footer { font-size: 0.8em; opacity: 0.5; }
footer:hover { opacity: 1; }

View file

@ -1,127 +1,153 @@
* Code magic :noexport: * Code magic :noexport:
#+TITLE: her.esy.fun #+TITLE: her.esy.fun
#+AUTHOR: Yann Esposito #+AUTHOR: Yann Esposito
#+EMAIL: yann.esposito@gmail.com #+EMAIL: yann.esposito@gmail.com
#+DATE: 2019-07-04
#+KEYWORDS: programming #+KEYWORDS: programming
#+DESCRIPTION: #+DESCRIPTION:
#+LANGUAGE: en #+LANGUAGE: en
#+LANG: en #+LANG: en
#+CREATOR: Spacemacs, org-mode (Emacs 26.1, Org mode 9.2.3)
#+OPTIONS: H:6 #+OPTIONS: H:6
#+begin_src elisp :results none #+begin_src elisp :results none
(require 'org) (require 'org)
(require 'ox-publish) (require 'ox-publish)
(require 'ox-html) (require 'ox-html)
(require 'org-element) (require 'org-element)
(require 'ox-rss) (require 'ox-rss)
(defun org-blog-prepare (project-plist) (defun org-blog-prepare (project-plist)
"With help from `https://github.com/howardabrams/dot-files'. "With help from `https://github.com/howardabrams/dot-files'.
Touch `index.org' to rebuilt it. Touch `index.org' to rebuilt it.
Argument `PROJECT-PLIST' contains information about the current project." Argument `PROJECT-PLIST' contains information about the current project."
(let* ((base-directory (plist-get project-plist :base-directory)) (let* ((base-directory (plist-get project-plist :base-directory))
(buffer (find-file-noselect (expand-file-name "index.org" base-directory) t))) (buffer (find-file-noselect (expand-file-name "index.org" base-directory) t)))
(with-current-buffer buffer (with-current-buffer buffer
(set-buffer-modified-p t) (set-buffer-modified-p t)
(save-buffer 0)) (save-buffer 0))
(kill-buffer buffer))) (kill-buffer buffer)))
(defvar org-blog-head (defvar org-blog-head
"<link rel=\"stylesheet\" type=\"text/css\" href=\"/assets/css/minimalist.css\"/> "<link rel=\"stylesheet\" type=\"text/css\" href=\"/assets/css/minimalist.css\"/>
<link rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/favicon.ico\">") <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\">")
(defun org-blog-preamble (_plist) (defun org-blog-preamble (_plist)
"Pre-amble for whole blog." "Pre-amble for whole blog."
"<strong><code>Programing Heresy</code></strong>") "<strong><code>Programing Heresy</code></strong>")
(defun org-blog-postamble (_plist) (defun menu ()
"Post-amble for whole blog." "Blog menu"
"<hr/> "<a href=\"/\">Home</a> -
<a href=\"/\">Home</a> - <a href=\"/archive.html\">Posts</a>")
<a href=\"/archive.html\">Posts</a>")
(defun org-blog-sitemap-format-entry (entry _style project) (defun get-from-info (info k)
"Return string for each ENTRY in PROJECT." (let ((i (car (plist-get info k))))
(when (s-starts-with-p "posts/" entry) (when (and i (stringp i))
(format "@@html:<span class=\"archive-item\"><span class=\"archive-date\">@@ %s @@html:</span>@@ [[file:%s][%s]] @@html:</span>@@" i)))
(format-time-string "%h %d, %Y"
(org-publish-find-date entry project))
entry
(org-publish-find-title entry project))))
(defun org-blog-sitemap-function (title list) (defun org-blog-postamble (info)
"Return sitemap using TITLE and LIST returned by `org-blog-sitemap-format-entry'." "Post-amble for whole blog."
(concat "#+TITLE: " title "\n\n" (concat "<footer>"
"\n#+begin_archive\n" (menu)
(mapconcat (lambda (li) "<hr/>"
(format "@@html:<li>@@ %s @@html:</li>@@" (car li))) (when-let ((author (get-from-info info :author)))
(seq-filter #'car (cdr list)) (if-let ((email (plist-get info :email)))
"\n") (format "<p class=\"author\">Author: <a href=\"mailto:%s\">%s</a></p>" email author)
"\n#+end_archive\n")) (format "<p class=\"author\">Author: %s</p>" author)))
(format "<p class=\"date\">Modified: %s</p>"
(format-time-string "%Y-%m-%d %H:%M:%S"))
(when-let ((date (get-from-info info :date)))
(format "<p class=\"date\">Created: %s</p>" date))
(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)
"</footer>"))
(setq base-dir (concat (projectile-project-root) "src")) (defun org-blog-sitemap-format-entry (entry _style project)
(setq publish-dir (concat (projectile-project-root) "_site")) "Return string for each ENTRY in PROJECT."
(setq assets-dir (concat base-dir "/assets")) (when (s-starts-with-p "posts/" entry)
(setq publish-assets-dir (concat publish-dir "/assets")) (format "@@html:<span class=\"archive-item\"><span class=\"archive-date\">@@ %s @@html:</span>@@ [[file:%s][%s]] @@html:</span>@@"
(setq rss-dir base-dir) (format-time-string "%h %d, %Y"
(setq publish-rss-dir publish-dir) (org-publish-find-date entry project))
(setq domainname "https://her.esy.fun") entry
(setq org-publish-project-alist (org-publish-find-title entry project))))
`(("orgfiles"
:base-directory ,base-dir
:exclude ".*drafts/.*"
:base-extension "org"
:publishing-directory ,publish-dir (defun org-blog-sitemap-function (title list)
"Return sitemap using TITLE and LIST returned by `org-blog-sitemap-format-entry'."
(concat "#+TITLE: " title "\n\n"
"\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"))
:recursive t (setq base-dir (concat (projectile-project-root) "src"))
:preparation-function org-blog-prepare (setq publish-dir (concat (projectile-project-root) "_site"))
:publishing-function org-html-publish-to-html (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"
:with-toc nil :publishing-directory ,publish-dir
: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 :recursive t
:sitemap-filename "archive.org" :preparation-function org-blog-prepare
:sitemap-title "Blog Posts" :publishing-function org-html-publish-to-html
:sitemap-style list
:sitemap-sort-files anti-chronologically
:sitemap-format-entry org-blog-sitemap-format-entry
:sitemap-function org-blog-sitemap-function)
("assets" :with-toc nil
:base-directory ,assets-dir :with-title t
:base-extension ".*" :with-date t
:publishing-directory ,publish-assets-dir :section-numbers nil
:publishing-function org-publish-attachment :html-doctype "html5"
:recursive t) :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
("rss" :auto-sitemap t
:base-directory ,rss-dir :sitemap-filename "archive.org"
:base-extension "org" :sitemap-title "Blog Posts"
:html-link-home ,domainname :sitemap-style list
:html-link-use-abs-url t :sitemap-sort-files anti-chronologically
:rss-extension "xml" :sitemap-format-entry org-blog-sitemap-format-entry
:publishing-directory ,publish-rss-dir :sitemap-function org-blog-sitemap-function)
:publishing-function (org-rss-publish-to-rss)
:exclude ".*"
:include ("archive.org")
:section-numbers nil
:table-of-contents nil)
("blog" :components ("orgfiles" "assets" "rss")))) ("assets"
:base-directory ,assets-dir
:base-extension ".*"
:publishing-directory ,publish-assets-dir
:publishing-function org-publish-attachment
:recursive t)
;; add target=_blank and rel="noopener noreferrer" to all links by default ("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
(defun my-org-export-add-target-blank-to-http-links (text backend info) (defun my-org-export-add-target-blank-to-http-links (text backend info)
"Add target=\"_blank\" to external links." "Add target=\"_blank\" to external links."
(when (and (when (and
@ -146,5 +172,3 @@ With a lot more minimalism in mind.
With [[http://orgmode.org][org-mode]] With [[http://orgmode.org][org-mode]]
TEST

View file

@ -1,129 +1,46 @@
#+TITLE: Static blog with org-mode #+TITLE: Static blog with org-mode
#+AUTHOR: Yann Esposito #+AUTHOR: Yann Esposito
#+EMAIL: yann.esposito@gmail.com #+EMAIL: yann.esposito@gmail.com
#+KEYWORDS: programming, blog #+KEYWORDS: programming, blog, org-mode
[[https://her.esy.fun][her.esy.fun]] This is the first article using my new blog system.
This is a new take on my personal blog. Each time I try different things.
With a lot more minimalism in mind.
Fully done with [[https://orgmode.org][=org-mode=]]. A long time ago, I used PHP for my first website.
I used include and took care of XHTML pages validation.
Then I used [[http://nanoc.ws][nanoc]], a ruby static website.
Then I switched to [[https://jaspervdj.be/hakyll/][hakyll]] because I wanted to switch to a Haskell's written tool.
Now I'll try to use emacs [[http://orgmode.org][org-mode]].
* Code magic So the article is a classical, Why?, How?
Here is how I publish this website in emacs using org-mode. * Why?
I just eval that code and then do a simple `org-publish` for the blog.
And that's it. Everything started when I was hired in a place where I was given a terrible
keyboard.
After a few weeks I started to feel a lot of pain in both my wrists.
So I started to go from classical IDE to being able to use vim
correctly[fn:vim].
#+begin_src elisp :results none Then I started to work in Clojure and I heard that emacs might certainly be a
(require 'org) better fit for LISP dialiects.
(require 'ox-publish) But, I couldn't switch to an editor without vim keybindings support because they
(require 'ox-html) are so great once you're used to them.
(require 'org-element) But miracle it was about the time [[http://spacemacs.org][spacemacs]] appeared and I switched.
(require 'ox-rss) It was really impressive how well the vim keybindings worked so well.
Even most of the advanced vim features I used to use worked like a charm.
(defun org-blog-prepare (project-plist) The first benefit of emacs is you can configure emacs with elisp.
"With help from `https://github.com/howardabrams/dot-files'. Which unlike vimscript looks like a correct language to work with.
Touch `index.org' to rebuilt it.
Argument `PROJECT-PLIST' contains information about the current project."
(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)
(save-buffer 0))
(kill-buffer buffer)))
(defvar org-blog-head One unexpected benefit of emacs was [[http://orgmode.org][org-mode]].
"<link rel=\"stylesheet\" type=\"text/css\" href=\"/assets/css/minimalist.css\"/> I always heard good things about it but it took me a while to really get it and
<link rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/favicon.ico\">") to understand why it is so great.
(defun org-blog-preamble (_plist) If you don't know anything about org-mode, it is many things.
"Pre-amble for whole blog." First imagine a Markdown but more TODO list oriented.
"<strong><code>Programming Heresy</code></strong>") But along with this, emacs has a lot of helper functions to work with those
org-mode files.
(defun org-blog-postamble (_plist) [fn:vim] I wrote this article to help people use vim: [[http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/][learn vim progressively]]
"Post-amble for whole blog."
"<hr/>
<a href=\"/\">Home</a> -
<a href=\"/archive.html\">Posts</a>")
(defun org-blog-sitemap-format-entry (entry _style project)
"Return string for each ENTRY in PROJECT."
(when (s-starts-with-p "posts/" entry)
(format (concat "@@html:<span class=\"archive-item\">"
"<span class=\"archive-date\">"
"@@ %s @@html:</span>@@ [[file:%s][%s]] @@html:</span>@@")
(format-time-string "%Y-%m-%d"
(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'."
(concat "#+TITLE: " title "\n\n"
"\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 rootdir (projectile-project-root))
(setq org-publish-project-alist
`(("orgfiles"
:base-directory (concat rootdir "/src/")
:exclude ".*drafts/.*"
:base-extension "org"
:publishing-directory (concat rootdir "/_site/")
: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 (concat rootdir "/src/assets/")
:base-extension ".*"
:publishing-directory (concat rootdir "/_site/assets/")
:publishing-function org-publish-attachment
:recursive t)
("rss"
:base-directory (concat rootdir "/src/")
:base-extension "org"
:html-link-home "https://her.esy.fun/"
:html-link-use-abs-url t
:rss-extension "xml"
:publishing-directory (concat rootdir "/")
:publishing-function (org-rss-publish-to-rss)
:exclude ".*"
:include ("archive.org")
:section-numbers nil
:table-of-contents nil)
("blog" :components ("orgfiles" "assets" "rss"))))
#+end_src