From 1cb2b2d6241b6dc88d1f5e5dcc128841e154a1d7 Mon Sep 17 00:00:00 2001 From: nathansmith Date: Wed, 7 May 2025 09:44:57 -0600 Subject: Changed the blog html generater to scheme as well --- blog/Makefile | 4 +- blog/generate_html.py | 68 ------------------------- blog/generate_html.scm | 71 ++++++++++++++++++++++++++ blog/index.html | 132 ++++++++++++++++++++++++------------------------- blog/template.html | 16 +++--- 5 files changed, 143 insertions(+), 148 deletions(-) delete mode 100755 blog/generate_html.py create mode 100755 blog/generate_html.scm diff --git a/blog/Makefile b/blog/Makefile index 3b3341e..4e13f8c 100644 --- a/blog/Makefile +++ b/blog/Makefile @@ -3,8 +3,8 @@ all: @echo Generating feed ./generate_feed.scm > feed.xml @echo Generating html - ./generate_html.py > index.html + ./generate_html.scm > index.html .PHONY: clean clean: - rm feed.rss index.html + rm feed.xml index.html diff --git a/blog/generate_html.py b/blog/generate_html.py deleted file mode 100755 index ce50032..0000000 --- a/blog/generate_html.py +++ /dev/null @@ -1,68 +0,0 @@ -#! /usr/bin/python3 - -""" -A script to generate html from the rss feed -""" - -import xml.etree.ElementTree as et - -# Generates a html table for the article -# I use table layout because fuck you -def make_article_table(article_info, article): - return """ - - - -

{title}

--- {date}
{article}
- """.format( - name=article_info["name"], - title=article_info["title"], - date=article_info["pubDate"], - article=article - ) - -def main(): - tree = et.parse("articles.xml") - root = tree.getroot() - - template = "" - - # Open html template - with open("template.html", "r") as fp: - template = fp.read() - - article_list = "" - - # Format the articles into the html - template = template.format(article_list=article_list, articles=article_html) - print(template) - -if __name__ == "__main__": - main() diff --git a/blog/generate_html.scm b/blog/generate_html.scm new file mode 100755 index 0000000..2d9baeb --- /dev/null +++ b/blog/generate_html.scm @@ -0,0 +1,71 @@ +#! /usr/bin/guile \ +-e main -s +!# + +(use-modules (sxml simple)) + +;; Loads an entire text file into a string +(define (read-entire-file file) + (call-with-input-file file + (lambda (fp) + (letrec ((read-characters + (lambda (fp) + (let ((character (read-char fp))) + (cond + ((eof-object? character) "") + (else (string-append (string character) + (read-characters fp)))))))) + (read-characters fp))))) + +;; Make a link for the article +(define (make-article-list-link article) + (let ((title (cadr (list-ref article 0))) + (name (cadr (list-ref article 2)))) + (string-append "
  • " title "
  • \n"))) + +;; Reads the article file and formats some stuff out +(define (get-raw-article file) + (letrec ((article (read-entire-file file)) + (article-open (string-contains article "
    ")) + (article-close (string-contains article "
    "))) + (substring article (+ article-open 9) article-close))) + +;; Makes a card for the article +(define (make-article-card article) + (let ((title (cadr (list-ref article 0))) + (name (cadr (list-ref article 2))) + (pub-date (cadr (list-ref article 4))) + (file (cadr (list-ref article 6)))) + (string-append + "\n\n" + " \n" + " \n" + "

    " title "

    --- " pub-date + "
    " (get-raw-article file) "
    \n"))) + +;; Generates a html blog from xml data +(define (generate-html) + (let ((template (read-entire-file "template.html")) + (article-list "\n")) + (format #t template article-list article-cards))) + +(define (main args) + (generate-html)) diff --git a/blog/index.html b/blog/index.html index e30b487..233ec2e 100644 --- a/blog/index.html +++ b/blog/index.html @@ -7,9 +7,6 @@ @@ -50,13 +47,12 @@ table {{ - {article_list} + ~a - - {articles} + ~a -- cgit v1.2.3