mostly working now
This commit is contained in:
parent
a3775b87db
commit
f2b5d8dbd1
4 changed files with 163 additions and 219 deletions
|
@ -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
|
||||||
|
|
|
@ -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; }
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
#+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)
|
||||||
|
@ -28,18 +28,44 @@
|
||||||
|
|
||||||
(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\"/>
|
||||||
|
<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\">")
|
<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 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>"
|
||||||
|
(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>"))
|
||||||
|
|
||||||
(defun org-blog-sitemap-format-entry (entry _style project)
|
(defun org-blog-sitemap-format-entry (entry _style project)
|
||||||
"Return string for each ENTRY in PROJECT."
|
"Return string for each ENTRY in PROJECT."
|
||||||
(when (s-starts-with-p "posts/" entry)
|
(when (s-starts-with-p "posts/" entry)
|
||||||
|
@ -146,5 +172,3 @@ With a lot more minimalism in mind.
|
||||||
|
|
||||||
With [[http://orgmode.org][org-mode]]
|
With [[http://orgmode.org][org-mode]]
|
||||||
|
|
||||||
|
|
||||||
TEST
|
|
||||||
|
|
|
@ -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
|
|
||||||
|
|
Loading…
Reference in a new issue