start actually documenting things and config
This commit is contained in:
parent
538284a649
commit
3683beb0b3
84
generate.fnl
84
generate.fnl
|
@ -4,34 +4,58 @@
|
|||
(global pp (fn [x]
|
||||
(print (fennel.view x))))
|
||||
|
||||
; config variables
|
||||
;;; Configuration. You will need to modify these for your site.
|
||||
|
||||
;; Directories
|
||||
|
||||
; URL of your site over the gemini protocol.
|
||||
(var gemini-baseurl "gemini://tilde.town/~nihilazo")
|
||||
; URL of your site over the HTTP protocol (on the web).
|
||||
(var html-baseurl "https://itwont.work")
|
||||
; the directory generated gemini files will be saved to.
|
||||
(var gemini-outdir "public_gemini")
|
||||
; the directory generated HTML files will be saved to.
|
||||
(var html-outdir "public_html")
|
||||
; the directory that your input content is stored in.
|
||||
(var content-dir "content")
|
||||
;; TODO header/footer files instead of variables?
|
||||
|
||||
;; Headers and footers
|
||||
|
||||
;; Headers and footers are are added in this order:
|
||||
;; <header>
|
||||
;; <blog-header> (on the blog index page)
|
||||
;; <page content>
|
||||
;; <footer>
|
||||
|
||||
; header of the blog index page on gemini
|
||||
(var gemini-blog-header "# lipu pi jan Niko\n\n")
|
||||
; footer added to all gemini output
|
||||
(var gemini-footer "\n=> gemini://tilde.town/~nihilazo Go Home\n")
|
||||
; header added to the blog index page on the web
|
||||
(var html-blog-header "<h1>lipu pi jan Niko</h1>\n\n")
|
||||
; header added to all pages on the web
|
||||
(var html-header "<!DOCTYPE html><head><link rel=stylesheet href='https://itwont.work/style.css'><title>lipu pi jan Niko</title><body><article>")
|
||||
; footer added to all pages on the web
|
||||
(var html-footer "</article><footer>
|
||||
<a href=https://itwont.work>Go Home</a><br>
|
||||
<a href='https://webring.xxiivv.com/#random' target='_blank'><img id='webring' src='https://webring.xxiivv.com/icon.white.svg'/></a></footer></body>")
|
||||
(var ass-feed-header "# Actually Simple Syndication - https://tilde.town/~dzwdz/ass/\n" )
|
||||
|
||||
;; Header of the RSS feed. Here you should set your site title (in between the <title> and </title> tags) and name (in between the <name> and </name> tags).
|
||||
(var rss-feed-header "<?xml version=\"1.0\" encoding=\"utf-8\"?>
|
||||
<feed xmlns=\"http://www.w3.org/2005/Atom\">
|
||||
<title>lipu pi jan Niko</title>
|
||||
<author><name>jan Niko</name></author>\n")
|
||||
|
||||
;; END OF CONFIG SECTION
|
||||
|
||||
; working variables
|
||||
(var dirs [])
|
||||
(var files [])
|
||||
(var posts [])
|
||||
|
||||
; converts a gemini link line to a html link line, with the correct changes to function
|
||||
|
||||
(fn html-link [line]
|
||||
"converts a gemini link line to an html link line, with file extension and protocol link changes if required"
|
||||
(var url "")
|
||||
(let [(u name) (line:match "=> ([^%s]+) (.+)")] ; get the url and name
|
||||
(set url u) ; if the link isn't an offsite gemini link, change .gmi extensions to .html
|
||||
|
@ -42,8 +66,8 @@
|
|||
(string.format "<a href=\"%s%s\">%s</a><br>\n" html-baseurl url name)
|
||||
(string.format "<a href=\"%s\">%s</a><br>\n" url name))))
|
||||
|
||||
; generates log roll page for gemini
|
||||
(fn generate-gemini-log []
|
||||
"generates the gemini blog index page"
|
||||
(var gemini-index gemini-blog-header)
|
||||
(each [_ p (ipairs posts)]
|
||||
(let [{: date : title : path} p
|
||||
|
@ -55,8 +79,8 @@
|
|||
(f:write gemini-index)
|
||||
(f:close)))
|
||||
|
||||
; generate rss/atom feeds
|
||||
(fn generate-rss-feeds []
|
||||
"generates rss/atom feeds"
|
||||
(var gemini-rss-feed (.. rss-feed-header "<id>" gemini-baseurl "</id>\n"))
|
||||
(var html-rss-feed (.. rss-feed-header "<id>" html-baseurl "</id>\n"))
|
||||
; add last updated info to rss feeds
|
||||
|
@ -86,27 +110,28 @@
|
|||
(f:write html-rss-feed)
|
||||
(f:close)))
|
||||
|
||||
; generate ass (https://tilde.town/~dzwdz/ass) feeds
|
||||
(fn generate-ass-feeds []
|
||||
(var gemini-ass-feed ass-feed-header)
|
||||
(var html-ass-feed ass-feed-header)
|
||||
; add posts to ass feeds
|
||||
(each [_ p (ipairs posts)]
|
||||
(let [ {: date : title : path} p]
|
||||
(set html-ass-feed (.. html-ass-feed
|
||||
(string.format "%s\t%s%s\t%s\n" date html-baseurl (path:gsub ".gmi" ".html") title)))
|
||||
(set gemini-ass-feed (.. gemini-ass-feed
|
||||
(string.format "%s\t%s%s\t%s\n" date gemini-baseurl path title)))))
|
||||
"generates ass (https://tilde.town/~dzwdz/ass) feeds"
|
||||
(let [header "# Actually Simple Syndication - https://tilde.town/~dzwdz/ass/\n"]
|
||||
(var gemini-ass-feed header)
|
||||
(var html-ass-feed header)
|
||||
; add posts to ass feeds
|
||||
(each [_ p (ipairs posts)]
|
||||
(let [ {: date : title : path} p]
|
||||
(set html-ass-feed (.. html-ass-feed
|
||||
(string.format "%s\t%s%s\t%s\n" date html-baseurl (path:gsub ".gmi" ".html") title)))
|
||||
(set gemini-ass-feed (.. gemini-ass-feed
|
||||
(string.format "%s\t%s%s\t%s\n" date gemini-baseurl path title)))))
|
||||
; write out ass feeds
|
||||
(let [f (io.open (.. gemini-outdir "/feed.ass") :w+)]
|
||||
(f:write gemini-ass-feed)
|
||||
(f:close))
|
||||
(let [f (io.open (.. html-outdir "/feed.ass") :w+)]
|
||||
(f:write html-ass-feed)
|
||||
(f:close)))
|
||||
(f:close))))
|
||||
|
||||
; generates log roll page for html
|
||||
(fn generate-html-log []
|
||||
"generates the blog index page for HTML"
|
||||
(var html-index (.. html-header html-blog-header :<ul>))
|
||||
(each [_ p (ipairs posts)]
|
||||
(let [{: date : title : path} p
|
||||
|
@ -120,8 +145,8 @@
|
|||
(f:write html-index)
|
||||
(f:close)))
|
||||
|
||||
; generate-log generates the log pages and feeds from the posts index
|
||||
(fn generate-logs []
|
||||
"generates the log index pages and feeds from the posts index"
|
||||
(table.sort posts (fn [a b]
|
||||
(> (. a :date) (. b :date))))
|
||||
(generate-gemini-log)
|
||||
|
@ -130,7 +155,8 @@
|
|||
(generate-rss-feeds))
|
||||
|
||||
; index-post adds a log post to the post index
|
||||
(fn index-post [f]
|
||||
(fn index-post [f]
|
||||
"adds a log post from the file f to the post index"
|
||||
(io.input (.. content-dir f)) ; open file
|
||||
(let [post {}]
|
||||
(tset post :path f)
|
||||
|
@ -142,9 +168,9 @@
|
|||
(tset post :date date))
|
||||
(table.insert posts post))
|
||||
(io.close))
|
||||
|
||||
; HTML-escapes and trims a string
|
||||
|
||||
(fn html-clean [l]
|
||||
"trims and escapes a string for inclusion in HTML"
|
||||
(let [s (l:match "%s*(.+)%s*")]
|
||||
(-> s
|
||||
(string.gsub "&" "&")
|
||||
|
@ -163,6 +189,7 @@
|
|||
; true if we are in a list, false otherwise
|
||||
(var blockquoting false)
|
||||
(fn to-html [line]
|
||||
"converts a line of gemtext to a line of HTML"
|
||||
(var prefix "")
|
||||
(if (and listing (not (line:match "^%*%s")))
|
||||
(do
|
||||
|
@ -209,6 +236,7 @@
|
|||
|
||||
; processes, converts, and writes out an input gemini page in html
|
||||
(fn process-html-page [f]
|
||||
"processes, converts, and writes out the input page f in html"
|
||||
(let [infile (.. content-dir f)
|
||||
outfile (io.open (.. html-outdir (string.gsub f "%.gmi" ".html")) :w+)]
|
||||
(outfile:write html-header)
|
||||
|
@ -221,6 +249,7 @@
|
|||
|
||||
; processes and writes out an input gemini page into an output one
|
||||
(fn process-gemini-page [f]
|
||||
"processes and writes out the input page f for the gemini protocol"
|
||||
(let [infile (.. content-dir f)
|
||||
outfile (io.open (.. gemini-outdir f) :w+)]
|
||||
(each [l (io.lines infile)]
|
||||
|
@ -235,8 +264,8 @@
|
|||
(outfile:write gemini-footer)
|
||||
(outfile:close)))
|
||||
|
||||
; process-file runs for every input file to process t
|
||||
(fn process-file [f]
|
||||
"runs for every input file to process it"
|
||||
(if (string.match f ".+log/.+%.gmi")
|
||||
(do
|
||||
(index-post f)
|
||||
|
@ -254,12 +283,12 @@
|
|||
|
||||
; process-dir is run for every input directory to copy the tree into output directories
|
||||
(fn process-dir [f]
|
||||
"run for every input directory to re-create the directory structure in the output"
|
||||
(lfs.mkdir (.. gemini-outdir f))
|
||||
(lfs.mkdir (.. html-outdir f)))
|
||||
|
||||
; walk the input directory tree recursively, processing every file and directory using the process-file and process-dir functions. "base" is the directory that is being walked. "position" is the current position in the directory tree.
|
||||
|
||||
(fn walk [base position] ; for each file in the current directory
|
||||
"walks through the input directory tree and populate the `files` and `dirs` tables for future processing"
|
||||
(each [file (lfs.dir (.. base position))]
|
||||
(let [fullpath (.. base position "/" file)]
|
||||
(let [{:mode filemode} (lfs.attributes fullpath)] ; get the mode (file or directory)
|
||||
|
@ -272,12 +301,15 @@
|
|||
(= filemode :file) ; process the file
|
||||
(table.insert files (.. position "/" file))))))))
|
||||
|
||||
; do everything
|
||||
|
||||
; main section
|
||||
; recreate output dirs
|
||||
(os.execute (.. "rm -rf " gemini-outdir))
|
||||
(os.execute (.. "rm -rf " html-outdir))
|
||||
(lfs.mkdir gemini-outdir)
|
||||
(lfs.mkdir html-outdir)
|
||||
|
||||
; walk and process files
|
||||
(print "getting files")
|
||||
(walk content-dir "")
|
||||
|
||||
|
|
Reference in New Issue