2024-01-18 17:38:14 +00:00
|
|
|
#lang racket
|
|
|
|
(provide (all-defined-out))
|
|
|
|
|
|
|
|
(require (only-in racket/list flatten add-between)
|
|
|
|
(only-in xml xexpr->string))
|
|
|
|
|
|
|
|
|
|
|
|
(define homepage "https://oxaliq.net")
|
|
|
|
|
|
|
|
;; 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))))
|
|
|
|
|
2024-01-18 18:15:30 +00:00
|
|
|
(define (archive-file input-file test #:modify-mode (exists-ok #f))
|
2024-01-18 17:38:14 +00:00
|
|
|
(if test
|
|
|
|
(copy-file input-file (string-replace input-file "in-progress" "publish-test/archive") #t)
|
2024-01-18 18:15:30 +00:00
|
|
|
(rename-file-or-directory input-file (string-replace input-file "in-progress" "archive") exists-ok)))
|
2024-01-18 17:38:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
;; 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 "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
|
|
|
(xexpr->string ((eval (read make-atom-input-port) ns)
|
|
|
|
"https://oxaliq.net/feed.atom"
|
|
|
|
publish-time
|
|
|
|
hp
|
|
|
|
(rest atom-table)))))
|
|
|
|
;; ---------------
|