Only generate blog index when necessary
This commit is contained in:
parent
1d6a9213cb
commit
4e8104f11f
1 changed files with 36 additions and 10 deletions
46
publish.el
46
publish.el
|
@ -52,7 +52,9 @@
|
||||||
time
|
time
|
||||||
(if (= time 1) "" "s")))
|
(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"
|
(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))
|
(car (org-publish-find-property file :title props))
|
||||||
(file-name-nondirectory file)
|
(file-name-nondirectory file)
|
||||||
|
@ -66,19 +68,43 @@
|
||||||
(list file)))
|
(list file)))
|
||||||
(file-name-nondirectory 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)
|
(defun publish-generate-index (props)
|
||||||
"Generate an index from my posts.
|
"Generate an index from my posts.
|
||||||
Argument PROPS
|
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"))
|
||||||
(with-temp-buffer
|
(index-generated-time (or (and (file-exists-p index-file)
|
||||||
(insert "#+title: ryuslash's blog\n")
|
(org-publish-cache-mtime-of-src index-file))
|
||||||
(insert "#+options: num:nil\n")
|
(publish-empty-time)))
|
||||||
(insert "\n")
|
(files (directory-files "posts/" t (rx bos (= 8 digit) "-" (= 4 digit) "-" (one-or-more nonl) (not "~") eos)))
|
||||||
(apply 'insert
|
(latest-modification-time (publish-get-latest-modified-time files)))
|
||||||
(mapcar (lambda (file) (publish-get-summary-from-file file props))
|
(if (publish-time>= index-generated-time latest-modification-time)
|
||||||
(take 30 (reverse files))))
|
(message "Not generating index...")
|
||||||
(write-file "posts/index.org"))))
|
(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-extract-summary-from-file file props))
|
||||||
|
(take 30 (reverse files))))
|
||||||
|
(write-file "posts/index.org"))))))
|
||||||
|
|
||||||
(setq org-export-exclude-tags '("noexport" "draft"))
|
(setq org-export-exclude-tags '("noexport" "draft"))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue