From 9fce418b46c9f0894f429384ef9e3dabaeffbeb4 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 14 Apr 2015 16:36:17 -0700 Subject: Change file hierarchy and rewrite makefile - File hierarchy is now as follows: - / - appendix/ < appendix source files - backlinks/ < backlink sources & builds - hapax/ < *.hapax source files - scripts/ < scripts, like *.js, *.hs, etc. - templates/ < templates for outputs - text/ < source files - trunk/ < assets, like css, images, heads, etc. - index.html - *.html - Makefile --- scripts/addhead.sh | 4 + scripts/compile.sh | 85 +++++++++++++++++ scripts/delink.hs | 8 ++ scripts/forceascii.hs | 17 ++++ scripts/hapax.lua | 252 ++++++++++++++++++++++++++++++++++++++++++++++++++ scripts/hylo.js | 21 +++++ scripts/randomize.js | 27 ++++++ scripts/versify.hs | 15 +++ 8 files changed, 429 insertions(+) create mode 100644 scripts/addhead.sh create mode 100644 scripts/compile.sh create mode 100644 scripts/delink.hs create mode 100644 scripts/forceascii.hs create mode 100644 scripts/hapax.lua create mode 100644 scripts/hylo.js create mode 100644 scripts/randomize.js create mode 100644 scripts/versify.hs (limited to 'scripts') 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 @@ +#!/bin/bash +# addhead.sh
+ + 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 @@ +#!/bin/bash +# vim: fdm=marker + +getMeta() { # getMeta #{{{ + local field="$1" file="$2"; + sed -n '/^---$/,/^\.\.\.$/p' $file | \ + grep "^${field}:" | \ + cut -d' ' -f2- \ + || return 1; +} #}}} +firstLineOf() { # firstLineOf #{{{ + local endOfYaml=$(sed -n '/^\.\.\.$/=' "$1") + local tryLine="" tryNum=$((endOfYaml + 1)) + while [[ -z $tryLine ]]; do + tryLine=$(sed -n -e "${tryNum}p" "$1" | \ + sed -e 's/^[|>] //' \ + -e 's/[][]//g' \ + -e 's/^#.*//' \ + -e 's/^--.*//'); + (( tryNum ++ )); + done + echo "$tryLine"; +} #}}} +backLinksOf() { # backLinksOf #{{{ + local search="${1}"; shift; local glob="$@"; + grep -ql "$search" $glob || return 1; +} #}}} + +FILE="$1"; shift; +case "$FILE" in + *.back) # backlinks: compile.sh a.back a.txt #{{{ + found=( $(backLinksOf "$(basename ${FILE%.*}).html" ${1%/*}/*.${1##*.}) ); + if [[ $? -ne 0 ]]; then + echo "__ISLAND__"; exit; + fi + for f in "${found[@]}"; do + echo -n "- [$(getMeta title "$f")](../$(basename ${f%.*}).html)"; + echo -n '' + echo -n "[φ]($(basename ${f%.*}).html)"; + echo '' + done + ;; #}}} + *island*) # islands: compile.sh islands.txt *.txt #{{{ + for f in $(grep -l "__ISLAND__" "$@"); do + echo "- [$(getMeta title "$f")]($(basename ${f%.*}).html)"; + done + ;; #}}} + *hapax*) # hapax: compile.sh hapax.txt *.hapax #{{{ + for word in $(sort $FILE); do + f=$(grep -liwq "^$word$" "$@"); + grep -qv "^[^0-9A-Za-z]" <<< $word && \ + echo "[$word]($(basename ${f%.*}).html)"; + done + ;; #}}} + *first-*) # first-lines: compile.sh first-lines.txt *.txt #{{{ + for f in "$@"; do + echo "[$(firstLineOf "$f")]($(basename ${f%.*}).html)"; + done + ;; #}}} + *common-*) # common-titles: compile.sh common-titles.txt *.txt #{{{ + for f in "$@"; do + echo "[$(getMeta title "$f")]($(basename ${f%.*}).html)"; + done + ;; #}}} + *toc*) # table of contents: compile.sh toc.txt *.txt #{{{ + for f in "$@"; do + echo "#. [$(getMeta toc "$f")]($(basename ${f%.*}).html)" >> $FILE; + done + ;; #}}} + *random*) # randomize.js: compile.sh randomize.js *.html #{{{ + rlist=$(echo "$@" | sed -e 's/\(\S\+.html\) \?/"\1",/g' \ + -e 's/^\(.*\),$/var files=[\1]/') + sed -i "s/var files=.*/$rlist/" $FILE; + ;; #}}} + --fix-head) # fix backlink head: compile.sh --fix-head a.back a.txt #{{{ + title="$(getMeta title "$2")"; + id="$(getMeta id "$2")"; + sed -i "s/__TITLE__/$title/" "$1"; + sed -i "s/__ID__/$id/" "$1"; + ;; #}}} + *) # bad argument {{{ + echo "Bad argument"; + exit 1; + ;; #}}} +esac 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 @@ +#!/usr/bin/env runhaskell +import Text.Pandoc.JSON + +main = toJSONFilter delink + +delink :: Inline -> [Inline] +delink (Link txt _) = txt +delink 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 @@ +-- Preprocessor for hapax.lua writer +-- because for some damn reason, UTF-8 confuses things + +import Text.Pandoc.JSON +import Data.Char (isAscii) + +main :: IO () +main = toJSONFilter unFancy + +unFancy :: Inline -> Inline +unFancy (Str s) = Str $ map makeAscii s +unFancy x = x + +makeAscii :: Char -> Char +makeAscii c + | isAscii c = c + | 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 @@ +-- Pandoc Hapax writer +-- it takes out all formatting, leaving only a river of text +-- running down the page: one word per line, stripping all duplicates +-- vim: fdm=marker +-- invoke with: pandoc -t hapax.lua + +os.setlocale("en_US.UTF-8") + +function hapax(s) + local function tablify (s, p) + local t={} + for w in s:gmatch(p) do + table.insert(t, w) + end + return t + end + local function stripDupes (t) + local seen = {} + local remove = {} + for i = 1, #t do + element = t[i] + if seen[element] then + remove[element] = true + else + seen[element] = true + end + end + for i = #t, 1, -1 do + if remove[t[i]] then + table.remove(t, i) + end + end + return t + end + return table.concat(stripDupes(tablify(s, "%S+")), "\n") +end + +function flow(s) + return s:gsub("%s+", "\n") +end + +function nude(s) + s = s:lower() + -- Expand contractions + s = s:gsub("'ll", " will ") + s = s:gsub("'ve", " have ") + s = s:gsub("'re", " are ") + s = s:gsub("i'm", " i am ") + s = s:gsub("it's", "it is") + s = s:gsub("n't", " not ") + s = s:gsub("'d", " would ") -- can be "had", but still no hapax + s = s:gsub("&", " and ") + -- -- Remove dashes (not hyphens) + s = s:gsub('%-[%-%s]+', ' ') + -- Remove everything that is not letters or numbers + s = s:gsub('[^A-Za-z0-9/\'-]', ' ') + -- Remove extra spaces + s = s:gsub('%s+', ' ') + return " "..s.." " +end + +-- This function is called once for the whole document. Parameters: +-- body is a string, metadata is a table, variables is a table. +-- One could use some kind of templating +-- system here; this just gives you a simple standalone HTML file. +function Doc(body, metadata, variables) + local buffer = "" + local function add(s) + buffer = buffer .. nude(s) .. "\n" + end + if metadata['title'] then + add(metadata['title']) + end + if metadata['subtitle'] then + add(metadata['subtitle']) + end + add(body) + return hapax(flow(buffer)) + -- return flow(buffer) +end + +-- Remove all formatting {{{ +function Note(s) + return s +end + +function Blocksep() + return "\n" +end +function Emph(s) + return s +end + +function Strong(s) + return s +end + +function Subscript(s) + return s +end + +function Superscript(s) + return s +end + +function SmallCaps(s) + return s +end + +function Strikeout(s) + return s +end + +function Code(s, attr) + return s +end + +function CodeBlock(s, attr) + return s +end + +function InlineMath(s) + return s +end + +function DisplayMath(s) + return s +end + +function Span(s, attr) + return s +end + +function Cite(s) + return s +end + +function Plain(s) + return s +end + +-- Links only include the link text +function Link(s, src, tit) + return s +end + +-- Images have nothing to give us +-- (but add a space just in case) +function Image(s, src, tit) + return "\n" +end + +function RawBlock(s) + return s +end + +function RawInline(s) + return s +end + +function CaptionedImage(s, src, tit) + return "\n" +end + +function Str(s) + return s +end + +function Div(s, attr) + return s +end + +function Space(s) + return "\n" +end + +function LineBreak() + return "\n" +end + +function Para(s) + return s +end + +function Header(lev, s, attr) + return s +end + +function BlockQuote(s) + return s +end + +function HorizontalRule() + return "\n" +end + +function BulletList(items) + local buffer = "" + for _, item in pairs(items) do + buffer = buffer .. " " .. item .. "\n" + end + return buffer .. "\n" +end + +function OrderedList(items) + local buffer = "" + for _, item in pairs(items) do + buffer = buffer .. " " .. item .. "\n" + end + return buffer .. "\n" +end + +function DefinitionList(items) + local buffer = "" + for _, item in pairs(items) do + for k, v in pairs(item) do + buffer = buffer .. " " .. k .. "\n" .. v .. "\n" + end + end + return buffer .. "\n" +end + +function Table(caption, aligns, widths, headers, rows) + local buffer = "" + local function add(s) + buffer = buffer .. " " .. s .. "\n" + end + if caption ~= "" then + add(caption) + end + for _,h in pairs(headers) do + add(h) + end + for _, row in pairs(rows) do + for _, cell in pairs(row) do + add(cell) + end + end + return buffer +end +-- }}} + +-- The following code will produce runtime warnings when you haven't defined +-- all of the functions you need for the custom writer, so it's useful +-- to include when you're working on a writer. +local meta = {} +meta.__index = + function(_, key) + io.stderr:write(string.format("WARNING: Undefined function '%s'\n",key)) + return function() return "" end + end +setmetatable(_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 @@ +/* + * Hyphenator_Loader 1.1.0 - client side hyphenation for webbrowsers + * Copyright (C) 2014 Mathias Nater, Zürich (mathias at mnn dot ch) + * Project and Source hosted on http://code.google.com/p/hyphenator/ + * + * This JavaScript code is free software: you can redistribute + * it and/or modify it under the terms of the GNU Lesser + * General Public License (GNU LGPL) as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) + * any later version. The code is distributed WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details. + * + * As additional permission under GNU GPL version 3 section 7, you + * may distribute non-source (e.g., minimized or compacted) forms of + * that code without the copy of the GNU GPL normally required by + * section 4, provided you include this license notice and a URL + * through which recipients can access the Corresponding Source. + */ + +var 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 Block +transformVerseParas (Para xs) + | LineBreak `elem` xs = Para (addLineSpans xs) + | otherwise = Para xs +transformVerseParas x = x + +addLineSpans :: [Inline] -> [Inline] +addLineSpans = map encloseInSpan . splitWhen (== LineBreak) + where encloseInSpan = Span ("", ["line"], []) -- cgit 1.4.1-21-gabe81