Only generate blog index when necessary
This commit is contained in:
parent
1d6a9213cb
commit
4e8104f11f
1 changed files with 36 additions and 10 deletions
34
publish.el
34
publish.el
|
@ -52,7 +52,9 @@
|
|||
time
|
||||
(if (= time 1) "" "s")))
|
||||
|
||||
(defun publish-get-summary-from-file (file props)
|
||||
(defun publish-extract-summary-from-file (file props)
|
||||
"Extract a summary from FILE.
|
||||
PROPS is used as an aid in getting the right information from the file."
|
||||
(format "* %s\n:PROPERTIES:\n:CUSTOM_ID: %s\n:PUBDATE: %s\n:RSS_PERMALINK: %s\n:END:\n\n%s\n\n[[file:%s][Read More]]\n\n"
|
||||
(car (org-publish-find-property file :title props))
|
||||
(file-name-nondirectory file)
|
||||
|
@ -66,19 +68,43 @@
|
|||
(list file)))
|
||||
(file-name-nondirectory file)))
|
||||
|
||||
(defun publish-get-latest-modified-time (files)
|
||||
"Get the latest modification time of any file from the list FILES."
|
||||
(car
|
||||
(last
|
||||
(sort (mapcar #'org-publish-cache-mtime-of-src files) #'time-less-p))))
|
||||
|
||||
(defun publish-time>= (a b)
|
||||
"Check if time A is greater than or equal to time B."
|
||||
(not (time-less-p a b)))
|
||||
|
||||
(defun publish-empty-time ()
|
||||
"Get an empty time value."
|
||||
(let ((current-time (current-time)))
|
||||
(time-subtract current-time current-time)))
|
||||
|
||||
(defun publish-generate-index (props)
|
||||
"Generate an index from my posts.
|
||||
Argument PROPS
|
||||
."
|
||||
(let ((files (directory-files "posts/" t (rx bos (= 8 digit) "-" (= 4 digit) "-" (one-or-more nonl) (not "~") eos))))
|
||||
(let* ((index-file (expand-file-name "posts/index.org"))
|
||||
(index-generated-time (or (and (file-exists-p index-file)
|
||||
(org-publish-cache-mtime-of-src index-file))
|
||||
(publish-empty-time)))
|
||||
(files (directory-files "posts/" t (rx bos (= 8 digit) "-" (= 4 digit) "-" (one-or-more nonl) (not "~") eos)))
|
||||
(latest-modification-time (publish-get-latest-modified-time files)))
|
||||
(if (publish-time>= index-generated-time latest-modification-time)
|
||||
(message "Not generating index...")
|
||||
(progn
|
||||
(message "Generating index...")
|
||||
(with-temp-buffer
|
||||
(insert "#+title: ryuslash's blog\n")
|
||||
(insert "#+options: num:nil\n")
|
||||
(insert "\n")
|
||||
(apply 'insert
|
||||
(mapcar (lambda (file) (publish-get-summary-from-file file props))
|
||||
(mapcar (lambda (file) (publish-extract-summary-from-file file props))
|
||||
(take 30 (reverse files))))
|
||||
(write-file "posts/index.org"))))
|
||||
(write-file "posts/index.org"))))))
|
||||
|
||||
(setq org-export-exclude-tags '("noexport" "draft"))
|
||||
|
||||
|
|
Loading…
Reference in a new issue