Compare commits
No commits in common. "7bc26d08641848084c188e65df99e13c9febabbb" and "7b9e5d2d18ca5f1f537e0def6260ca8ea59d1df1" have entirely different histories.
7bc26d0864
...
7b9e5d2d18
5 changed files with 41 additions and 109 deletions
6
.dev-log
6
.dev-log
|
@ -1,9 +1,3 @@
|
||||||
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,17 +13,12 @@ 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 settled
|
mkdir fragment/settled
|
||||||
mkdir unsettled
|
mkdir fragment/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
|
||||||
mv settled page/.
|
mkdir page/settled
|
||||||
mv unsettled page/.
|
mkdir page/unsettled
|
||||||
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 "./utils.rkt" list->csv resource-link atom-table-entry add-atom-entry
|
(only-in "./tool/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 (equal? r-type "root")
|
(if (eq? 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 #:print-mode? (is-print #f))
|
(define (write-to-file out-port new-content old-content accumulator)
|
||||||
(let ([rb-thunks (cons (thunk (write-to-file-with-retries out-port old-content is-print))
|
(let ([rb-thunks (cons (thunk (write-to-file-with-retries out-port old-content))
|
||||||
(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)
|
||||||
((if is-print print display) new-content out-port)
|
(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 is-print)
|
(define (write-to-file-with-retries out-port content)
|
||||||
(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 is-print))])
|
(write-to-file-with-retries out-port content))])
|
||||||
(write-to-file out-port content #:print-mode? is-print)))
|
(write-to-file out-port content)))
|
||||||
;; ------------
|
;; ------------
|
||||||
|
|
||||||
;; 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 #:print-mode? #t)
|
old-content accumulator)
|
||||||
'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 update-time))])
|
(atom-table-entry l-head res-link desc publish-time update-time))])
|
||||||
(hash-remove
|
(hash-remove
|
||||||
(hash-remove
|
(hash-remove
|
||||||
(hash-update
|
(hash-update
|
||||||
|
@ -390,8 +390,13 @@
|
||||||
(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 #:modify-mode #t)
|
(archive-file n-in x-test)
|
||||||
|
|
||||||
(displayln "modify was successful")))))
|
(displayln "modify was successful")))))
|
||||||
|
|
||||||
(run modify)
|
;(run modify)
|
||||||
|
|
||||||
|
(run modify #("-i" "in-progress/now.txt"
|
||||||
|
"-l" "now"
|
||||||
|
"-r" "root"
|
||||||
|
"-x"))
|
43
publish.rkt
43
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 "./utils.rkt" homepage list->csv add-atom-entry atom-table-entry make-feed archive-file)
|
(only-in "./tool/utils.rkt" homepage list->csv add-atom-entry archive-file)
|
||||||
csv-reading)
|
csv-reading)
|
||||||
|
|
||||||
(define-namespace-anchor anc)
|
(define-namespace-anchor anc)
|
||||||
|
@ -254,7 +254,6 @@
|
||||||
|
|
||||||
|
|
||||||
;; 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))
|
||||||
|
@ -264,11 +263,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)
|
||||||
|
@ -283,23 +282,19 @@
|
||||||
'())))
|
'())))
|
||||||
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
|
||||||
(print resource out)
|
(write 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
|
||||||
(if (equal? r "root")
|
(write-new-resource/index r new-res-table #:test (if x #t #f))
|
||||||
(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
|
||||||
|
@ -309,29 +304,31 @@
|
||||||
(build-path "data" "atom"))
|
(build-path "data" "atom"))
|
||||||
#".csv"))))
|
#".csv"))))
|
||||||
(define new-atom-table
|
(define new-atom-table
|
||||||
(add-atom-entry atom-table (atom-table-entry l (~a res-link) d publish-time)))
|
(add-atom-entry atom-table (list 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
|
||||||
(displayln "updating feed")
|
(define feed ((eval (read (open-input-file (if x
|
||||||
|
"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 'replace ))
|
#:exists (if x 'replace 'error)))
|
||||||
(if (port-try-file-lock? feed-out 'exclusive)
|
(if (port-try-file-lock? feed-out 'exclusive)
|
||||||
(begin
|
(begin
|
||||||
(display
|
(display
|
||||||
(make-feed ns (open-input-file
|
(string-append "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
||||||
(if x
|
(xexpr->string feed))
|
||||||
"publish-test/data/make-atom.txt"
|
feed-out)
|
||||||
"data/make-atom.txt"))
|
|
||||||
new-atom-table
|
|
||||||
publish-time)
|
|
||||||
feed-out)
|
|
||||||
(port-file-unlock feed-out)
|
(port-file-unlock feed-out)
|
||||||
(close-output-port feed-out))
|
(close-output-port feed-out))
|
||||||
(error "couldn't obtain file lock on ~a" feed-out))
|
(error "couldn't obtain file lock on ~a" feed-out))
|
||||||
|
|
59
utils.rkt
59
utils.rkt
|
@ -1,59 +0,0 @@
|
||||||
#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