about summary refs log tree commit diff
path: root/pandoc-blog/make.scm
diff options
context:
space:
mode:
authorArun Isaac2025-04-07 15:57:53 +0100
committerArun Isaac2025-04-07 15:57:53 +0100
commita760bff3efa44c282ed119032a6831bdaac79e7b (patch)
tree44a74e8d59b44065ab5b3a3270ba57827ec5fc1a /pandoc-blog/make.scm
downloadgexp-make-a760bff3efa44c282ed119032a6831bdaac79e7b.tar.gz
gexp-make-a760bff3efa44c282ed119032a6831bdaac79e7b.tar.lz
gexp-make-a760bff3efa44c282ed119032a6831bdaac79e7b.zip
Initial commit
Diffstat (limited to 'pandoc-blog/make.scm')
-rw-r--r--pandoc-blog/make.scm47
1 files changed, 47 insertions, 0 deletions
diff --git a/pandoc-blog/make.scm b/pandoc-blog/make.scm
new file mode 100644
index 0000000..1c9728c
--- /dev/null
+++ b/pandoc-blog/make.scm
@@ -0,0 +1,47 @@
+(use-modules ((gnu packages haskell-xyz) #:select (pandoc))
+	     ((gnu packages python) #:select (python))
+	     (guix build utils)
+	     (guix gexp))
+
+(define (build-post post)
+  (computed-file (basename post ".md")
+		 (with-imported-modules '((guix build utils))
+		   #~(begin
+		       (use-modules (guix build utils))
+
+		       (let ((posts-directory (string-append #$output "/posts/")))
+			 (mkdir-p posts-directory)
+			 (invoke #$(file-append pandoc "/bin/pandoc")
+				 "--from" "markdown"
+				 "--to" "html"
+				 "--standalone"
+				 "--output" (string-append posts-directory
+							   #$(basename post ".md")
+							   ".html")
+				 #$(local-file post)))))))
+
+(define (build-index posts)
+  (computed-file "blog-index"
+		 (with-imported-modules '((guix build utils))
+		   #~(begin
+		       (use-modules (guix build utils))
+
+		       (invoke #$(file-append python "/bin/python3")
+			       #$(local-file "generate-index.py")
+			       "index.md"
+			       #$@(map (lambda (file)
+					 (local-file file))
+				       posts))
+		       (mkdir #$output)
+		       (invoke #$(file-append pandoc "/bin/pandoc")
+			       "--from" "markdown"
+			       "--to" "html"
+			       "--standalone"
+			       "--metadata" "title=My blog"
+			       "--output" (string-append #$output "/index.html")
+			       "index.md")))))
+
+(let ((posts (find-files "posts" "\\.md$")))
+  (directory-union "blog"
+		   (cons (build-index posts)
+			 (map build-post posts))))