帶雕像房子的對面
泉声咽危石,日色冷青松
闲来造轮子

最近发现gitlab的ci是个好东西,写起来简单,配上docker简直是想怎么来就怎么来。

我在gitlab有一个repo是存放一些非重要的org文档的。

昨天夜晚突然想,和不用ci调用emacs把这些org文档输出成一个简单的静态网站呢。

于是就有了这样几行代码。

image: silex/emacs:master-alpine

.build: &build
  script:
    - emacs --batch --no-init-file --load publish.el --funcall org-publish-all
    artifacts:
      paths:
	- public

	pages:
	  <<: *build
	  only:
	    - master

	    test:
	      <<: *build
	      except:
		- master

非常的简单,调用docker里独立的emacs,不适用init文件启动这个emacs,然后将org发布的一些信息和配置写在这个publish.el里面,通过emacs,将repo里面的org文档转换成网页。

至于这个publish.el嘛,我也是东拼西凑。css也是直接用的别人的,等有时间了,好好的弄一个自己的css吧。

(require 'package)
(package-initialize)
(add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-refresh-contents)
(package-install 'org-plus-contrib)
(package-install 'htmlize)

(require 'org)
(require 'ox-publish)

;; setting to nil, avoids "Author: x" at the bottom
(setq user-full-name nil)

(setq org-export-with-section-numbers nil
      org-export-with-smart-quotes t
      org-export-with-toc nil)

(setq org-html-divs '((preamble "header" "top")
		      (content "main" "content")
		      (postamble "footer" "postamble"))
      org-html-container-element "section"
      org-html-metadata-timestamp-format "%Y-%m-%d"
      org-html-checkbox-type 'html
      org-html-html5-fancy t
      org-html-validation-link nil
      org-html-doctype "html5")

(setq org-html-htmlize-output-type 'css)


(defun my/org-publish-org-sitemap-format (entry style project)
  (cond ((not (directory-name-p entry))
	 (format "[[file:%s][(%s) %s]]"
		 entry
		 (format-time-string "%Y-%m-%d"
				     (org-publish-find-date entry project))
		 (org-publish-find-title entry project)))
	((eq style 'tree)
	 ;; Return only last subdir.
	 (file-name-nondirectory (directory-file-name entry)))
	(t entry)))

(defvar site-attachments
  (regexp-opt '("jpg" "jpeg" "gif" "png" "svg"
		"ico" "cur" "css" "js" "woff" "html" "pdf"))
  "File types that are published as static files.")

(setq org-publish-project-alist
      (list
       (list "org-site"
	     :base-directory "."
	     :base-extension "org"
	     :recursive t
	     :with-date t
	     :with-title t
	     :publishing-function '(org-html-publish-to-html)
	     :publishing-directory "./public"
	     :exclude (regexp-opt '("README" "draft"))
	     :html-preamble "<div class=\"nav\">
  <input type=\"checkbox\" id=\"show-menu\" role=\"button\">
  <label for=\"show-menu\" class=\"show-menu f-right\">Menu</label>
  <div id=\"menu\">
    <ul class=\"f-left\"><li>
	<a href=\"/index.html\" class=\"home\">Home</a></li><li>
    </li></ul>
    <ul class=\"f-right\"><li>
	<a href=\"/about.html\" class=\"blog\">About</a></li><li>
    </li></ul>
  </div>
</div>"
	     :auto-sitemap t
	     :sitemap-title "闫的杂项文本"
	     :sitemap-filename "index.org"
	     :sitemap-file-entry-format 'my/org-publish-org-sitemap-format
	     :html-head-extra "<link rel=\"icon\" type=\"image/x-icon\" href=\"/favicon.ico\"/>
<link rel=\"stylesheet\" type=\"text/css\" href=\"https://www.sadiqpk.org/css/site.css\"/>"
	     :sitemap-style 'list
	     :sitemap-sort-files 'anti-chronologically)
       (list "site-static"
	     :base-directory "."
	     :exclude "public/"
	     :base-extension site-attachments
	     :publishing-directory "./public"
	     :publishing-function 'org-publish-attachment
	     :recursive t)
       (list "site" :components '("org-site" "site-static"))))
(provide 'publish)
;;; publish.el ends here

于是就有了这么一切。

Figure 1: Screenshot of the Site

Figure 1: Screenshot of the Site

看起来还不错吧。


最后修改于 2020-08-28