Skip to content

Commit

Permalink
implement rss feature
Browse files Browse the repository at this point in the history
  • Loading branch information
sillykelvin committed Sep 3, 2013
1 parent a72fd74 commit a418548
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
37 changes: 36 additions & 1 deletion op-export.el
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
(require 'format-spec)
(require 'ox)
(require 'ht)
(require 'dash)
(require 'op-util)
(require 'op-vars)
(require 'op-git)
Expand Down Expand Up @@ -72,6 +73,7 @@ deleted. PUB-ROOT-DIR is the root publication directory."
all-list)
(op/generate-default-about pub-root-dir))
(op/update-category-index file-attr-list pub-root-dir)
(op/update-rss file-attr-list pub-root-dir)
(op/update-tags file-attr-list pub-root-dir))))

(defun op/get-org-file-options (pub-root-dir do-pub)
Expand All @@ -91,7 +93,9 @@ content of the buffer will be converted into html."
filename)
(format-time-string
"%Y-%m-%d"
(nth 5 (file-attributes filename)))))))
(nth 5 (file-attributes filename)))))
:description ,(or (op/read-org-option "DESCRIPTION")
"No Description")))
component-table tags category cat-config)
(setq tags (op/read-org-option "TAGS"))
(when tags
Expand Down Expand Up @@ -494,6 +498,37 @@ TODO: improve this function."
(concat tag-dir "index.html") 'html-mode))
tag-alist)))

(defun op/update-rss (file-attr-list pub-base-dir)
"Update RSS. FILE-ATTR-LIST is the list of all file attribute property lists.
PUB-BASE-DIR is the root publication directory."
(let ((last-10-posts
(-take 10 (--sort (>= 0 (compare-standard-date
(fix-timestamp-string
(plist-get it :mod-date))
(fix-timestamp-string
(plist-get other :mod-date))))
(--filter (not (or
(string= (plist-get it :category)
"index")
(string= (plist-get it :category)
"about")))
file-attr-list)))))
(string-to-file
(mustache-render
op/rss-template
(ht ("title" op/site-main-title)
("link" op/site-domain)
("description" op/site-sub-title)
("date" (format-time-string "%a, %d %b %Y %T %Z"))
("items" (--map (ht ("item-title" (plist-get it :title))
("item-link" (concat (replace-regexp-in-string
"/?$" "" op/site-domain)
(plist-get it :uri)))
("item-description" (plist-get it :description))
("item-update-date" (plist-get it :mod-date)))
last-10-posts))))
(concat pub-base-dir "rss.xml"))))


(provide 'op-export)

Expand Down
24 changes: 24 additions & 0 deletions op-vars.el
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,30 @@ default value is `op/get-file-category'."
(defvar op/item-cache nil
"The cache for general purpose.")

(defconst op/rss-template "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<rss version=\"2.0\">
<channel>
<title>{{title}}</title>
<link>{{link}}</link>
<description>{{description}}</description>
<pubDate>{{date}}</pubDate>
<lastBuildDate>{{date}}</lastBuildDate>
<docs>http://www.rssboard.org/rss-specification</docs>
<generator>Org-page static site generator \
(https://github.com/kelvinh/org-page)</generator>
{{#items}}
<item>
<title>{{item-title}}</title>
<link>{{item-link}}</link>
<description>{{item-description}}</description>
<pubDate>{{item-update-date}}</pubDate>
<guid>{{item-link}}</guid>
</item>
{{/items}}
</channel>
</rss>"
"Template for RSS rendering.")


(provide 'op-vars)

Expand Down

0 comments on commit a418548

Please sign in to comment.