summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile12
-rw-r--r--README.org76
-rwxr-xr-xbin/auto-changelog2
-rw-r--r--config.yaml1
-rw-r--r--lib/page_index.rb8
-rw-r--r--lib/page_local.rb15
-rw-r--r--lib/page_pdf.rb62
-rw-r--r--lib/sitegen.rb2
-rw-r--r--src/changelog.md15
-rw-r--r--src/dnd/drews_rules.pdfbin0 -> 715540 bytes
-rw-r--r--src/dnd/drews_rules.yaml4
-rw-r--r--src/main.scss30
-rw-r--r--tmpl/pdf.md.erb5
13 files changed, 191 insertions, 41 deletions
diff --git a/Makefile b/Makefile
index 96e0fdf..f61c4c3 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,9 @@
MAKEFLAGS += -j1
+pdfjs = https://github.com/mozilla/pdf.js/releases/download/v1.9.426/pdfjs-1.9.426-dist.zip
+
# Default target
-all: out/index.html out/main.css
+all: out/index.html out/main.css out/pdfjs
phony += all
# Boilerplate
@@ -25,7 +27,13 @@ out/%.css: src/%.scss
@mkdir -p $(@D)
scss --stdin < $< > $@
-targets = $(phony) %.css
+out/$(notdir $(pdfjs)):
+ wget -c --no-use-server-timestamp -O $@ $(pdfjs)
+out/pdfjs: out/$(notdir $(pdfjs))
+ rm -rf -- $@
+ mkdir -- $@ && bsdtar -xf $(abspath $<) -C $@ --exclude '*.pdf' || { rm -rf -- $@; false; }
+
+targets = $(phony) %.css out/pdfjs%
$(sort $(filter-out $(targets),out/index.html $(MAKECMDGOALS))): FORCE
./bin/sitegen
diff --git a/README.org b/README.org
index 1b9491e..e95aff5 100644
--- a/README.org
+++ b/README.org
@@ -54,20 +54,29 @@ Those dependencies are:
* Authoring pages
-Currently supported are Markdown (~.md~) and Org-mode (~.org~) files.
-Each of these format supports embedding metadata in the document
-(well, Markdown doesn't really, but the Pandoc syntax extension
-~yaml_metadata_block~ adds it).
+If you drop a file in the ~src/~ folder, the site generator will try
+to turn it into usable HTML. The big caveat is that files *MUST* to
+be in all lower case (this is to efficiently handle the requirement
+that URLs be case-insensitive)!
-In Org-mode, this looks like
+Currently supported formats are:
-#+BEGIN_SRC
-#+KEY: value
+ - Markdown (~.md~) : converted with Pandoc
+ - Org-mode (~.org~) : converted with Pandoc
+ - PDF (~.pdf~) : embedded with PDF.js
-...rest of document...
-#+END_SRC
+I don't need to tell you how to make these types of files.
+
+In addition to the raw content of the files, you'll want/need to set
+metadata about the page. Each of these format supports embedding
+metadata in the document.
-In Markdown, this looks like
+** Setting metadata: Markdown
+
+Metadata for Markdown files can be set by adding a block of YAML at
+the beginning of the document, terminated with "---". This isn't
+"standard" markdown, but is a common syntax extension (Pandoc calls it
+~yaml_metadata_block~).
#+BEGIN_SRC
---
@@ -79,16 +88,47 @@ key2:
...rest of document...
#+END_SRC
+Pandoc may make use of some of these metadata attributes internally
+when converting to HTML. See the Pandoc documentation.
+
+** Setting metadata: Org-mode
+
+Metadata for Org-mode files can be set by adding ~#+KEY: value~ lines
+at the beginning of the document.
+
+#+BEGIN_SRC
+#+KEY: value
+
+...rest of document...
+#+END_SRC
+
+Pandoc may make use of some of these metadata attributes internally
+when converting to HTML. See the Org-mode and Pandoc documentation.
+
AFAIK, unfortunately Org-mode only has values as strings, no
structured data.
-Pandoc may make use of some of these values internally when converting
-to HTML. See the Org-mode and Pandoc documentation.
+** Setting metadata: PDF
+
+PDF files natively support embedding certain bits of metadata. The
+bits that we use are:
+
+ - title
+ - author
+ - creation date
+ - modification date
+
+If you need to set any other metadata attributes, or want to override
+the values in the PDF (since setting them can be difficult), create
+YAML file with the same name as the PDF file, but with the ~.yaml~
+file extension instead of ~.pdf~.
+
+** Metadata attributes that are handles specially
-However, there are some of these that are used specially by the site
+There are some metadata attributes that are used specially by the site
generator:
-| attribute | default | standard | format |
+| attribute | default value | standard | format |
|------------------+---------------------------------+----------+-------------------------------------------------|
| title | the first line of the file | Pandoc | string |
| author | ~config.yaml:default_author~ | Pandoc | string +or list+ [fn:1] |
@@ -98,16 +138,16 @@ generator:
| html_head_extra | "" | Org-mode | string |
| class | "" | no | string (CSS class to apply to ~<body>~) |
| categories[fn:2] | "" | no | string ("ES HB") or list (["ES", "HB"]) |
-| published[fn:2] | most recent git commit for file | no | string (Ruby ~DateTime::parse()~) or date[fn:3] |
-| updated[fn:2] | first git commit for file | no | string (Ruby ~DateTime::parse()~) or date[fn:3] |
+| published[fn:2] | first git commit for file | no | string (Ruby ~DateTime::parse()~) or date[fn:3] |
+| updated[fn:2] | most recent git commit for file | no | string (Ruby ~DateTime::parse()~) or date[fn:3] |
[fn:1] We don't support lists of authors, though the Pandoc "standard"
does.
[fn:2] The "published"/"updated"/"categories" terminology is borrowed
from the Atom specification (RFC 4287), and I intend them to have the
-same semantics. For "published"/"updated", there is a "standard"
-variable name is "date", but I thought that was dreadfully ambiguous
+same semantics. For "published"/"updated", the Pandoc "standard"
+variable name is "date"; but I thought that was dreadfully ambiguous
and confusing when the site generator deals with two distinct dates.
[fn:3] At various times there have been bugs in the YAML parser
diff --git a/bin/auto-changelog b/bin/auto-changelog
index d672b5f..b374fda 100755
--- a/bin/auto-changelog
+++ b/bin/auto-changelog
@@ -14,7 +14,7 @@ should-insert() {
}
generate-entry() {
- git log -n1 --stat --date='format:%Y-%m-%d' --format=$'## %ad %an <%ae>\n\n%B' | cat -s
+ git log -n1 --date='format:%Y-%m-%d' --format=$'## %ad %an <%ae>\n\n%B' | cat -s
}
html_escape() {
diff --git a/config.yaml b/config.yaml
index 605faaa..4ca1bac 100644
--- a/config.yaml
+++ b/config.yaml
@@ -1,5 +1,4 @@
url: "https://www.andrewdm.me/"
-html_suffixes: ["md", "org"]
# Licenses
default_license: "CC BY-SA-3.0"
diff --git a/lib/page_index.rb b/lib/page_index.rb
index 585fd57..31d4682 100644
--- a/lib/page_index.rb
+++ b/lib/page_index.rb
@@ -28,13 +28,15 @@ class IndexPage < LocalPage
@ls ||= Dir::entries(local_infile)
.select{|fname|not fname.start_with?(".")}
.map{|fname|"#{local_infile}/#{fname}"}
- .select{|path|Dir::exist?(path) or Config::get.html_suffixes.include?(File::extname(path).gsub(/^[.]/, ''))}
end
def index_pages
if @pages.nil?
@pages = Set[]
for path in _ls
- @pages.add( Dir::exist?(path) ? IndexPage::new(path) : LocalPage::new(path) )
+ page = LocalPage::load(path)
+ unless page.nil?
+ @pages.add(page)
+ end
end
for data in (_metadata['external'] || [])
@pages.add(RemotePage::new(data))
@@ -59,7 +61,7 @@ class IndexPage < LocalPage
unless depth <= 1
ret += "<section><h#{depth}>[#{atom_title}](#{cururl.route_to(url)})</h#{depth}>\n\n"
end
- for page in index_pages.select{|page|not page.is_a?(IndexPage)}.sort_by{|page|page.atom_published}
+ for page in index_pages.select{|page|not page.is_a?(IndexPage)}.sort_by{|page|page.atom_updated}.reverse
ret += page.index_link(cururl, depth+1)
end
ret += "\n"
diff --git a/lib/page_local.rb b/lib/page_local.rb
index e13fa33..6c70ac3 100644
--- a/lib/page_local.rb
+++ b/lib/page_local.rb
@@ -9,6 +9,21 @@ require 'pandoc'
require 'person'
class LocalPage < Page
+ def self.load(inpath)
+ case
+ when Dir::exist?(inpath)
+ require 'page_index'
+ return IndexPage::new(inpath)
+ when [".md", ".org"].include?(File::extname(inpath))
+ return LocalPage::new(inpath)
+ when ".pdf" == File::extname(inpath)
+ require 'page_pdf'
+ return PdfPage::new(inpath)
+ else
+ return nil
+ end
+ end
+
def initialize(infile)
@infile = infile
super()
diff --git a/lib/page_pdf.rb b/lib/page_pdf.rb
new file mode 100644
index 0000000..e70c887
--- /dev/null
+++ b/lib/page_pdf.rb
@@ -0,0 +1,62 @@
+# coding: utf-8
+require 'erb'
+require 'open3'
+require 'yaml'
+
+require 'page_local'
+
+class PdfPage < LocalPage
+ def initialize(filename)
+ super(filename)
+ end
+
+ def pdf_metadata
+ if @metadata.nil?
+ stdout, stderr, status = Open3::capture3("pdfinfo", "--", local_infile)
+ unless stderr.empty?
+ raise stderr
+ end
+ unless status.success?
+ raise status
+ end
+ raw_metadata = stdout.split("\n").map{|l|l.split(":", 2).map{|c|c.strip}}.to_h
+
+ # Transform the PDF property names to match our metadata names
+ key_map = {
+ "Title" => "title",
+ "Author" => "author",
+ "CreationDate" => "published",
+ "ModDate" => "updated",
+ # "Keywords" => "categories",
+ }
+ @metadata = raw_metadata.map{|k,v|[key_map[k]||k,v]}.to_h
+
+ yamlfile = local_infile.sub(/\.pdf$/, '.yaml')
+ if File::exist?(yamlfile)
+ @metadata = @metadata.merge(YAML::load(File::read(yamlfile)))
+ end
+ end
+ @metadata
+ end
+ def pdf_js_url
+ @@pdjfs ||= Config::get.url + 'pdfjs/web/viewer.html'
+ end
+ def pdf_viewer_url
+ @viewer_url ||= pdf_js_url + ('?file=' + URI::encode_www_form_component(pdf_js_url.route_to(local_srcurl)))
+ end
+
+ def local_intype
+ return 'markdown'
+ end
+ def local_depends
+ if @depends.nil?
+ yamlfile = local_infile.sub(/\.pdf$/, '.yaml')
+ metafile = File::exist?(yamlfile) ? yamlfile : File::dirname(yamlfile)
+ tmplfile = "tmpl/pdf.md.erb"
+ @depends = super.map{|k,v|[k,v.merge([metafile, tmplfile])]}.to_h
+ end
+ @depends
+ end
+end
+
+ERB::new(File::read("tmpl/pdf.md.erb")).def_method(PdfPage, 'local_input()', "tmpl/pdf.md.erb")
diff --git a/lib/sitegen.rb b/lib/sitegen.rb
index 78222a3..4a3dd48 100644
--- a/lib/sitegen.rb
+++ b/lib/sitegen.rb
@@ -40,7 +40,7 @@ module Sitegen
end
@deps
end
- def self.Makefile()
+ def self.Makefile
str = ''
dependencies.each do |target, deps|
str += "#{target.to_s}: #{deps.sort.join(' ')}\n"
diff --git a/src/changelog.md b/src/changelog.md
index 1fa24d5..1c42125 100644
--- a/src/changelog.md
+++ b/src/changelog.md
@@ -68,33 +68,18 @@ Updated the About with an Epigraph
remove unfinished sources
- src/dnd/psionist-class.md | 1504 -------------------------------
- src/dnd/{psionist2.org => psionist.org} | 0
- src/dnd/spell-gauntlet.org | 683 --------------
- 3 files changed, 2187 deletions(-)
-
## 2017-01-14 Andrew Murrell &lt;merl@neo.andrewdm.me&gt;
updated Psionist Title page
- bin/pre-generate | 2 ++
- src/dnd/{Psionist2.org => psionist2.org} | 4 ++++
- 2 files changed, 6 insertions(+)
-
## 2017-01-14 Andrew Murrell &lt;merl@neo.andrewdm.me&gt;
Added an updated Psionist class with more complete domains, but no mind powers yet.
- src/dnd/Psionist2.org | 566 ++++++++++++++++++++++++++++++++++++++++++++++++++
- 1 file changed, 566 insertions(+)
-
## 2017-01-04 Luke Shumaker &lt;lukeshu@lukeshu.com&gt;
Change the title of "Psionist" -&gt; "Psionist Class [5e]"
- src/dnd/Psionist.md | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
## 31 August 2016
Decided that the 1/5th of 'Magic is Magic' that was 'finished' was
diff --git a/src/dnd/drews_rules.pdf b/src/dnd/drews_rules.pdf
new file mode 100644
index 0000000..65ffb89
--- /dev/null
+++ b/src/dnd/drews_rules.pdf
Binary files differ
diff --git a/src/dnd/drews_rules.yaml b/src/dnd/drews_rules.yaml
new file mode 100644
index 0000000..70a57e6
--- /dev/null
+++ b/src/dnd/drews_rules.yaml
@@ -0,0 +1,4 @@
+---
+author: "Andrew Murrell"
+title: "Drew's Rules"
+categories: "HB"
diff --git a/src/main.scss b/src/main.scss
index be00d49..fadd75b 100644
--- a/src/main.scss
+++ b/src/main.scss
@@ -287,3 +287,33 @@ body.dnd {
font-weight:bold; }
}
}
+
+/* D&D-style pages ************************************************************/
+
+body.pdf {
+ position: absolute;
+ width: 100%;
+ height: 100%;
+ bottom: 0;
+
+ display: flex;
+ flex-direction: column;
+
+ article {
+ flex-grow: 2;
+ padding: 0;
+
+ p {
+ float: left;
+ margin: 0.25em -100% 0.25em 0.25em;
+ }
+ h1 {
+ text-align: center;
+ margin: 0.25em 0;
+ }
+ iframe {
+ width: 100%;
+ height: 100%;
+ }
+ }
+}
diff --git a/tmpl/pdf.md.erb b/tmpl/pdf.md.erb
new file mode 100644
index 0000000..2ce7327
--- /dev/null
+++ b/tmpl/pdf.md.erb
@@ -0,0 +1,5 @@
+<%= pdf_metadata.to_yaml %>
+class: pdf
+---
+
+<iframe src="<%= url.route_to(pdf_viewer_url) %>" ></iframe>