aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCem Keylan <cem@ckyln.com>2021-03-03 15:16:50 +0300
committerCem Keylan <cem@ckyln.com>2021-03-03 15:16:50 +0300
commit960a2bb03790ade45949ec46852eb363fbfeb81e (patch)
tree9bac2ef4ebd8759c467ba384a93af1cafaca3fc8
parentae1b5f7496dfe30e840870ee2e8875534c0e3fba (diff)
downloadwebsite-960a2bb03790ade45949ec46852eb363fbfeb81e.tar.gz
add latest blog posts to index page
-rw-r--r--.gitignore1
-rwxr-xr-xorg-publish.el31
-rw-r--r--src/index.org4
3 files changed, 36 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 167d057..7fafb4f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@
/news/index.org
/news/news.org
/news/latest-news.org
+/blog/latest-blog.org
/blog/index.org
/blog/rss.org
/docs/
diff --git a/org-publish.el b/org-publish.el
index 6f9165a..872b33d 100755
--- a/org-publish.el
+++ b/org-publish.el
@@ -131,6 +131,26 @@ returned by `org-list-to-lisp'."
(concat (carbs--insert-template "blog.org")
(org-list-to-org filtered-list) "\n")))
+(defun carbs/org-publish-latest-blog (title list)
+ "Generate sitemap as a string, having TITLE.
+LIST is an internal representation for the files to include, as returned by
+`org-list-to-lisp'."
+ (let* ((filtered-list (cl-remove-if (lambda (x)
+ (and (sequencep x) (null (car x))))
+ list))
+ (latest-posts (seq-subseq filtered-list 0 (min (length filtered-list) 4))))
+ (concat (org-list-to-org latest-posts) "\n")))
+
+(defun carbs/org-publish-latest-blog-entry (entry style project)
+ "Format for sitemap ENTRY, as a string.
+ENTRY is a file name. STYLE is the style of the sitemap.
+PROJECT is the current project."
+ (unless (equal entry "404.org")
+ (format "%s - [[file:%s][%s]]"
+ (format-time-string "%b %d, %Y" (org-publish-find-date entry project))
+ entry
+ (org-publish-find-title entry project))))
+
(defun carbs/org-publish-sitemap-entry (entry style project)
"Format for sitemap ENTRY, as a string.
ENTRY is a file name. STYLE is the style of the sitemap.
@@ -246,6 +266,17 @@ PROJECT is the current project."
:html-link-home "https://carbslinux.org/news"
:publishing-directory carbs--publish-directory
:publishing-function 'carbs/org-rss-publish-to-rss)
+ (list "blog-latest"
+ :base-directory carbs--blog-directory
+ :publishing-directory carbs--publish-directory
+ :publishing-function 'ignore
+ :exclude (regexp-opt '("index.org" "rss.org" "latest-blog.org"))
+ :auto-sitemap t
+ :sitemap-filename "latest-blog.org"
+ :sitemap-style 'list
+ :sitemap-sort-files 'anti-chronologically
+ :sitemap-function 'carbs/org-publish-latest-blog
+ :sitemap-format-entry 'carbs/org-publish-latest-blog-entry)
(list "home"
:base-directory carbs--src-directory
:html-preamble t
diff --git a/src/index.org b/src/index.org
index ee130ba..df920ae 100644
--- a/src/index.org
+++ b/src/index.org
@@ -63,6 +63,10 @@ other system supervision technique along with your own init scripts.
- Reddit - [[https://reddit.com/r/carbslinux][r/carbslinux]]
- [[file:mailing-lists.org][Mailing Lists]]
+* Latest Blog Posts
+
+#+INCLUDE: ../blog/latest-blog.org :minlevel 1
+
* News
:PROPERTIES:
:CUSTOM_ID: news