From d161be120c22faf222ec15ca618ee367e4d56575 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 1 Apr 2015 23:16:18 -0700 Subject: Refactor makefile; Add hapax preprocessor --- trunk/backlink.sh | 29 ++++++++++++++++ trunk/forceascii.hs | 17 ++++++++++ trunk/hapax.lua | 95 +++++++++++++++++++++++++--------------------------- trunk/hapaxlink.sh | 26 ++++++++++++++ trunk/lozenge.js | 2 +- trunk/lozenge.sh | 15 +++++++++ trunk/versify.exe | Bin 13686106 -> 13686106 bytes 7 files changed, 133 insertions(+), 51 deletions(-) create mode 100644 trunk/backlink.sh create mode 100644 trunk/forceascii.hs create mode 100644 trunk/hapaxlink.sh create mode 100644 trunk/lozenge.sh (limited to 'trunk') diff --git a/trunk/backlink.sh b/trunk/backlink.sh new file mode 100644 index 0000000..7d143a8 --- /dev/null +++ b/trunk/backlink.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Command-line variables +searchQuery="$1"; # .html file to backlink +outFile="$2"; # .back file to create +headerFile="$3"; # header information file +shift 3; +glob="$@"; # where to search for backlinks + +# Find backlinkers +echo -n "Back-linking \"$searchQuery\"" +cat "$headerFile" > "$outFile"; +grep -ql "$searchQuery" $glob >> "$outFile"; + +# Change title of $outFile +inText="`basename $searchQuery .html`.txt"; +title=`grep '^title:' "$inText" | cut -d' ' -f2-`; +sed -i "s/_TITLE_/$title/" "$outFile"; +echo -n "." + +# Link to backlinks +for file in `grep '.html' "$outFile"`; do + fText="`basename $file .html`.txt"; + title=`grep '^title:' $fText | cut -d' ' -f2-`; + sed -i "s/^$file$/- [$title](&)/" "$outFile"; + echo -n "." +done + +echo "Done." diff --git a/trunk/forceascii.hs b/trunk/forceascii.hs new file mode 100644 index 0000000..b5f1645 --- /dev/null +++ b/trunk/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/trunk/hapax.lua b/trunk/hapax.lua index 7e8410c..af59e59 100644 --- a/trunk/hapax.lua +++ b/trunk/hapax.lua @@ -1,8 +1,8 @@ --- Pandoc River writer +-- Pandoc Hapax writer -- it takes out all formatting, leaving only a river of text --- running down the page: one word per line +-- running down the page: one word per line, stripping all duplicates -- vim: fdm=marker --- invoke with: pandoc -t river.lua +-- invoke with: pandoc -t hapax.lua os.setlocale("en_US.UTF-8") @@ -40,36 +40,22 @@ function flow(s) end function nude(s) + s = s:lower() -- Expand contractions - s = s:gsub("'%a+%s", function (x) - if x == "'ll" then - return " will " - elseif x == "'ve" then - return " have " - elseif x == "'re" then - return " are " - else - return x - end - end) + 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 ") - -- Get rid of quotes around words - s = s:gsub('"', ' ') - s = s:gsub("%s'", ' ') - s = s:gsub("'%s", ' ') - -- Remove HTML entities - s = s:gsub('&.-;', ' ') - s = s:gsub('%b<>', ' ') - -- Remove end-of-line backslashes - s = s:gsub('\\$', ' ') - -- Remove dashes (not hyphens) + s = s:gsub("&", " and ") + -- -- Remove dashes (not hyphens) s = s:gsub('%-[%-%s]+', ' ') -- Remove everything that is not letters or numbers - s = s:gsub('[%.!%?:;,%[%]%(%)<>]', ' ') + s = s:gsub('[^A-Za-z0-9/\'-]', ' ') -- Remove extra spaces s = s:gsub('%s+', ' ') - return s:lower() + return " "..s.." " end -- This function is called once for the whole document. Parameters: @@ -89,71 +75,72 @@ function Doc(body, metadata, variables) end add(body) return hapax(flow(buffer)) + -- return flow(buffer) end -- Remove all formatting {{{ function Note(s) - return nude(s) + return s end function Blocksep() return "\n" end function Emph(s) - return nude(s) + return s end function Strong(s) - return nude(s) + return s end function Subscript(s) - return nude(s) + return s end function Superscript(s) - return nude(s) + return s end function SmallCaps(s) - return nude(s) + return s end function Strikeout(s) - return nude(s) + return s end function Code(s, attr) - return nude(s) + return s end function CodeBlock(s, attr) - return nude(s) + return s end function InlineMath(s) - return nude(s) + return s end function DisplayMath(s) - return nude(s) + return s end function Span(s, attr) - return nude(s) + return s end function Cite(s) - return nude(s) + return s end function Plain(s) - return nude(s) + return s end -- Links only include the link text function Link(s, src, tit) - return nude(s) + return s end -- Images have nothing to give us @@ -162,16 +149,24 @@ 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 nude(s) + return s end function Div(s, attr) - return nude(s) + return s end function Space(s) @@ -183,15 +178,15 @@ function LineBreak() end function Para(s) - return nude(s) + return s end function Header(lev, s, attr) - return nude(s) + return s end function BlockQuote(s) - return nude(s) + return s end function HorizontalRule() @@ -201,7 +196,7 @@ end function BulletList(items) local buffer = "" for _, item in pairs(items) do - buffer = buffer .. nude(item) .. "\n" + buffer = buffer .. " " .. item .. "\n" end return buffer .. "\n" end @@ -209,7 +204,7 @@ end function OrderedList(items) local buffer = "" for _, item in pairs(items) do - buffer = buffer .. nude(item) .. "\n" + buffer = buffer .. " " .. item .. "\n" end return buffer .. "\n" end @@ -218,7 +213,7 @@ function DefinitionList(items) local buffer = "" for _, item in pairs(items) do for k, v in pairs(item) do - buffer = buffer .. nude(k) .. "\n" .. nude(v) .. "\n" + buffer = buffer .. " " .. k .. "\n" .. v .. "\n" end end return buffer .. "\n" @@ -227,7 +222,7 @@ end function Table(caption, aligns, widths, headers, rows) local buffer = "" local function add(s) - buffer = buffer .. nude(s) .. "\n" + buffer = buffer .. " " .. s .. "\n" end if caption ~= "" then add(caption) diff --git a/trunk/hapaxlink.sh b/trunk/hapaxlink.sh new file mode 100644 index 0000000..286c43d --- /dev/null +++ b/trunk/hapaxlink.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +file="$1"; +headFile="$2"; +shift 2; +glob="$@"; # *.hapax + +tempFile="${RANDOM}.tmp" + +echo -n "Linking \"$file\"" +# Begin +cat "$headFile" > "$tempFile"; +echo -n "." +# Link words to files they appear in +for word in `sort "$file"`; do + f=`grep -liwq "^$word$" $glob`; + link="`basename $f .hapax`.html" + echo "[$word]($link)" >> "$tempFile"; + echo -n "." +done + +# Make the changes happen +rm "$file" +mv "$tempFile" "$file" + +echo "Done." diff --git a/trunk/lozenge.js b/trunk/lozenge.js index 4e6968b..171e251 100644 --- a/trunk/lozenge.js +++ b/trunk/lozenge.js @@ -6,7 +6,7 @@ function _lozenge() { var lozenge = document.getElementById('lozenge'); // array with all files {{{ - var files=["100-lines.html","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","common-titles.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","first-lines.html","found-typewriter-poem.html","hands.html","hapax.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","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"] + var files=["100-lines.html","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","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"] // }}} var index = Math.floor(Math.random() * files.length); diff --git a/trunk/lozenge.sh b/trunk/lozenge.sh new file mode 100644 index 0000000..9f0cd55 --- /dev/null +++ b/trunk/lozenge.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +outFile="$1"; +shift; +fileList="$@"; + +echo -n "Updating \"lozenge.js\"..." + +list=`echo ${fileList[@]} |\ + sed -e 's/\(\S\+.html\) \?/"\1",/g'\ + -e 's/^\(.*\),$/var files=[\1]/'` + +sed -i "s/var files=.*/$list/" "$outFile"; + +echo "Done." diff --git a/trunk/versify.exe b/trunk/versify.exe index 59850a2..cf9809c 100644 Binary files a/trunk/versify.exe and b/trunk/versify.exe differ -- cgit 1.4.1-21-gabe81