Finish up the tag and category files
This commit is contained in:
父節點
dc4b171c16
當前提交
1fb1d6e4bb
|
@ -5,4 +5,6 @@ _tmp/
|
|||
*~
|
||||
.cask/
|
||||
*.elc
|
||||
build/
|
||||
build/
|
||||
orgs/categories/
|
||||
orgs/tags/
|
||||
|
|
101
build.el
101
build.el
|
@ -51,24 +51,27 @@
|
|||
(seq-reduce
|
||||
;; all-tags is in (tags . tags->files) form
|
||||
(lambda (all-tags file)
|
||||
(with-temp-buffer
|
||||
(insert-file-contents file)
|
||||
(let ((tags (mapcar #'car (org-get-buffer-tags))))
|
||||
(seq-reduce
|
||||
(lambda (result tag)
|
||||
(let ((tag-list (car result))
|
||||
(tag->file (cdr result)))
|
||||
(cons
|
||||
;; Tag list
|
||||
(if (member tag tag-list) tag-list (sort (cons tag tag-list) 'string<))
|
||||
;; tag->file
|
||||
(cons (cons tag
|
||||
;; Current value of the the given tag (all the files
|
||||
;; that contain that tag)
|
||||
(append (list file) (cdr (assoc tag tag->file))))
|
||||
tag->file))))
|
||||
tags
|
||||
all-tags))))
|
||||
(if (get-file-global-props file "PAGE")
|
||||
;; Ignore pages
|
||||
all-tags
|
||||
(with-temp-buffer
|
||||
(insert-file-contents file)
|
||||
(let ((tags (mapcar #'car (org-get-buffer-tags))))
|
||||
(seq-reduce
|
||||
(lambda (result tag)
|
||||
(let ((tag-list (car result))
|
||||
(tag->file (cdr result)))
|
||||
(cons
|
||||
;; Tag list
|
||||
(if (member tag tag-list) tag-list (sort (cons tag tag-list) 'string<))
|
||||
;; tag->file
|
||||
(cons (cons tag
|
||||
;; Current value of the the given tag (all the files
|
||||
;; that contain that tag)
|
||||
(append (list file) (cdr (assoc tag tag->file))))
|
||||
tag->file))))
|
||||
tags
|
||||
all-tags)))))
|
||||
(all-org-files)
|
||||
'()))
|
||||
|
||||
|
@ -149,7 +152,7 @@ Not pages."
|
|||
(mapconcat
|
||||
(lambda (cat)
|
||||
(let ((count (length (cdr (assoc cat (cdr categories))))))
|
||||
(format " - [[//categories/%s.html][%s(%s)]]" cat cat count)))
|
||||
(format " - [[./%s.html][%s(%s)]]" cat cat count)))
|
||||
(car categories)
|
||||
"\n")))
|
||||
|
||||
|
@ -160,7 +163,7 @@ Not pages."
|
|||
(mapconcat
|
||||
(lambda (tag)
|
||||
(let ((count (length (cdr (assoc tag (cdr tags))))))
|
||||
(format " - [[//tags/%s.html][%s(%s)]]" tag tag count)))
|
||||
(format " - [[./%s.html][%s(%s)]]" tag tag count)))
|
||||
(car tags)
|
||||
"\n")))
|
||||
|
||||
|
@ -179,6 +182,61 @@ Not pages."
|
|||
(latest-org-list))
|
||||
|
||||
|
||||
(defun pair-file-with-date (file)
|
||||
"Return a pair for the given FILE with date as car and file as cdr."
|
||||
(cons
|
||||
(->epoch (get-file-global-props file "DATE"))
|
||||
file))
|
||||
|
||||
|
||||
(defun create-tag-pages (project-dir)
|
||||
"Create all the tag files in the PROJECT-DIR."
|
||||
(let ((tags (get-all-tags)))
|
||||
(mapcar
|
||||
(lambda (tag)
|
||||
(let ((out (format "%s/orgs/tags/%s.org" project-dir tag))
|
||||
(files (cdr (assoc tag (cdr tags)))))
|
||||
(copy-template
|
||||
(format "%s/templates/links_template.org" project-dir)
|
||||
out
|
||||
(mapconcat
|
||||
(lambda (file-pair)
|
||||
(format "- [[file:..%s][%s]]"
|
||||
(replace-regexp-in-string (regexp-quote (from-root "/orgs")) "" (cdr file-pair) nil 'literal)
|
||||
(get-file-global-props (cdr file-pair) "TITLE")))
|
||||
|
||||
(sort
|
||||
(mapcar #'pair-file-with-date files)
|
||||
(lambda (x y) (< (car x) (car y))))
|
||||
"\n")
|
||||
tag)))
|
||||
(car tags))))
|
||||
|
||||
|
||||
(defun create-category-pages (project-dir)
|
||||
"Create all the category files in the PROJECT-DIR."
|
||||
(let ((tags (get-all-categories)))
|
||||
(mapcar
|
||||
(lambda (tag)
|
||||
(let ((out (format "%s/orgs/categories/%s.org" project-dir tag))
|
||||
(files (cdr (assoc tag (cdr tags)))))
|
||||
(copy-template
|
||||
(format "%s/templates/links_template.org" project-dir)
|
||||
out
|
||||
(mapconcat
|
||||
(lambda (file-pair)
|
||||
(format "- [[file:..%s][%s]]"
|
||||
(replace-regexp-in-string (regexp-quote (from-root "/orgs")) "" (cdr file-pair) nil 'literal)
|
||||
(get-file-global-props (cdr file-pair) "TITLE")))
|
||||
|
||||
(sort
|
||||
(mapcar #'pair-file-with-date files)
|
||||
(lambda (x y) (< (car x) (car y))))
|
||||
"\n")
|
||||
tag)))
|
||||
(car tags))))
|
||||
|
||||
|
||||
(defun main ()
|
||||
"The entry point to the build script."
|
||||
|
||||
|
@ -217,6 +275,9 @@ Not pages."
|
|||
(from-root "/orgs/tags/index.org")
|
||||
(tags-org-list))
|
||||
|
||||
(create-tag-pages project-root)
|
||||
(create-category-pages project-root)
|
||||
|
||||
(setq org-html-preamble #'preamble-fn)
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
;;; utils.el --- The utility collections
|
||||
;;; Version: 0.1.0
|
||||
;;; Package-Version 0.1.0
|
||||
;;; Commentary:
|
||||
;;; Code:
|
||||
|
||||
(defmacro comment (&rest body)
|
||||
"Ignore the given BODY."
|
||||
nil)
|
||||
|
||||
|
||||
(defun prod-p ()
|
||||
"Return non-nil if we're in development mode."
|
||||
(when (getenv "LXHOME_PROD")
|
||||
t))
|
||||
|
||||
|
||||
(defun get-buffer-global-props (prop)
|
||||
"Get a plists of global org properties PROP of current buffer."
|
||||
(car
|
||||
(org-element-map
|
||||
(org-element-parse-buffer)
|
||||
'keyword
|
||||
(lambda (el)
|
||||
(when (string-match prop (org-element-property :key el))
|
||||
(org-element-property :value el))))))
|
||||
|
||||
|
||||
(defun get-file-global-props (file prop)
|
||||
"Return the value of the given global PROP in the given org FILE."
|
||||
(with-temp-buffer
|
||||
(insert-file-contents file)
|
||||
(message (get-buffer-global-props prop))))
|
||||
|
||||
|
||||
(comment
|
||||
(setq org-directory "~/src/lxhome/orgs/")
|
||||
(let ((f "./orgs/index.org"))
|
||||
(get-file-global-props f "CATEGORY")))
|
||||
|
||||
|
||||
(defun ->epoch (date-str)
|
||||
"Convert the given DATE-STR to epoch seconds."
|
||||
;; Just because it's easier to deal with date in bash rather than elisp
|
||||
(string-to-number
|
||||
(shell-command-to-string (concat (format "date -d %s" date-str) " +%s"))))
|
||||
|
||||
|
||||
(defun replace-in-buffer (str replacement)
|
||||
"Replace the given STR with its REPLACEMENT in current buffer."
|
||||
(with-current-buffer (current-buffer)
|
||||
(goto-char (point-min))
|
||||
(while (search-forward str nil t)
|
||||
(replace-match replacement))))
|
||||
|
||||
|
||||
(defun copy-template (src dest content &optional title)
|
||||
"Replace the placeholder in SRC with CONTENT and write it to DEST."
|
||||
(with-temp-file dest
|
||||
(insert-file-contents src)
|
||||
(when title
|
||||
(replace-in-buffer "<<<title>>>" title))
|
||||
(replace-in-buffer "<<<links>>>" content)))
|
||||
|
||||
|
||||
(defun get-file-tags (file)
|
||||
"Returna list of tags for the given FILE."
|
||||
(with-temp-buffer
|
||||
(insert-file-contents file)
|
||||
(mapcar #'car (org-get-buffer-tags))))
|
||||
|
||||
|
||||
(provide 'lisp/utils)
|
||||
;;; utils.el ends here
|
|
@ -15,4 +15,3 @@
|
|||
ads ad asd asd as dasd asd
|
||||
- [[http://localhost:3003/essays/serene-blah.html][Serene blah]]
|
||||
- [[http://localhost:3003/essays/javascript-blah.html][javascript blah]]
|
||||
- [[http://localhost:3003/essays/theindex.html][Index]]
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
#+TITLE: lxsameer's nest
|
||||
|
||||
- [[file:theindex.org][Index]]
|
||||
- [[file:categories/nil.org][<<<title>>>]]
|
||||
- [[file:categories/SLA.org][SLA]]
|
||||
- [[file:tags/ASDK.org][ASDK]]
|
||||
- [[file:tags/BD.org][BD]]
|
||||
- [[file:tags/ABD.org][ABD]]
|
||||
- [[file:essays/javascript-blah.org][javascript blah]]
|
||||
- [[file:tags/index.org][index]]
|
||||
- [[file:categories/index.org][index]]
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
<header>
|
||||
<nav style="text-align: center;">
|
||||
<a href="/">HOME</a> | <a href="#">GPG</a> | <a href="/categories/">Categories</a> | <a href="/tags/">Tags</a>
|
||||
<a href="/">HOME</a> | <a href="/categories/">Categories</a> | <a href="/tags/">Tags</a> | <a href="#">Code of Honor</a> | <a href="#">RSS</a>
|
||||
</nav>
|
||||
<hr/>
|
||||
</header>
|
||||
|
@ -27,7 +27,6 @@
|
|||
<span>Built with <a href="https://www.gnu.org/software/emacs/">Emacs Lisp</a> and <a href="https://orgmode.org/">org-mode</a>.</span><br/>
|
||||
<span><a href="https://devheroes.codes/lxsameer/lxhome">https://devheroes.codes/lxsameer/lxhome</a></span>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
#+SETUPFILE: ../../config.org
|
||||
#+OPTIONS: toc:nil
|
||||
#+EXPORT_FILE_NAME: index.html
|
||||
#+PAGE: true
|
||||
#+TITLE: Categories
|
||||
|
||||
<<<links>>>
|
|
@ -0,0 +1,16 @@
|
|||
#+SETUPFILE: ../config.org
|
||||
#+OPTIONS: toc:nil
|
||||
#+EXPORT_FILE_NAME: index.html
|
||||
#+TAGS: ABD(a) BD(c) ASDK(k)
|
||||
#+DATE: 2021-02-11
|
||||
#+CATEGORY: blah
|
||||
#+TITLE: blah
|
||||
#+PAGE: true
|
||||
|
||||
* Welcome :ABD:BD:
|
||||
:PROPERTIES:
|
||||
:BLAH: s
|
||||
:END:
|
||||
blha bbasd asds asd a asd =asdasd= somer `asdasd` sadasd *asdasD* asdasd /asdasd/ asdasd.
|
||||
ads ad asd asd as dasd asd
|
||||
<<<links>>>
|
|
@ -0,0 +1,7 @@
|
|||
#+SETUPFILE: ../../config.org
|
||||
#+OPTIONS: toc:nil
|
||||
#+TITLE: <<<title>>>
|
||||
#+PAGE: true
|
||||
|
||||
|
||||
<<<links>>>
|
|
@ -0,0 +1 @@
|
|||
<h1>{{title}}</h1>
|
|
@ -0,0 +1,2 @@
|
|||
<h1 class="title">{{title}}</h1>
|
||||
<span class="tags">{{{tags}}}</span> - <time>{{date}}</time>
|
|
@ -0,0 +1,8 @@
|
|||
#+SETUPFILE: ../../config.org
|
||||
#+OPTIONS: toc:nil
|
||||
#+EXPORT_FILE_NAME: index.html
|
||||
#+PAGE: true
|
||||
#+TITLE: Tags
|
||||
|
||||
|
||||
<<<links>>>
|
載入中…
新增問題並參考