From 14f718834fa12d87a9abf419a05e7762b00c3b09 Mon Sep 17 00:00:00 2001 From: nathan Date: Sat, 24 May 2025 00:26:37 -0600 Subject: More small pointless changes --- org/blog/Makefile | 4 +-- org/blog/generate-feed.scm | 66 ++++++++++++++++++++++++++++++++++++++++++ org/blog/generate-html.scm | 71 ++++++++++++++++++++++++++++++++++++++++++++++ org/blog/generate_feed.scm | 66 ------------------------------------------ org/blog/generate_html.scm | 71 ---------------------------------------------- publish.el | 4 ++- 6 files changed, 142 insertions(+), 140 deletions(-) create mode 100755 org/blog/generate-feed.scm create mode 100755 org/blog/generate-html.scm delete mode 100755 org/blog/generate_feed.scm delete mode 100755 org/blog/generate_html.scm diff --git a/org/blog/Makefile b/org/blog/Makefile index e644a6d..06da0b6 100644 --- a/org/blog/Makefile +++ b/org/blog/Makefile @@ -1,9 +1,9 @@ .PHONY: all all: @echo Generating feed - ./generate_feed.scm > feed.xml + ./generate-feed.scm > feed.xml @echo Generating html - ./generate_html.scm > index.xhtml + ./generate-html.scm > index.xhtml .PHONY: clean clean: diff --git a/org/blog/generate-feed.scm b/org/blog/generate-feed.scm new file mode 100755 index 0000000..8519f0c --- /dev/null +++ b/org/blog/generate-feed.scm @@ -0,0 +1,66 @@ +#! /usr/bin/guile \ +-e main -s +!# + +(use-modules (sxml simple)) + +(define site-url "https://shittyweb.org") + +;; Generate description from article file +(define (get-description file) + (call-with-input-file file + (lambda (fp) + (letrec ((read-characters + (lambda (fp) + (let ((character (read-char fp))) + (unless (eof-object? character) + (display character) + (read-characters fp)))))) + (display "\n"))))) + +;; Generate rss item +(define (make-item 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)))) + (format #t "\n \n\ + ~a\n\ + ~a/blog#~a\n\ + ~a\n\ + \n" title site-url name pub-date) + (get-description file) + (display " \n") + (display " \n"))) + +;; Generate rss feed +(define (generate-feed) + ;; Display the rss header + (format #t "\n\ +\n\ + \n\ + Nathan's shitty blog\n\ + The coffee powered blog of chaos\n\ + ~a\n\ + \n\ + ~a/images/icon.png\n\ + Nathan's shitty blog\n\ + ~a/blog\n\ + \n" site-url site-url site-url) + + (call-with-input-file "articles.xml" + (lambda (fp) + (let ((articles (xml->sxml fp))) + (for-each (lambda (article) + (if (list? article) + (make-item (cddr article)))) + (cdr (cadr articles)))))) + + (display " \n") + (display "\n")) + +(define (main args) + (generate-feed)) + diff --git a/org/blog/generate-html.scm b/org/blog/generate-html.scm new file mode 100755 index 0000000..c214ff1 --- /dev/null +++ b/org/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.xhtml")) + (article-list "\n")) + (format #t template article-list article-cards))) + +(define (main args) + (generate-html)) diff --git a/org/blog/generate_feed.scm b/org/blog/generate_feed.scm deleted file mode 100755 index 8519f0c..0000000 --- a/org/blog/generate_feed.scm +++ /dev/null @@ -1,66 +0,0 @@ -#! /usr/bin/guile \ --e main -s -!# - -(use-modules (sxml simple)) - -(define site-url "https://shittyweb.org") - -;; Generate description from article file -(define (get-description file) - (call-with-input-file file - (lambda (fp) - (letrec ((read-characters - (lambda (fp) - (let ((character (read-char fp))) - (unless (eof-object? character) - (display character) - (read-characters fp)))))) - (display "\n"))))) - -;; Generate rss item -(define (make-item 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)))) - (format #t "\n \n\ - ~a\n\ - ~a/blog#~a\n\ - ~a\n\ - \n" title site-url name pub-date) - (get-description file) - (display " \n") - (display " \n"))) - -;; Generate rss feed -(define (generate-feed) - ;; Display the rss header - (format #t "\n\ -\n\ - \n\ - Nathan's shitty blog\n\ - The coffee powered blog of chaos\n\ - ~a\n\ - \n\ - ~a/images/icon.png\n\ - Nathan's shitty blog\n\ - ~a/blog\n\ - \n" site-url site-url site-url) - - (call-with-input-file "articles.xml" - (lambda (fp) - (let ((articles (xml->sxml fp))) - (for-each (lambda (article) - (if (list? article) - (make-item (cddr article)))) - (cdr (cadr articles)))))) - - (display " \n") - (display "\n")) - -(define (main args) - (generate-feed)) - diff --git a/org/blog/generate_html.scm b/org/blog/generate_html.scm deleted file mode 100755 index c214ff1..0000000 --- a/org/blog/generate_html.scm +++ /dev/null @@ -1,71 +0,0 @@ -#! /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.xhtml")) - (article-list "\n")) - (format #t template article-list article-cards))) - -(define (main args) - (generate-html)) diff --git a/publish.el b/publish.el index e708329..ef9e321 100644 --- a/publish.el +++ b/publish.el @@ -22,7 +22,9 @@ ) ("org-static" :base-directory "org/" - :base-extension "css\\|html\\|xhtml\\|py\\|png\\|jpg\\|gif\\|cgi\\|rss" + :base-extension "css\\|html\\|xhtml\\|py\\|png\\|jpg\\|gif\\|cgi" + :include ("blog/feed.xml") + :exclude "template.xhtml" :publishing-directory "xhtml/" :recursive t :publishing-function org-publish-attachment -- cgit v1.2.3