Compare commits
3 commits
7b9e5d2d18
...
7bc26d0864
Author | SHA1 | Date | |
---|---|---|---|
7bc26d0864 | |||
c81dbccac1 | |||
145127b430 |
5 changed files with 109 additions and 41 deletions
6
.dev-log
6
.dev-log
|
@ -1,3 +1,9 @@
|
||||||
|
2024/01/17
|
||||||
|
- add html cache directories to build script
|
||||||
|
TODO:
|
||||||
|
- putting content in atom will require changing csv parsing;
|
||||||
|
that's for v2
|
||||||
|
|
||||||
2024/01/15
|
2024/01/15
|
||||||
- cache static logic
|
- cache static logic
|
||||||
- START HERE:
|
- START HERE:
|
||||||
|
|
|
@ -13,12 +13,17 @@ mv static oxaliq/.
|
||||||
# add html cache directories
|
# add html cache directories
|
||||||
echo "ADDING HTML CACHE DIRECTORIES"
|
echo "ADDING HTML CACHE DIRECTORIES"
|
||||||
mkdir fragment
|
mkdir fragment
|
||||||
mkdir fragment/settled
|
mkdir settled
|
||||||
mkdir fragment/unsettled
|
mkdir unsettled
|
||||||
|
mkdir tagged
|
||||||
|
cp -r settled fragment/.
|
||||||
|
cp -r unsettled fragment/.
|
||||||
|
cp -r tagged fragment/.
|
||||||
mv fragment oxaliq/static/.
|
mv fragment oxaliq/static/.
|
||||||
mkdir page
|
mkdir page
|
||||||
mkdir page/settled
|
mv settled page/.
|
||||||
mkdir page/unsettled
|
mv unsettled page/.
|
||||||
|
mv tagged page/.
|
||||||
mv page oxaliq/static/.
|
mv page oxaliq/static/.
|
||||||
|
|
||||||
# put them on the deployment target
|
# put them on the deployment target
|
||||||
|
|
29
modify.rkt
29
modify.rkt
|
@ -8,7 +8,7 @@
|
||||||
(only-in racket/function thunk identity)
|
(only-in racket/function thunk identity)
|
||||||
(only-in csv-reading csv->list)
|
(only-in csv-reading csv->list)
|
||||||
(only-in xml read-xml)
|
(only-in xml read-xml)
|
||||||
(only-in "./tool/utils.rkt" list->csv resource-link atom-table-entry add-atom-entry
|
(only-in "./utils.rkt" list->csv resource-link atom-table-entry add-atom-entry
|
||||||
make-feed archive-file))
|
make-feed archive-file))
|
||||||
|
|
||||||
(define-namespace-anchor anc)
|
(define-namespace-anchor anc)
|
||||||
|
@ -80,7 +80,7 @@
|
||||||
;; (. -> . input-port? output-port?)
|
;; (. -> . input-port? output-port?)
|
||||||
(define (get-source-ports)
|
(define (get-source-ports)
|
||||||
(let ([file-handle (path-add-extension
|
(let ([file-handle (path-add-extension
|
||||||
(if (eq? r-type "root")
|
(if (equal? r-type "root")
|
||||||
(if x-test
|
(if x-test
|
||||||
(build-path "publish-test" "source" l-head)
|
(build-path "publish-test" "source" l-head)
|
||||||
(build-path "source" l-head))
|
(build-path "source" l-head))
|
||||||
|
@ -212,8 +212,8 @@
|
||||||
|
|
||||||
;; write-to-file must manually truncate since out-ports do not truncate
|
;; write-to-file must manually truncate since out-ports do not truncate
|
||||||
;; (output-port? xexpr? xexpr? rb-thunks? . -> . rb-thunks?)
|
;; (output-port? xexpr? xexpr? rb-thunks? . -> . rb-thunks?)
|
||||||
(define (write-to-file out-port new-content old-content accumulator)
|
(define (write-to-file out-port new-content old-content accumulator #:print-mode? (is-print #f))
|
||||||
(let ([rb-thunks (cons (thunk (write-to-file-with-retries out-port old-content))
|
(let ([rb-thunks (cons (thunk (write-to-file-with-retries out-port old-content is-print))
|
||||||
(hash-ref accumulator 'rb-thunks))])
|
(hash-ref accumulator 'rb-thunks))])
|
||||||
(if (port-try-file-lock? out-port 'exclusive)
|
(if (port-try-file-lock? out-port 'exclusive)
|
||||||
;; wrap in handler that raises file-write-exception
|
;; wrap in handler that raises file-write-exception
|
||||||
|
@ -225,7 +225,7 @@
|
||||||
rb-thunks)))
|
rb-thunks)))
|
||||||
(thunk
|
(thunk
|
||||||
(file-truncate out-port 0)
|
(file-truncate out-port 0)
|
||||||
(display new-content out-port)
|
((if is-print print display) new-content out-port)
|
||||||
(port-file-unlock out-port)
|
(port-file-unlock out-port)
|
||||||
(close-output-port out-port)))
|
(close-output-port out-port)))
|
||||||
(hash-update accumulator 'rb-thunks
|
(hash-update accumulator 'rb-thunks
|
||||||
|
@ -235,13 +235,13 @@
|
||||||
(current-continuation-marks)
|
(current-continuation-marks)
|
||||||
rb-thunks)))))
|
rb-thunks)))))
|
||||||
|
|
||||||
(define (write-to-file-with-retries out-port content)
|
(define (write-to-file-with-retries out-port content is-print)
|
||||||
(with-handlers
|
(with-handlers
|
||||||
([file-write-exception? (lambda (expn)
|
([file-write-exception? (lambda (expn)
|
||||||
(displayln "filewrite failed with" expn)
|
(displayln "filewrite failed with" expn)
|
||||||
(displayln "retrying")
|
(displayln "retrying")
|
||||||
(write-to-file-with-retries out-port content))])
|
(write-to-file-with-retries out-port content is-print))])
|
||||||
(write-to-file out-port content)))
|
(write-to-file out-port content #:print-mode? is-print)))
|
||||||
;; ------------
|
;; ------------
|
||||||
|
|
||||||
;; resource-replacement
|
;; resource-replacement
|
||||||
|
@ -277,7 +277,7 @@
|
||||||
(write-to-file
|
(write-to-file
|
||||||
source-output-port
|
source-output-port
|
||||||
(make-new-content res-table)
|
(make-new-content res-table)
|
||||||
old-content accumulator)
|
old-content accumulator #:print-mode? #t)
|
||||||
'res-table)
|
'res-table)
|
||||||
'resource
|
'resource
|
||||||
identity
|
identity
|
||||||
|
@ -327,7 +327,7 @@
|
||||||
[desc (third res-row)]
|
[desc (third res-row)]
|
||||||
[publish-time (hash-ref accumulator 'publish-time)]
|
[publish-time (hash-ref accumulator 'publish-time)]
|
||||||
[new-table (add-atom-entry old-table
|
[new-table (add-atom-entry old-table
|
||||||
(atom-table-entry l-head res-link desc publish-time update-time))])
|
(atom-table-entry l-head res-link desc publish-time #:update-time update-time))])
|
||||||
(hash-remove
|
(hash-remove
|
||||||
(hash-remove
|
(hash-remove
|
||||||
(hash-update
|
(hash-update
|
||||||
|
@ -390,13 +390,8 @@
|
||||||
(compose-accumulator rollback-thunks))
|
(compose-accumulator rollback-thunks))
|
||||||
|
|
||||||
;; only archive after everything else is done
|
;; only archive after everything else is done
|
||||||
(archive-file n-in x-test)
|
(archive-file n-in x-test #:modify-mode #t)
|
||||||
|
|
||||||
(displayln "modify was successful")))))
|
(displayln "modify was successful")))))
|
||||||
|
|
||||||
;(run modify)
|
(run modify)
|
||||||
|
|
||||||
(run modify #("-i" "in-progress/now.txt"
|
|
||||||
"-l" "now"
|
|
||||||
"-r" "root"
|
|
||||||
"-x"))
|
|
||||||
|
|
39
publish.rkt
39
publish.rkt
|
@ -5,7 +5,7 @@
|
||||||
(only-in racket/format ~a)
|
(only-in racket/format ~a)
|
||||||
(only-in racket/list append* first second third fourth fifth rest flatten add-between take)
|
(only-in racket/list append* first second third fourth fifth rest flatten add-between take)
|
||||||
(only-in xml xexpr->string)
|
(only-in xml xexpr->string)
|
||||||
(only-in "./tool/utils.rkt" homepage list->csv add-atom-entry archive-file)
|
(only-in "./utils.rkt" homepage list->csv add-atom-entry atom-table-entry make-feed archive-file)
|
||||||
csv-reading)
|
csv-reading)
|
||||||
|
|
||||||
(define-namespace-anchor anc)
|
(define-namespace-anchor anc)
|
||||||
|
@ -254,6 +254,7 @@
|
||||||
|
|
||||||
|
|
||||||
;; update tag table
|
;; update tag table
|
||||||
|
(displayln "updating tag table")
|
||||||
(define tag-table (csv->list (open-input-file
|
(define tag-table (csv->list (open-input-file
|
||||||
(if x "publish-test/data/tagged.csv" "data/tagged.csv"))))
|
(if x "publish-test/data/tagged.csv" "data/tagged.csv"))))
|
||||||
(define new-tag-table (write-new-tag-table tag-table t r res-id))
|
(define new-tag-table (write-new-tag-table tag-table t r res-id))
|
||||||
|
@ -263,11 +264,11 @@
|
||||||
(if x
|
(if x
|
||||||
(write-new-tagged/index new-tag-table #:test #t)
|
(write-new-tagged/index new-tag-table #:test #t)
|
||||||
(write-new-tagged/index new-tag-table)))
|
(write-new-tagged/index new-tag-table)))
|
||||||
; (displayln new-tag-table)
|
|
||||||
(write-csv-to-file (list->csv new-tag-table)
|
(write-csv-to-file (list->csv new-tag-table)
|
||||||
(if x "publish-test/data/tagged.csv" "data/tagged.csv"))
|
(if x "publish-test/data/tagged.csv" "data/tagged.csv"))
|
||||||
|
|
||||||
|
(displayln "updating tagged/'tag")
|
||||||
;; update tagged/'tag for each tag
|
;; update tagged/'tag for each tag
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (tt-row)
|
(lambda (tt-row)
|
||||||
|
@ -282,19 +283,23 @@
|
||||||
'())))
|
'())))
|
||||||
new-tag-table)
|
new-tag-table)
|
||||||
|
|
||||||
|
(displayln "writing resource to file")
|
||||||
;; write to file
|
;; write to file
|
||||||
(if (port-try-file-lock? out 'exclusive)
|
(if (port-try-file-lock? out 'exclusive)
|
||||||
(begin
|
(begin
|
||||||
(write resource out)
|
(print resource out)
|
||||||
(port-file-unlock out)
|
(port-file-unlock out)
|
||||||
(close-output-port out))
|
(close-output-port out))
|
||||||
(error "couldn't obtain file lock on ~a" out))
|
(error "couldn't obtain file lock on ~a" out))
|
||||||
|
|
||||||
;; update 'resource/index
|
;; update 'resource/index
|
||||||
(write-new-resource/index r new-res-table #:test (if x #t #f))
|
(if (equal? r "root")
|
||||||
|
(displayln "skipping resource/index")
|
||||||
|
(begin
|
||||||
|
(displayln "updating resource/index")
|
||||||
|
(write-new-resource/index r new-res-table #:test (if x #t #f))))
|
||||||
|
|
||||||
|
(displayln "updating feed table")
|
||||||
;; update feed table
|
;; update feed table
|
||||||
(define atom-table (csv->list
|
(define atom-table (csv->list
|
||||||
(open-input-file
|
(open-input-file
|
||||||
|
@ -304,30 +309,28 @@
|
||||||
(build-path "data" "atom"))
|
(build-path "data" "atom"))
|
||||||
#".csv"))))
|
#".csv"))))
|
||||||
(define new-atom-table
|
(define new-atom-table
|
||||||
(add-atom-entry atom-table (list l (~a res-link) d publish-time)))
|
(add-atom-entry atom-table (atom-table-entry l (~a res-link) d publish-time)))
|
||||||
(write-csv-to-file (list->csv new-atom-table)
|
(write-csv-to-file (list->csv new-atom-table)
|
||||||
(if x "publish-test/data/atom.csv" "data/atom.csv"))
|
(if x "publish-test/data/atom.csv" "data/atom.csv"))
|
||||||
|
|
||||||
|
|
||||||
;; update feed.atom
|
;; update feed.atom
|
||||||
;; for now, this does not include the html for the post, only a link
|
;; for now, this does not include the html for the post, only a link
|
||||||
(define feed ((eval (read (open-input-file (if x
|
(displayln "updating feed")
|
||||||
"publish-test/data/make-atom.txt"
|
|
||||||
"data/make-atom.txt"))) ns)
|
|
||||||
"https://oxaliq.net/feed.atom"
|
|
||||||
publish-time
|
|
||||||
homepage
|
|
||||||
(rest new-atom-table)))
|
|
||||||
(define feed-out
|
(define feed-out
|
||||||
(open-output-file (if x "publish-test/source/feed.atom"
|
(open-output-file (if x "publish-test/source/feed.atom"
|
||||||
"source/feed.atom")
|
"source/feed.atom")
|
||||||
;; need to remove this and just replace once testing is done
|
;; need to remove this and just replace once testing is done
|
||||||
#:exists (if x 'replace 'error)))
|
#:exists 'replace ))
|
||||||
(if (port-try-file-lock? feed-out 'exclusive)
|
(if (port-try-file-lock? feed-out 'exclusive)
|
||||||
(begin
|
(begin
|
||||||
(display
|
(display
|
||||||
(string-append "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
(make-feed ns (open-input-file
|
||||||
(xexpr->string feed))
|
(if x
|
||||||
|
"publish-test/data/make-atom.txt"
|
||||||
|
"data/make-atom.txt"))
|
||||||
|
new-atom-table
|
||||||
|
publish-time)
|
||||||
feed-out)
|
feed-out)
|
||||||
(port-file-unlock feed-out)
|
(port-file-unlock feed-out)
|
||||||
(close-output-port feed-out))
|
(close-output-port feed-out))
|
||||||
|
|
59
utils.rkt
Normal file
59
utils.rkt
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
#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))))
|
||||||
|
|
||||||
|
(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 "<?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)))))
|
||||||
|
;; ---------------
|
Loading…
Reference in a new issue