diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 8 | ||||
-rwxr-xr-x | index.rb | 20 | ||||
-rwxr-xr-x | pagerender.rb | 54 | ||||
-rw-r--r-- | pandoc.rb | 65 | ||||
-rw-r--r-- | public/arch-systemd.md | 4 | ||||
-rw-r--r-- | public/bash-arrays.md | 4 | ||||
-rw-r--r-- | public/emacs-as-an-os.md | 4 | ||||
-rw-r--r-- | public/emacs-shells.md | 4 | ||||
-rw-r--r-- | public/fd_printf.md | 6 | ||||
-rw-r--r-- | public/fs-licensing-explanation.md | 4 | ||||
-rw-r--r-- | public/git-go-pre-commit.md | 6 | ||||
-rw-r--r-- | public/pacman-overview.md | 4 | ||||
-rw-r--r-- | public/poor-system-documentation.md | 4 | ||||
-rw-r--r-- | public/term-colors.md | 4 | ||||
-rw-r--r-- | template.erb | 2 |
16 files changed, 125 insertions, 69 deletions
@@ -1 +1,2 @@ public/*.html +public/index.md @@ -1,4 +1,4 @@ -articles = $(patsubst %.md,%,$(wildcard public/*.md)) +articles = $(filter-out public/index,$(patsubst %.md,%,$(wildcard public/*.md))) .DELETE_ON_ERROR: .SECONDARY: @@ -7,7 +7,7 @@ all: public/index.html $(addsuffix .html,$(articles)) public/%.html: public/%.md pagerender.rb template.erb Makefile ./pagerender.rb $< > $@ -public/index.html: $(addsuffix .md,$(articles)) index.rb template.erb Makefile - ./index.rb $(sort $(filter-out Makefile index.rb template.erb,$^)) > $@ +public/index.md: $(addsuffix .md,$(articles)) index.rb Makefile + ./index.rb $(sort $(filter-out Makefile index.rb public/index.md,$^)) > $@ clean: - rm -- public/*.html + rm -f -- public/*.html public/index.md @@ -1,23 +1,13 @@ #!/usr/bin/env ruby # -*- coding: utf-8 -*- -require 'rdiscount' +load 'pandoc.rb' require 'erb' -@title = "Web log entries" -@copyright = "Luke Shumaker" -license = "CC BY-SA-3.0" -license_url = 'https://creativecommons.org/licenses/by-sa/3.0/' -@license="<a href=\"#{license_url}\">#{license}</a>" - -markdown = "# #{@title}\n\n" +markdown = "Web log entries\n=====\n\n" for filename in ARGV do - title = File.read(filename).split("\n",2).first + input = File.read(filename) + title = Pandoc::load('markdown',input)["title"] || input.split("\n",2).first slug = filename.sub(/^public\//,'').sub(/\.md$/,'') markdown += " * [`#{slug}`](./#{slug}.html) — #{title}\n" end -@content = RDiscount.new(markdown).to_html - -template = 'template.erb' -erb = ERB.new(File.read(template)); -erb.filename = template -erb.run() +puts markdown diff --git a/pagerender.rb b/pagerender.rb index ecedaae..d63bcad 100755 --- a/pagerender.rb +++ b/pagerender.rb @@ -1,58 +1,38 @@ #!/usr/bin/env ruby # -*- coding: utf-8 -*- -require 'rdiscount' +load 'pandoc.rb' require 'erb' +require 'date' license_urls = { "CC BY-SA-3.0" => 'https://creativecommons.org/licenses/by-sa/3.0/', 'WTFPL-2' => "http://www.wtfpl.net/txt/copying/", } +author_urls = { + "Luke Shumaker" => "mailto:lukeshu@sbcglobal.net", +} template = 'template.erb' -input = ARGV.first - -lines = File.read(input).split("\n") +infile = ARGV.first -footnote_start = /^\[\^/ -footnote_cont = /^(\t| {2,4})/ +Pandoc::prog='pandoc' -markdown = '' -tags = {} -footnotes = {} -footnote_label = nil -for line in lines do - if (line =~ /^:/) - (key, val) = line.sub(/^:/, '').split(/\s+/, 2) - tags[key] = val - else - if (line =~ footnote_start) - footnote_label, footnote_body = line.split(':', 2) - footnote_label.gsub!(/[\^\[\]:]/, '') - footnotes[footnote_label] = footnote_body+"\n" - markdown += "[^#{footnote_label}]: 555PHONYFOOTNOTE555#{footnote_label}\n" - elsif (!footnote_label.nil? and line =~ footnote_cont) - footnotes[footnote_label] += line.sub(footnote_cont, '')+"\n" - else - footnote_label = nil - markdown += line+"\n" - end - end -end +input = File.read(infile) +doc = Pandoc::load('markdown-markdown_in_html_blocks', input) -@title = tags['title'] || lines.first -@copyright = tags['copyright'] || "Luke Shumaker" -@license = tags['license'] || "CC BY-SA-3.0" +@title = doc['title'] || input.split("\n",2).first +@author = doc['author'] || "Luke Shumaker" +@date = Date.parse(doc['date']) unless doc['date'].nil? +@license = doc['license'] || "CC BY-SA-3.0" unless license_urls[@license].nil? @license="<a href=\"#{license_urls[@license]}\">#{@license}</a>" end - -renderer = RDiscount.new(markdown) -renderer.footnotes = true; -@content = renderer.to_html -footnotes.each do |label, body| - @content.gsub!("555PHONYFOOTNOTE555#{label}", RDiscount.new(body).to_html) +unless author_urls[@author].nil? + @author="<a href=\"#{author_urls[@author]}\">#{@author}</a>" end +@content = doc.to('html5') + erb = ERB.new(File.read(template)); erb.filename = template erb.run() diff --git a/pandoc.rb b/pandoc.rb new file mode 100644 index 0000000..47f638e --- /dev/null +++ b/pandoc.rb @@ -0,0 +1,65 @@ +require 'open3' +require 'json' + +module Pandoc + def self.prog + @prog ||= 'pandoc' + end + def self.prog=(val) + @prog = val + end + def self.load(fmt, input) + cmd = Pandoc::prog + " -t json" + unless fmt.nil? + cmd += " -f " + fmt + end + str = input + if str.respond_to? :read + str = str.read + end + json = '' + Open3::popen3(cmd) do |stdin, stdout, stderr| + stdin.puts(str) + stdin.close + json = stdout.read + end + return Pandoc::AST::new(json) + end + + class AST + def initialize(json) + @js = JSON::parse(json) + end + + def [](key) + Pandoc::AST::js2sane(@js[0]["unMeta"][key]) + end + + def to(format) + cmd = Pandoc::prog + " -f json -t " + format.to_s + output = '' + Open3::popen3(cmd) do |stdin, stdout, stderr| + stdin.puts @js.to_json + stdin.close + output = stdout.read + end + output + end + + def self.js2sane(js) + if js.nil? + return js + end + case js["t"] + when "MetaList" + js["c"].map{|c| js2sane(c)} + when "MetaInlines" + js["c"].map{|c| js2sane(c)}.join() + when "Space" + " " + when "Str" + js["c"] + end + end + end +end diff --git a/public/arch-systemd.md b/public/arch-systemd.md index f0a484b..e62a61b 100644 --- a/public/arch-systemd.md +++ b/public/arch-systemd.md @@ -1,6 +1,8 @@ What Arch Linux's switch to systemd means for users =================================================== -:copyright 2012 Luke Shumaker +--- +date: 2012-09-11 +--- This is based on a post on [reddit][1], published on 2012-09-11. diff --git a/public/bash-arrays.md b/public/bash-arrays.md index 902635a..92201e2 100644 --- a/public/bash-arrays.md +++ b/public/bash-arrays.md @@ -1,6 +1,8 @@ Bash arrays =========== -:copyright 2013 Luke Shumaker +--- +date: 2013-10-13 +--- Way too many people don't understand Bash arrays. Many of them argue that if you need arrays, you shouldn't be using Bash. If we reject diff --git a/public/emacs-as-an-os.md b/public/emacs-as-an-os.md index c22cd15..b3db3d1 100644 --- a/public/emacs-as-an-os.md +++ b/public/emacs-as-an-os.md @@ -1,6 +1,8 @@ Emacs as an operating system ============================ -:copyright 2013 Luke Shumaker +--- +date: 2013-08-29 +--- This was originally published on [Hacker News][1] on 2013-08-29. diff --git a/public/emacs-shells.md b/public/emacs-shells.md index fdd5bcb..55bb846 100644 --- a/public/emacs-shells.md +++ b/public/emacs-shells.md @@ -1,6 +1,8 @@ A summary of Emacs' bundled shell and terminal modes ==================================================== -:copyright 2013 Luke Shumaker +--- +date: 2013-04-09 +--- This is based on a post on [reddit][1], published on 2013-04-09. diff --git a/public/fd_printf.md b/public/fd_printf.md index 5e1098e..8f4e1a7 100644 --- a/public/fd_printf.md +++ b/public/fd_printf.md @@ -1,7 +1,9 @@ `fd_printf`: print formatted text directly to a file descriptor =============================================================== -:copyright 2013 Luke Shumaker -:license WTFPL-2 +--- +date: 2013-10-12 +license: WTFPL-2 +--- I wrote this while debugging some code, and thought it might be useful to others: diff --git a/public/fs-licensing-explanation.md b/public/fs-licensing-explanation.md index 3e30975..8b840fa 100644 --- a/public/fs-licensing-explanation.md +++ b/public/fs-licensing-explanation.md @@ -1,6 +1,8 @@ An explanation of how "copyleft" licensing works ================================================ -:copyright 2013 Luke Shumaker +--- +date: 2013-02-21 +--- This is based on a post on [reddit][1], published on 2013-02-21. diff --git a/public/git-go-pre-commit.md b/public/git-go-pre-commit.md index 84137cc..98e7b28 100644 --- a/public/git-go-pre-commit.md +++ b/public/git-go-pre-commit.md @@ -1,7 +1,9 @@ A git pre-commit hook for automatically formatting Go code ========================================================== -:copyright 2013 Luke Shumaker -:license WTFPL-2 +--- +date: 2013-10-12 +license: WTFPL-2 +--- One of the (many) wonderful things about the Go programming language is the `gofmt` tool, which formats your source in a canonical way. I diff --git a/public/pacman-overview.md b/public/pacman-overview.md index 620ca61..8dc7e54 100644 --- a/public/pacman-overview.md +++ b/public/pacman-overview.md @@ -1,6 +1,8 @@ A quick overview of usage of the Pacman package manager ======================================================= -:copyright 2013 Luke Shumaker +--- +date: 2013-01-23 +--- This was originally published on [Hacker News][1] on 2013-01-23. diff --git a/public/poor-system-documentation.md b/public/poor-system-documentation.md index 0c97e40..2f9640d 100644 --- a/public/poor-system-documentation.md +++ b/public/poor-system-documentation.md @@ -1,6 +1,8 @@ Why documentation on GNU/Linux sucks ==================================== -:copyright 2012 Luke Shumaker +--- +date: 2012-09-12 +--- This is based on a post on [reddit][1], published on 2012-09-12. diff --git a/public/term-colors.md b/public/term-colors.md index bb945d0..3bf1d6f 100644 --- a/public/term-colors.md +++ b/public/term-colors.md @@ -1,6 +1,8 @@ An explanation of common terminal emulator color codes ====================================================== -:copyright 2013 Luke Shumaker +--- +date: 2013-03-21 +--- This is based on a post on [reddit][1], published on 2013-03-21. diff --git a/template.erb b/template.erb index 01ad125..66f9c85 100644 --- a/template.erb +++ b/template.erb @@ -13,7 +13,7 @@ <%= @content %> </article> <footer> -<p>The content of this page is Copyright © <%= @copyright %>.</p> +<p>The content of this page is Copyright © <%= @date.year unless @date.nil? %> <%= @author %>.</p> <p>This page is licensed under the <%= @license %> license.</p> </footer> </body> |