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
@@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

View file

@ -42,12 +42,13 @@ hr {
line-height: 0;
overflow: hidden;
border: 0;
margin-bottom: 20px;
margin: 20px 0;
}
hr:after {
content: "----------------------------------------------------------------------------------------------------";
font-family: monospace;
position: absolute;
opacity: 0.3;
top: 0;
left: 0;
font-size: 14px;
@ -120,3 +121,5 @@ h6 { color: #859900;}
img { max-width: 100%;
max-height: 800px;
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
#+AUTHOR: Yann Esposito
#+EMAIL: yann.esposito@gmail.com
#+DATE: 2019-07-04
#+KEYWORDS: programming
#+DESCRIPTION:
#+LANGUAGE: en
#+LANG: en
#+CREATOR: Spacemacs, org-mode (Emacs 26.1, Org mode 9.2.3)
#+OPTIONS: H:6
#+begin_src elisp :results none
(require 'org)
(require 'ox-publish)
(require 'ox-html)
(require 'org-element)
(require 'ox-rss)
(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'.
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)))
(defun org-blog-prepare (project-plist)
"With help from `https://github.com/howardabrams/dot-files'.
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
"<link rel=\"stylesheet\" type=\"text/css\" href=\"/assets/css/minimalist.css\"/>
<link rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/favicon.ico\">")
(defvar org-blog-head
"<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\">")
(defun org-blog-preamble (_plist)
"Pre-amble for whole blog."
"<strong><code>Programing Heresy</code></strong>")
(defun org-blog-preamble (_plist)
"Pre-amble for whole blog."
"<strong><code>Programing Heresy</code></strong>")
(defun org-blog-postamble (_plist)
"Post-amble for whole blog."
"<hr/>
<a href=\"/\">Home</a> -
<a href=\"/archive.html\">Posts</a>")
(defun menu ()
"Blog menu"
"<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 "@@html:<span class=\"archive-item\"><span class=\"archive-date\">@@ %s @@html:</span>@@ [[file:%s][%s]] @@html:</span>@@"
(format-time-string "%h %d, %Y"
(org-publish-find-date entry project))
entry
(org-publish-find-title entry project))))
(defun get-from-info (info k)
(let ((i (car (plist-get info k))))
(when (and i (stringp i))
i)))
(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"))
(defun org-blog-postamble (info)
"Post-amble for whole blog."
(concat "<footer>"
(menu)
"<hr/>"
(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)))
(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"))
(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"
(defun org-blog-sitemap-format-entry (entry _style project)
"Return string for each ENTRY in PROJECT."
(when (s-starts-with-p "posts/" entry)
(format "@@html:<span class=\"archive-item\"><span class=\"archive-date\">@@ %s @@html:</span>@@ [[file:%s][%s]] @@html:</span>@@"
(format-time-string "%h %d, %Y"
(org-publish-find-date entry project))
entry
(org-publish-find-title entry project))))
: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
:preparation-function org-blog-prepare
:publishing-function org-html-publish-to-html
(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"
: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
:publishing-directory ,publish-dir
: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)
:recursive t
:preparation-function org-blog-prepare
:publishing-function org-html-publish-to-html
("assets"
:base-directory ,assets-dir
:base-extension ".*"
:publishing-directory ,publish-assets-dir
:publishing-function org-publish-attachment
:recursive t)
: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
("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)
: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)
("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)
"Add target=\"_blank\" to external links."
(when (and
@ -146,5 +172,3 @@ With a lot more minimalism in mind.
With [[http://orgmode.org][org-mode]]
TEST

View file

@ -1,129 +1,46 @@
#+TITLE: Static blog with org-mode
#+AUTHOR: Yann Esposito
#+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.
With a lot more minimalism in mind.
Each time I try different things.
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.
I just eval that code and then do a simple `org-publish` for the blog.
* Why?
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
(require 'org)
(require 'ox-publish)
(require 'ox-html)
(require 'org-element)
(require 'ox-rss)
Then I started to work in Clojure and I heard that emacs might certainly be a
better fit for LISP dialiects.
But, I couldn't switch to an editor without vim keybindings support because they
are so great once you're used to them.
But miracle it was about the time [[http://spacemacs.org][spacemacs]] appeared and I switched.
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)
"With help from `https://github.com/howardabrams/dot-files'.
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)))
The first benefit of emacs is you can configure emacs with elisp.
Which unlike vimscript looks like a correct language to work with.
(defvar org-blog-head
"<link rel=\"stylesheet\" type=\"text/css\" href=\"/assets/css/minimalist.css\"/>
<link rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/favicon.ico\">")
One unexpected benefit of emacs was [[http://orgmode.org][org-mode]].
I always heard good things about it but it took me a while to really get it and
to understand why it is so great.
(defun org-blog-preamble (_plist)
"Pre-amble for whole blog."
"<strong><code>Programming Heresy</code></strong>")
If you don't know anything about org-mode, it is many things.
First imagine a Markdown but more TODO list oriented.
But along with this, emacs has a lot of helper functions to work with those
org-mode files.
(defun org-blog-postamble (_plist)
"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
[fn:vim] I wrote this article to help people use vim: [[http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/][learn vim progressively]]