summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rw-r--r--apollo11.html8
-rw-r--r--compile.lua128
-rw-r--r--lua/compile-uff.lua208
-rw-r--r--src/makefile5
5 files changed, 15 insertions, 338 deletions
diff --git a/README.md b/README.md index 0972f11..80d5d0d 100644 --- a/README.md +++ b/README.md
@@ -50,6 +50,8 @@ project:
50... 50...
51```` 51````
52 52
53To compile all the markdown into glorious, glorious HTML (visible at <http://autocento.me>), run `compile.lua` (`bash compile.lua` in Windows) in the root directory of this git repository. 53To compile all the markdown into glorious, glorious HTML (visible at <http://autocento.me>), run `make all` in the src directory of this repository.
54(Windows users: get a UNIX shell.
55I'm over it.)
54 56
55[pandoc]: http://johnmacfarlane.net/pandoc/ 57[pandoc]: http://johnmacfarlane.net/pandoc/
diff --git a/apollo11.html b/apollo11.html index 9be4c25..1ac9258 100644 --- a/apollo11.html +++ b/apollo11.html
@@ -39,6 +39,14 @@
39 </div> 39 </div>
40 </header> 40 </header>
41 41
42 <div class="ekphrastic">
43 <a href="http://apod.nasa.gov/apod/ap141220.html">
44 <img src="img/img/panorama-apollo11.jpg"
45 title="Big deal."
46 alt="Big deal."
47 />
48 </a>
49 </div>
42 50
43 <section class="content verse"><p>So it’s the <a href="deathstrumpet.html">fucking moon</a>. Big deal. As if<br />you haven’t seen it before, hanging in the sky<br />like a piece of <a href="roughgloves.html">rotten meat</a> nailed to the wall,</p> 51 <section class="content verse"><p>So it’s the <a href="deathstrumpet.html">fucking moon</a>. Big deal. As if<br />you haven’t seen it before, hanging in the sky<br />like a piece of <a href="roughgloves.html">rotten meat</a> nailed to the wall,</p>
44<p>a maudlin love letter (the i’s dotted with <a href="proverbs.html">hearts</a>)<br />tacked to the sky’s door like ninety-eight theses.<br />Don’t stare at it like it means anything.</p> 52<p>a maudlin love letter (the i’s dotted with <a href="proverbs.html">hearts</a>)<br />tacked to the sky’s door like ninety-eight theses.<br />Don’t stare at it like it means anything.</p>
diff --git a/compile.lua b/compile.lua deleted file mode 100644 index c02566e..0000000 --- a/compile.lua +++ /dev/null
@@ -1,128 +0,0 @@
1#!/usr/bin/env lua
2-- A compiler for Autocento of the breakfast table
3-- written in Lua (because we can, and because
4-- it's good practice for Functional Programming)
5-- ((OR WHATEVER YOU CALL IT, GAHD))
6-- vim: fdm=indent
7
8function filterout (list, filter)
9 -- Remove elements that match filter
10 local output = {}
11 for _,v in ipairs(list) do
12 if not string.match(v, filter) then
13 -- table.insert Y U NO WORK?
14 output[#output + 1] = v
15 end
16 end
17 return output
18end
19function intable (table, item)
20 -- Find out if an element's in a table
21 for k,v in pairs(table) do
22 if v == item then return k end
23 end
24 return false
25end
26function tabsub (table, pattern, replace)
27 -- Replace a pattern in all table values
28 local output = {}
29 for k,v in pairs(table) do
30 output[k] = v:gsub(pattern, replace)
31 end
32 return output
33end
34
35function compile (files, output_fmt, extension, template, args)
36 -- Run pandoc on file list
37 local errors = {}
38 if template then table.insert(args, 'template="'..template..'"') end
39 for _, file in pairs(files) do
40 local pandoc_run = {
41 'pandoc',
42 '-f markdown',
43 '-t '..output_fmt,
44 table.concat(tabsub(args, "^", "--"), ' '),
45 '-o '..file:gsub('^.*/(.-)%.%a+', '%1.'..extension),
46 file
47 }
48 print("Compiling "..file.." to ".. extension)
49 -- print(table.concat(pandoc_run, ' '))
50 os.execute(table.concat(pandoc_run, ' '))
51 end
52end
53
54function move (files, new_dir)
55 -- Move files to destinations
56 local exe = {}
57 for _,file in pairs(files) do
58 print("Moving "..file.." to "..new_dir.."/ ..")
59 table.insert(exe, 'mv '..file..' '..new_dir..'/')
60 end
61 os.execute(table.concat(exe, ' && '))
62 -- print(table.concat(exe, '; '))
63end
64
65function lozenge (files)
66 -- Update lozenge.js file list
67 local output = 'var files=['
68 for _,file in pairs(files) do
69 output = output .. file:gsub('.*', '"%0",')
70 end
71 output = output:gsub('"",','')
72 output = output:gsub(',$', ']')
73 return output
74end
75-- BEGIN MAIN STUFF HERE
76local files = filterout(arg, '^%-')
77if not files or #files == 0 then
78 -- Error: need files to work on!
79 -- TODO: don't need files if only arg is -lozenge
80 print("> No file list. WUT?")
81 os.exit(1)
82end
83local args = filterout(arg, '^[^%-]')
84if not args or #args == 0 or args == {'-all'} then
85 args = {
86 '-html',
87 '-river',
88 '-lozenge',
89 }
90end
91
92if intable(args, '-html') then
93 print("Compiling HTML ... ")
94 compile(files, "html5", "html", ".template.html", {
95 "smart",
96 "mathml",
97 "section-divs",
98 })
99 -- move(tabsub(files,'^.*/(.*)%.txt','%1.html'), ".")
100end
101if intable(args, '-river') then
102 print("Compiling RIVER ... ")
103 compile(files, "lua/river.lua", "river", nil, {})
104 move(tabsub(files,'^.*/(.*)%.txt','%1.river'), "river")
105end
106if intable(args, '-lozenge') then
107 print("Updating lozenge.js with file list ... ")
108 local f = assert(io.open("js/lozenge.js", "r"))
109 local tloz = {}
110 local HTMLs = io.popen("ls *.html")
111 local lozfs = {}
112 for line in HTMLs:lines() do
113 table.insert(lozfs, line)
114 end
115 for line in f:lines() do
116 if line:find("var files=") then
117 table.insert(tloz, lozenge(lozfs))
118 else
119 table.insert(tloz, line)
120 end
121 end
122 f:close()
123 -- And write the file we've just read
124 local _f = assert(io.open("js/lozenge.js", "w"))
125 _f:write(table.concat(tloz, "\n"))
126 _f:close()
127 print("Done.")
128end
diff --git a/lua/compile-uff.lua b/lua/compile-uff.lua deleted file mode 100644 index 9da70b8..0000000 --- a/lua/compile-uff.lua +++ /dev/null
@@ -1,208 +0,0 @@
1#!/usr/bin/env lua
2-- A compiler for "Autocento of the breakfast table" by Case Duckworth
3-- check it in action at: www.autocento.me
4-- Usage: `lua compile.lua [options] <files>
5-- Where [options] are
6-- -- -html: compiles html files
7-- -- -river: compiles river files (only words, one per line)
8-- -- -lozenge: updates lozenge.js file
9-- vim: fdm=indent
10
11defaults = {}
12 defaults.dirs = {
13 root = "/d/Copy/projects/autocento/",
14 src = "/d/Copy/projects/autocento/src/",
15 lua = "/d/Copy/projects/autocento/lua/",
16 js = "/d/Copy/projects/autocento/js/",
17 css = "/d/Copy/projects/autocento/css/",
18 }
19 defaults.files = {
20 lozenge = defaults.dirs.js .. "lozenge.js",
21 }
22 defaults.formats = {
23 html = {
24 output_dir = defaults.dirs.root,
25 extension = "html",
26 pandoc_args = {
27 from = "markdown",
28 to = "html5",
29 template = ".template.html",
30 "smart",
31 "mathml",
32 "section-divs",
33 }
34 },
35 river = {
36 output_dir = defaults.dirs.root .. "river/",
37 extension = "river",
38 pandoc_args = {
39 from = "markdown",
40 to = defaults.dirs.lua.."river.lua",
41 },
42 },
43 }
44 defaults.compile_args = {
45 '-html',
46 '-river',
47 '-lozenge',
48 }
49helpers = {
50 -- Little helper functions
51 filter = function (list, filter)
52 -- Filter a list.
53 -- 1st return is list of terms that match.
54 -- 2nd return is list of terms that don't match.
55 local output_match = {}
56 local output_nomatch = {}
57 for _,v in ipairs(list) do
58 if string.match(v, filter) then
59 output_match[#output_match+1] = v
60 else
61 output_nomatch[#output_nomatch+1] = v
62 end
63 end
64 return output_match, output_nomatch
65 end,
66 in_table = function (table, term)
67 -- Search for term in table
68 for k,v in pairs(table) do
69 if v == term then
70 return k
71 end
72 end
73 return nil
74 end,
75 tsub = function (table, pattern, replace, i)
76 -- gsub on every term in a table
77 local output = {}
78 if i then -- 'i' option just does ipair part of table
79 for k,v in ipairs(table) do
80 output[k] = v:gsub(pattern, replace)
81 end
82 else
83 for k,v in pairs(table) do
84 output[k] = v:gsub(pattern, replace)
85 end
86 end
87 return output
88 end,
89 scandir = function (directory)
90 -- Find all files in a directory
91 local i, t, popen = 0, {}, io.popen
92 for filename in popen('ls -a "'..directory..'"'):lines() do
93 i = i+1
94 t[i] = filename
95 end
96 return t
97 end
98}
99
100function compile (files, format_args)
101 -- Run pandoc on <files>, producing <output_format>, with [pandoc_args].
102 local errors = 0
103 if not format_args then
104 format_args = defaults.formats[output_format]
105 end
106 print("Compiling files to "..format_args.extension.." ...")
107 args = format_args.pandoc_args
108 for _, file in pairs(files) do
109 local pandoc_run = {
110 'pandoc',
111 '-f', args.from,
112 '-t', args.to,
113 '-o',
114 file:gsub('%.%a+$', "."..format_args.extension)
115 }
116 if args.template then
117 table.insert(pandoc_run, '--template="'..args.template..'"')
118 end
119 for _,a in ipairs(args) do
120 pandoc_run[#pandoc_run+1] = a:gsub("^", "--")
121 end
122 table.insert(pandoc_run, file)
123 for k,v in pairs(pandoc_run) do
124 print(k, v)
125 end
126 if not os.execute(table.concat(pandoc_run, " ")) then
127 errors = errors+1
128 end
129 io.write(".")
130 end
131 print("Compiling "..#files.." files completed with "..errors.." errors.")
132end
133
134function move (files, destination)
135 -- Move files to destination
136 print("Moving files to "..destination.." ...")
137 local errors = 0
138 for _, file in pairs(files) do
139 if not os.execute("mv "..file.." "..destination) then
140 errors = errors+1
141 end
142 end
143 print("Moving "..#files.." completed with "..errors.." errors.")
144end
145
146function lozenge_list (files, blacklist)
147 -- Produce list for placement in lozenge.js
148 local output = {}
149 for _,file in pairs(files) do
150 -- table.insert(output, #output+1, file:gsub('.*', '"%0"'))
151 output[#output+1] = file:gsub(".*", '"%0",')
152 end
153 if blacklist then
154 for _,unwanted in pairs(blacklist) do
155 _,output = helpers.filter(files, unwanted)
156 end
157 end
158 output = table.concat(output, " ")
159 output = "var files = ["..output
160 output = output:gsub('"",', '')
161 output = output:gsub(",$", "]")
162 print(output)
163end
164
165local args, files = helpers.filter(arg, "^%-")
166if not files or #files == 0 then
167 -- Error: need files to work on!
168 -- TODO: don't technically need file list for -lozenge
169 print("ERROR: No file list.")
170 os.exit(1)
171end
172basenames = helpers.tsub(files, "^.*/", "")
173basenames = helpers.tsub(files, "%.%a+$", "")
174if not args or #args == 0 or args == { "-all" } then
175 args = defaults.compile_args
176end
177-- Option parsing
178if helpers.in_table(args, "-html") then
179 compile(files, defaults.formats.html)
180 move(helpers.tsub(basenames, "$", "%0.html"),
181 defaults.formats.html.output_dir)
182end
183if helpers.in_table(args, "-river") then
184 compile(files, defaults.formats.river)
185 move(helpers.tsub(basenames, ".*", "%0.river"),
186 defaults.formats.river.output_dir)
187end
188if helpers.in_table(args, "-lozenge") then
189 -- TODO: should probably break this out into a function
190 print("Updating lozenge.js file list...")
191 local htmls = helpers.filter(helpers.scandir(defaults.dirs.root),
192 "html$")
193 local f = assert(io.open(defaults.files.lozenge, "r"))
194 local buffer = {}
195 for line in f:lines() do
196 if line:find("var files=") then
197 table.insert(buffer, lozenge_list(htmls))
198 else
199 table.insert(buffer, line)
200 end
201 end
202 f:close()
203 -- Write the file we've just read
204 local F = assert(io.open(defaults.files.lozenge, "w"))
205 F:write(table.concat(buffer, "\n"))
206 F:close()
207 print("Done.")
208end
diff --git a/src/makefile b/src/makefile index eefa4a3..800f8a0 100644 --- a/src/makefile +++ b/src/makefile
@@ -17,8 +17,11 @@ all : $(HTMLs) $(RIVERs)
17 17
18# Generic rule for HTML targets and Markdown sources 18# Generic rule for HTML targets and Markdown sources
19%.html : %.txt 19%.html : %.txt
20 pandoc $< -f markdown -t html5 $(HTMLopts) -o $(HTMLdir)/$@ 20 pandoc $< -f markdown -t html5 $(HTMopts) -o $(HTMLdir)/$@
21 21
22# Generic rule for RIVER targets and Markdown sources 22# Generic rule for RIVER targets and Markdown sources
23%.river : %.txt 23%.river : %.txt
24 pandoc $< -f markdown -t $(LUAdir)/river.lua $(RIVopts) -o $(RIVdir)/$@ 24 pandoc $< -f markdown -t $(LUAdir)/river.lua $(RIVopts) -o $(RIVdir)/$@
25
26# TODO: add lozenge updating
27# AND compiling hapax