Separate code blog from ordinary blog

This can now be done by putting code-only posts in a "clog" folder
instead of the customary "blog". To implement this, the code
checks the path of every file and matches the beginning with the
string "posts/clog/".

Other posts can be moved to a "blog" folder or kept outside as-is;
it doesn't make a difference because everything that is not in
"posts/clog/" is filed into the ordinary blog as a default.
This commit is contained in:
Badri Sunderarajan 2024-03-31 17:03:51 +05:30
parent 4483822ef6
commit 69ea5ac4ce
Signed by: badrihippo
GPG Key ID: 9F594532AD60DE03
6 changed files with 44 additions and 2 deletions

View File

@ -118,6 +118,8 @@
(strong "@badrihippo")
" or read my "
,(animating-a "/blog/" "computer" "blog")
" and "
,(animating-a "/clog/" "computer" "code blog")
".")
))
@ -131,6 +133,16 @@
#:big-logo #t)
sxml->html))
;; We'll need this to compare the beginnings
;; of strings
(define (string-head string length)
(list->string (list-head (string->list string) length)))
(define (string-starts-with? string match)
(let ((match-length (string-length match)))
(if (< (string-length string) match-length)
#f
(equal? (string-head string match-length) match))))
;; Blog contents
(define* (post-template post #:key post-link)
@ -158,6 +170,23 @@
(div ,(or (post-ref post 'summary))))))
posts))))
;; Different slug for code and normal blog
(define (code-post? post)
(string-starts-with? (post-file-name post) "posts/clog/"))
(define (post-slug-category post)
(let ((clog-or-blog (if (code-post? post)
"clog/"
"blog/")))
(string-append clog-or-blog (post-slug-v2 post))))
(define (posts/blog posts)
(filter (lambda (post) (not (code-post? post)))
posts))
(define (posts/clog posts)
(filter code-post? posts))
(define hippo-haunt-theme
(theme #:name "Hippo"
#:layout
@ -173,9 +202,22 @@
#:default-metadata
'((author . "Badri Sunderarajan")
(email . "badrihippo@disroot.org"))
#:posts-directory "posts"
#:make-slug post-slug-category
#:readers (list commonmark-reader)
#:builders (list (blog #:prefix "/blog"
#:theme hippo-haunt-theme)
#:builders (list (blog #:prefix ""
#:theme hippo-haunt-theme
#:collections
`(("Latest Posts"
"blog/index.html"
,(lambda (posts)
(posts/reverse-chronological
(posts/blog posts))))
("Code Blog"
"clog/index.html"
,(lambda (posts)
(posts/reverse-chronological
(posts/clog posts))))))
index-page
(atom-feed)
(atom-feeds-by-tag)