#lang racket (provide (all-defined-out)) (require (only-in racket/list flatten add-between) (only-in xml xexpr->string)) (define homepage "https://oxaliq.net") (define git-forge "https://git.bunk.computer/oxaliq/oxaliq.net/src/branch/main/") (define (source-url resource-type resource-id) (~a git-forge (if (equal? resource-type "root") "source/" (~a "source/" resource-type)) resource-id ".scm")) ;; takes a parsed table as a list of lists and formats for writing as a .csv file (define (list->csv l) (foldl (lambda (i res) (string-append res i)) "" (flatten (add-between (map (lambda (row) (add-between row ",")) l) "\n")))) ;; construct resource-link for use in atom feed (define (resource-link resource-type resource-id #:homepage (hp homepage)) (if (equal? resource-type "root") (build-path hp (~a resource-id)) (build-path hp resource-type (~a resource-id)))) (define (archive-file input-file test #:modify-mode (exists-ok #f)) (if test (copy-file input-file (string-replace input-file "in-progress" "publish-test/archive") #t) (rename-file-or-directory input-file (string-replace input-file "in-progress" "archive") exists-ok))) ;; atom-table utils ;; ---------------- ;; atom-table-entry constructs new row to pass to add-atom-entry (define (atom-table-entry headline resource-link desc publish-time #:update-time (update-time "")) (list headline (~a resource-link) desc publish-time update-time)) ;; add-atom-entry takes old atom table and new row, constructing new ;; atom table with only first 21 rows (or all rows) (define (add-atom-entry atom-table new-row) ;; insert new-row after header (let ([out-length (min (+ 1 (length atom-table)) 21)] [header (first atom-table)] [old-content (rest atom-table)]) (take (append (list header new-row) old-content) out-length))) ;; ---------------- ;; atom-feed utils ;; --------------- (define (make-feed ns make-atom-input-port atom-table publish-time #:homepage (hp homepage)) (string-append "" (xexpr->string ((eval (read make-atom-input-port) ns) "https://oxaliq.net/feed.atom" publish-time hp (rest atom-table))))) ;; ---------------