about summary refs log tree commit diff stats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/addhead.sh4
-rw-r--r--scripts/compile.sh85
-rw-r--r--scripts/delink.hs8
-rw-r--r--scripts/forceascii.hs17
-rw-r--r--scripts/hapax.lua252
-rw-r--r--scripts/hylo.js21
-rw-r--r--scripts/randomize.js27
-rw-r--r--scripts/versify.hs15
8 files changed, 429 insertions, 0 deletions
diff --git a/scripts/addhead.sh b/scripts/addhead.sh new file mode 100644 index 0000000..73e1dcf --- /dev/null +++ b/scripts/addhead.sh
@@ -0,0 +1,4 @@
1#!/bin/bash
2# addhead.sh <file> <header>
3
4
diff --git a/scripts/compile.sh b/scripts/compile.sh new file mode 100644 index 0000000..5478410 --- /dev/null +++ b/scripts/compile.sh
@@ -0,0 +1,85 @@
1#!/bin/bash
2# vim: fdm=marker
3
4getMeta() { # getMeta <metafield> <file> #{{{
5 local field="$1" file="$2";
6 sed -n '/^---$/,/^\.\.\.$/p' $file | \
7 grep "^${field}:" | \
8 cut -d' ' -f2- \
9 || return 1;
10} #}}}
11firstLineOf() { # firstLineOf <file> #{{{
12 local endOfYaml=$(sed -n '/^\.\.\.$/=' "$1")
13 local tryLine="" tryNum=$((endOfYaml + 1))
14 while [[ -z $tryLine ]]; do
15 tryLine=$(sed -n -e "${tryNum}p" "$1" | \
16 sed -e 's/^[|>] //' \
17 -e 's/[][]//g' \
18 -e 's/^#.*//' \
19 -e 's/^--.*//');
20 (( tryNum ++ ));
21 done
22 echo "$tryLine";
23} #}}}
24backLinksOf() { # backLinksOf <file> <in files> #{{{
25 local search="${1}"; shift; local glob="$@";
26 grep -ql "$search" $glob || return 1;
27} #}}}
28
29FILE="$1"; shift;
30case "$FILE" in
31 *.back) # backlinks: compile.sh a.back a.txt #{{{
32 found=( $(backLinksOf "$(basename ${FILE%.*}).html" ${1%/*}/*.${1##*.}) );
33 if [[ $? -ne 0 ]]; then
34 echo "__ISLAND__"; exit;
35 fi
36 for f in "${found[@]}"; do
37 echo -n "- [$(getMeta title "$f")](../$(basename ${f%.*}).html)";
38 echo -n '<span class="daisy">'
39 echo -n "[&phi;]($(basename ${f%.*}).html)";
40 echo '</span>'
41 done
42 ;; #}}}
43 *island*) # islands: compile.sh islands.txt *.txt #{{{
44 for f in $(grep -l "__ISLAND__" "$@"); do
45 echo "- [$(getMeta title "$f")]($(basename ${f%.*}).html)";
46 done
47 ;; #}}}
48 *hapax*) # hapax: compile.sh hapax.txt *.hapax #{{{
49 for word in $(sort $FILE); do
50 f=$(grep -liwq "^$word$" "$@");
51 grep -qv "^[^0-9A-Za-z]" <<< $word && \
52 echo "[$word]($(basename ${f%.*}).html)";
53 done
54 ;; #}}}
55 *first-*) # first-lines: compile.sh first-lines.txt *.txt #{{{
56 for f in "$@"; do
57 echo "[$(firstLineOf "$f")]($(basename ${f%.*}).html)";
58 done
59 ;; #}}}
60 *common-*) # common-titles: compile.sh common-titles.txt *.txt #{{{
61 for f in "$@"; do
62 echo "[$(getMeta title "$f")]($(basename ${f%.*}).html)";
63 done
64 ;; #}}}
65 *toc*) # table of contents: compile.sh toc.txt *.txt #{{{
66 for f in "$@"; do
67 echo "#. [$(getMeta toc "$f")]($(basename ${f%.*}).html)" >> $FILE;
68 done
69 ;; #}}}
70 *random*) # randomize.js: compile.sh randomize.js *.html #{{{
71 rlist=$(echo "$@" | sed -e 's/\(\S\+.html\) \?/"\1",/g' \
72 -e 's/^\(.*\),$/var files=[\1]/')
73 sed -i "s/var files=.*/$rlist/" $FILE;
74 ;; #}}}
75 --fix-head) # fix backlink head: compile.sh --fix-head a.back a.txt #{{{
76 title="$(getMeta title "$2")";
77 id="$(getMeta id "$2")";
78 sed -i "s/__TITLE__/$title/" "$1";
79 sed -i "s/__ID__/$id/" "$1";
80 ;; #}}}
81 *) # bad argument {{{
82 echo "Bad argument";
83 exit 1;
84 ;; #}}}
85esac
diff --git a/scripts/delink.hs b/scripts/delink.hs new file mode 100644 index 0000000..735e829 --- /dev/null +++ b/scripts/delink.hs
@@ -0,0 +1,8 @@
1#!/usr/bin/env runhaskell
2import Text.Pandoc.JSON
3
4main = toJSONFilter delink
5
6delink :: Inline -> [Inline]
7delink (Link txt _) = txt
8delink x = [x]
diff --git a/scripts/forceascii.hs b/scripts/forceascii.hs new file mode 100644 index 0000000..b5f1645 --- /dev/null +++ b/scripts/forceascii.hs
@@ -0,0 +1,17 @@
1-- Preprocessor for hapax.lua writer
2-- because for some damn reason, UTF-8 confuses things
3
4import Text.Pandoc.JSON
5import Data.Char (isAscii)
6
7main :: IO ()
8main = toJSONFilter unFancy
9
10unFancy :: Inline -> Inline
11unFancy (Str s) = Str $ map makeAscii s
12unFancy x = x
13
14makeAscii :: Char -> Char
15makeAscii c
16 | isAscii c = c
17 | otherwise = ' '
diff --git a/scripts/hapax.lua b/scripts/hapax.lua new file mode 100644 index 0000000..1cabbaa --- /dev/null +++ b/scripts/hapax.lua
@@ -0,0 +1,252 @@
1-- Pandoc Hapax writer
2-- it takes out all formatting, leaving only a river of text
3-- running down the page: one word per line, stripping all duplicates
4-- vim: fdm=marker
5-- invoke with: pandoc -t hapax.lua
6
7os.setlocale("en_US.UTF-8")
8
9function hapax(s)
10 local function tablify (s, p)
11 local t={}
12 for w in s:gmatch(p) do
13 table.insert(t, w)
14 end
15 return t
16 end
17 local function stripDupes (t)
18 local seen = {}
19 local remove = {}
20 for i = 1, #t do
21 element = t[i]
22 if seen[element] then
23 remove[element] = true
24 else
25 seen[element] = true
26 end
27 end
28 for i = #t, 1, -1 do
29 if remove[t[i]] then
30 table.remove(t, i)
31 end
32 end
33 return t
34 end
35 return table.concat(stripDupes(tablify(s, "%S+")), "\n")
36end
37
38function flow(s)
39 return s:gsub("%s+", "\n")
40end
41
42function nude(s)
43 s = s:lower()
44 -- Expand contractions
45 s = s:gsub("'ll", " will ")
46 s = s:gsub("'ve", " have ")
47 s = s:gsub("'re", " are ")
48 s = s:gsub("i'm", " i am ")
49 s = s:gsub("it's", "it is")
50 s = s:gsub("n't", " not ")
51 s = s:gsub("'d", " would ") -- can be "had", but still no hapax
52 s = s:gsub("&", " and ")
53 -- -- Remove dashes (not hyphens)
54 s = s:gsub('%-[%-%s]+', ' ')
55 -- Remove everything that is not letters or numbers
56 s = s:gsub('[^A-Za-z0-9/\'-]', ' ')
57 -- Remove extra spaces
58 s = s:gsub('%s+', ' ')
59 return " "..s.." "
60end
61
62-- This function is called once for the whole document. Parameters:
63-- body is a string, metadata is a table, variables is a table.
64-- One could use some kind of templating
65-- system here; this just gives you a simple standalone HTML file.
66function Doc(body, metadata, variables)
67 local buffer = ""
68 local function add(s)
69 buffer = buffer .. nude(s) .. "\n"
70 end
71 if metadata['title'] then
72 add(metadata['title'])
73 end
74 if metadata['subtitle'] then
75 add(metadata['subtitle'])
76 end
77 add(body)
78 return hapax(flow(buffer))
79 -- return flow(buffer)
80end
81
82-- Remove all formatting {{{
83function Note(s)
84 return s
85end
86
87function Blocksep()
88 return "\n"
89end
90function Emph(s)
91 return s
92end
93
94function Strong(s)
95 return s
96end
97
98function Subscript(s)
99 return s
100end
101
102function Superscript(s)
103 return s
104end
105
106function SmallCaps(s)
107 return s
108end
109
110function Strikeout(s)
111 return s
112end
113
114function Code(s, attr)
115 return s
116end
117
118function CodeBlock(s, attr)
119 return s
120end
121
122function InlineMath(s)
123 return s
124end
125
126function DisplayMath(s)
127 return s
128end
129
130function Span(s, attr)
131 return s
132end
133
134function Cite(s)
135 return s
136end
137
138function Plain(s)
139 return s
140end
141
142-- Links only include the link text
143function Link(s, src, tit)
144 return s
145end
146
147-- Images have nothing to give us
148-- (but add a space just in case)
149function Image(s, src, tit)
150 return "\n"
151end
152
153function RawBlock(s)
154 return s
155end
156
157function RawInline(s)
158 return s
159end
160
161function CaptionedImage(s, src, tit)
162 return "\n"
163end
164
165function Str(s)
166 return s
167end
168
169function Div(s, attr)
170 return s
171end
172
173function Space(s)
174 return "\n"
175end
176
177function LineBreak()
178 return "\n"
179end
180
181function Para(s)
182 return s
183end
184
185function Header(lev, s, attr)
186 return s
187end
188
189function BlockQuote(s)
190 return s
191end
192
193function HorizontalRule()
194 return "\n"
195end
196
197function BulletList(items)
198 local buffer = ""
199 for _, item in pairs(items) do
200 buffer = buffer .. " " .. item .. "\n"
201 end
202 return buffer .. "\n"
203end
204
205function OrderedList(items)
206 local buffer = ""
207 for _, item in pairs(items) do
208 buffer = buffer .. " " .. item .. "\n"
209 end
210 return buffer .. "\n"
211end
212
213function DefinitionList(items)
214 local buffer = ""
215 for _, item in pairs(items) do
216 for k, v in pairs(item) do
217 buffer = buffer .. " " .. k .. "\n" .. v .. "\n"
218 end
219 end
220 return buffer .. "\n"
221end
222
223function Table(caption, aligns, widths, headers, rows)
224 local buffer = ""
225 local function add(s)
226 buffer = buffer .. " " .. s .. "\n"
227 end
228 if caption ~= "" then
229 add(caption)
230 end
231 for _,h in pairs(headers) do
232 add(h)
233 end
234 for _, row in pairs(rows) do
235 for _, cell in pairs(row) do
236 add(cell)
237 end
238 end
239 return buffer
240end
241-- }}}
242
243-- The following code will produce runtime warnings when you haven't defined
244-- all of the functions you need for the custom writer, so it's useful
245-- to include when you're working on a writer.
246local meta = {}
247meta.__index =
248 function(_, key)
249 io.stderr:write(string.format("WARNING: Undefined function '%s'\n",key))
250 return function() return "" end
251 end
252setmetatable(_G, meta)
diff --git a/scripts/hylo.js b/scripts/hylo.js new file mode 100644 index 0000000..5a39427 --- /dev/null +++ b/scripts/hylo.js
@@ -0,0 +1,21 @@
1/*
2 * Hyphenator_Loader 1.1.0 - client side hyphenation for webbrowsers
3 * Copyright (C) 2014 Mathias Nater, Zürich (mathias at mnn dot ch)
4 * Project and Source hosted on http://code.google.com/p/hyphenator/
5 *
6 * This JavaScript code is free software: you can redistribute
7 * it and/or modify it under the terms of the GNU Lesser
8 * General Public License (GNU LGPL) as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option)
10 * any later version. The code is distributed WITHOUT ANY WARRANTY;
11 * without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
13 *
14 * As additional permission under GNU GPL version 3 section 7, you
15 * may distribute non-source (e.g., minimized or compacted) forms of
16 * that code without the copy of the GNU GPL normally required by
17 * section 4, provided you include this license notice and a URL
18 * through which recipients can access the Corresponding Source.
19 */
20
21var Hyphenator_Loader=(function(window){'use strict';var languages,config,path,createElem=function(tagname){var r;if(window.document.createElementNS){r=window.document.createElementNS('http://www.w3.org/1999/xhtml',tagname);}else if(window.document.createElement){r=window.document.createElement(tagname);}return r;},checkLangSupport=function(lang,longword){var shadow,computedHeight,bdy=window.document.getElementsByTagName('body')[0];shadow=createElem('div');shadow.style.width='5em';shadow.style.MozHyphens='auto';shadow.style['-webkit-hyphens']='auto';shadow.style['-ms-hyphens']='auto';shadow.style.hyphens='auto';shadow.style.fontSize='12px';shadow.style.lineHeight='12px';shadow.style.visibility='hidden';shadow.lang=lang;shadow.style['-webkit-locale']="'"+lang+"'";shadow.innerHTML=longword;bdy.appendChild(shadow);computedHeight=shadow.offsetHeight;bdy.removeChild(shadow);return(computedHeight>12)?true:false;},loadNrunHyphenator=function(config){var head,script,interval;head=window.document.getElementsByTagName('head').item(0);script=createElem('script');script.src=path;script.type='text/javascript';head.appendChild(script);interval=window.setInterval(function(){if(window.Hyphenator!==undefined){window.clearInterval(interval);Hyphenator.config(config);Hyphenator.run();}},10);},runner=function(){var loadHyphenator=false,r,results={},lang;for(lang in languages){if(languages.hasOwnProperty(lang)){r=checkLangSupport(lang,languages[lang]);results[lang]=r;loadHyphenator=loadHyphenator||!r;}}if(loadHyphenator){loadNrunHyphenator(config);}},runOnContentLoaded=function(window,f){var toplevel,hyphRunForThis={},doFrames=false,contextWindow,documentLoaded,add=window.document.addEventListener?'addEventListener':'attachEvent',rem=window.document.addEventListener?'removeEventListener':'detachEvent',pre=window.document.addEventListener?'':'on',init=function(context){contextWindow=context||window;if(!hyphRunForThis[contextWindow.location.href]&&(!documentLoaded||!!contextWindow.frameElement)){documentLoaded=true;f();hyphRunForThis[contextWindow.location.href]=true;}},doScrollCheck=function(){try{window.document.documentElement.doScroll("left");}catch(error){window.setTimeout(doScrollCheck,1);return;}init(window);},doOnLoad=function(){var i,haveAccess,fl=window.frames.length;if(doFrames&&fl>0){for(i=0;i<fl;i+=1){haveAccess=undefined;try{haveAccess=window.frames[i].document.toString();}catch(e){haveAccess=undefined;}if(!!haveAccess){if(window.frames[i].location.href!=='about:blank'){init(window.frames[i]);}}}contextWindow=window;f();hyphRunForThis[window.location.href]=true;}else{init(window);}},DOMContentLoaded=function(e){if(e.type==='readystatechange'&&window.document.readyState!=='complete'){return;}window.document[rem](pre+e.type,DOMContentLoaded,false);if(!doFrames&&window.frames.length===0){init(window);}};if(window.document.readyState==="complete"||window.document.readyState==="interactive"){window.setTimeout(doOnLoad,1);}else{window.document[add](pre+"DOMContentLoaded",DOMContentLoaded,false);window.document[add](pre+'readystatechange',DOMContentLoaded,false);window[add](pre+'load',doOnLoad,false);toplevel=false;try{toplevel=!window.frameElement;}catch(ignore){}if(window.document.documentElement.doScroll&&toplevel){doScrollCheck();}}};return{init:function(langs,p,configs){languages=langs;path=p;config=configs||{};runOnContentLoaded(window,runner);}};}(window));Hyphenator_Loader.init({"en":"hyphenationalgorithm",},"./Hyphenator.js",{classname:'prose',defaultlanguage:'en',displaytogglebox:true,togglebox:function(){var bdy,myTextNode,text=(Hyphenator.doHyphenation?'-':'~'),myBox=contextWindow.document.getElementById('HyphenatorToggleBox');if(!!myBox){myBox.firstChild.data=text;}else{bdy=contextWindow.document.getElementsByTagName('body')[0];myBox=createElem('div',contextWindow);myBox.setAttribute('id','HyphenatorToggleBox');myBox.setAttribute('class',dontHyphenateClass);myTextNode=contextWindow.document.createTextNode(text);myBox.appendChild(myTextNode);myBox.onclick=Hyphenator.toggleHyphenation;myBox.style.position='absolute';myBox.style.top='0px';myBox.style.right='0px';myBox.style.margin='0';myBox.style.backgroundColor=rgba(0,0,0,255);myBox.style.color=rgba(255,255,255,100);myBox.style.font='6pt Arial';myBox.style.letterSpacing='0.2em';myBox.style.padding='3px';myBox.style.cursor='pointer';myBox.style.WebkitBorderBottomLeftRadius='4px';myBox.style.MozBorderRadiusBottomleft='4px';myBox.style.borderBottomLeftRadius='4px';bdy.appendChild(myBox);}},useCSS3hyphenation:true});
diff --git a/scripts/randomize.js b/scripts/randomize.js new file mode 100644 index 0000000..b225b2f --- /dev/null +++ b/scripts/randomize.js
@@ -0,0 +1,27 @@
1/* Lozenge.js for Autocento of the breakfast table
2 * Cause a#lozenge to link to random file in array
3 * vim: fdm=marker
4 */
5
6function _randomize() {
7 var randomlink = document.getElementById('randomizelink');
8 // array with all files {{{
9 var files=["about-the-author.html","about.html","about_author.html","abstract.html","amber-alert.html","and.html","angeltoabraham.html","apollo11.html","arspoetica.html","art.html","axe.html","big-dipper.html","boar.html","boy_bus.html","building.html","call-me-aural-pleasure.html","cereal.html","cold-wind.html","collage-instrument.html","creation-myth.html","deadman.html","death-zone.html","deathstrumpet.html","dollywood.html","dream.html","early.html","elegyforanalternateself.html","epigraph.html","ex-machina.html","exasperated.html","father.html","feedingtheraven.html","finding-the-lion.html","fire.html","found-typewriter-poem.html","hands.html","hard-game.html","hardware.html","howithappened.html","howtoread.html","hymnal.html","i-am.html","i-think-its-you.html","i-want-to-say.html","i-wanted-to-tell-you-something.html","in-bed.html","initial-conditions.html","january.html","joke.html","lappel-du-vide.html","largest-asteroid.html","last-bastion.html","last-passenger.html","leaf.html","leg.html","likingthings.html","listen.html","love-as-god.html","lovesong.html","man.html","manifesto_poetics.html","moon-drowning.html","moongone.html","mountain.html","movingsideways.html","music-433.html","no-nothing.html","notes.html","nothing-is-ever-over.html","on-genre-dimension.html","one-hundred-lines.html","onformalpoetry.html","options.html","ouroboros_memory.html","paul.html","peaches.html","philosophy.html","phone.html","planks.html","plant.html","poetry-time.html","prelude.html","problems.html","process.html","proverbs.html","punch.html","purpose-dogs.html","question.html","real-writer.html","reports.html","riptide_memory.html","ronaldmcdonald.html","roughgloves.html","sapling.html","seasonal-affective-disorder.html","sense-of-it.html","serengeti.html","shed.html","shipwright.html","sixteenth-chapel.html","snow.html","something-simple.html","spittle.html","squirrel.html","stagnant.html","statements-frag.html","stayed-on-the-bus.html","stump.html","swansong-alt.html","swansong.html","swear.html","table_contents.html","tapestry.html","telemarketer.html","the-night-we-met.html","the-sea_the-beach.html","theoceanoverflowswithcamels.html","time-looks-up-to-the-sky.html","todaniel.html","toilet.html","toothpaste.html","treatise.html","underwear.html","walking-in-the-rain.html","wallpaper.html","weplayedthosegamestoo.html","what-we-are-made-of.html","when-im-sorry-i.html","window.html","words-irritable-reaching.html","words-meaning.html","worse-looking-over.html","writing.html","x-ray.html","yellow.html"]
10 // }}}
11
12 var index = Math.floor(Math.random() * files.length);
13
14 var url = window.location.pathname;
15 var current = url.substring(url.lastIndexOf('/')+1);
16
17 if (current != files[index]) {
18 randomlink.setAttribute("href", files[index]);
19 randomlink.setAttribute("title", "To random article");
20 } else {
21 _randomize()
22 }
23}
24
25window.onload = function () {
26 _randomize()
27};
diff --git a/scripts/versify.hs b/scripts/versify.hs new file mode 100644 index 0000000..48e9c00 --- /dev/null +++ b/scripts/versify.hs
@@ -0,0 +1,15 @@
1import Text.Pandoc.JSON
2import Data.List.Split
3
4main :: IO ()
5main = toJSONFilter transformVerseParas
6
7transformVerseParas :: Block -> Block
8transformVerseParas (Para xs)
9 | LineBreak `elem` xs = Para (addLineSpans xs)
10 | otherwise = Para xs
11transformVerseParas x = x
12
13addLineSpans :: [Inline] -> [Inline]
14addLineSpans = map encloseInSpan . splitWhen (== LineBreak)
15 where encloseInSpan = Span ("", ["line"], [])