From 61ac134ab6fc68166b2fddeec16914d28e40aa26 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 22 Dec 2017 21:05:44 -0500 Subject: Re-do CSS. I also add a few
tags, and added classes to a couple of s. I moved the dnd CSS to a separate file that is currently unused. I assume I'll add it back soon. --- lib/page.rb | 4 ++-- lib/page_index.rb | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/page.rb b/lib/page.rb index b349dc8..ebc123b 100644 --- a/lib/page.rb +++ b/lib/page.rb @@ -91,11 +91,11 @@ class Page end def index_link(cururl, depth) # FIXME: This code is super gross. - ret = " * #{atom_title}" + ret += "\">#{atom_title}" atom_categories.each do |t| ret += t.html end diff --git a/lib/page_index.rb b/lib/page_index.rb index 43bf367..585fd57 100644 --- a/lib/page_index.rb +++ b/lib/page_index.rb @@ -57,7 +57,7 @@ class IndexPage < LocalPage def index_link(cururl, depth) ret = '' unless depth <= 1 - ret += "[#{atom_title}](#{cururl.route_to(url)})\n\n" + ret += "
[#{atom_title}](#{cururl.route_to(url)})\n\n" end for page in index_pages.select{|page|not page.is_a?(IndexPage)}.sort_by{|page|page.atom_published} ret += page.index_link(cururl, depth+1) @@ -67,6 +67,9 @@ class IndexPage < LocalPage ret += page.index_link(cururl, depth+1) end ret += "\n" + unless depth <= 1 + ret += "
\n\n" + end return ret.gsub(/\n\n+/, "\n\n") end def index_title -- cgit v1.2.3-2-g168b From df82c975ee5cb6ff3000bca99b246d90e8be7eec Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 22 Dec 2017 23:23:27 -0500 Subject: fix tag names in page titles --- lib/category.rb | 2 +- lib/config.rb | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/category.rb b/lib/category.rb index e0ed8e0..8f14153 100644 --- a/lib/category.rb +++ b/lib/category.rb @@ -9,7 +9,7 @@ class Category @abbr.downcase end def name - Config::get.category_name(@abbr) + Config::get.category_name(abbr) end def html return "#{name}" diff --git a/lib/config.rb b/lib/config.rb index 4690559..57e3b3f 100644 --- a/lib/config.rb +++ b/lib/config.rb @@ -42,10 +42,8 @@ class Config return @data['person_emails'][name] end # Categories - def categories - return @data['categories'].keys - end def category_name(abbr) - return @data['categories'][abbr] + @categories ||= (@data['categories'] || {}).map{|k,v|[k.downcase,v]}.to_h + return @categories[abbr.downcase] end end -- cgit v1.2.3-2-g168b From c70e32b7d43282e0cb4b4d36ca4956bd5e1b9ed6 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 23 Dec 2017 00:31:48 -0500 Subject: config: fix typo, prevent it from happening again --- lib/config.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/config.rb b/lib/config.rb index 57e3b3f..944acc3 100644 --- a/lib/config.rb +++ b/lib/config.rb @@ -21,11 +21,7 @@ class Config return @default_license ||= @data['default_license'] end def license_uri(name) - str = @data['license_uris'][name] - if str.nil? - return nil - end - return URI::parse(str) + return URI::parse(@data['license_uris'][name]) end # People def default_author -- cgit v1.2.3-2-g168b From e8197dabd76b55f2c21e92c07fc7080d2db8d7df Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 23 Dec 2017 13:20:32 -0500 Subject: index pages: sort by "most recently updated" instead of "publication order" --- lib/page_index.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/page_index.rb b/lib/page_index.rb index 585fd57..42c9e21 100644 --- a/lib/page_index.rb +++ b/lib/page_index.rb @@ -59,7 +59,7 @@ class IndexPage < LocalPage unless depth <= 1 ret += "
[#{atom_title}](#{cururl.route_to(url)})\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" -- cgit v1.2.3-2-g168b From 3ca1e438fe602f3f03609ea6869b1de7a4091acc Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 23 Dec 2017 15:51:23 -0500 Subject: lib/sitegen: remove extra parens --- lib/sitegen.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') 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" -- cgit v1.2.3-2-g168b From 4c3f03c1a7c622c3e92081664b42c96831b43dca Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 23 Dec 2017 15:02:32 -0500 Subject: Let LocalPage::load decide how to handle different file types --- lib/page_index.rb | 6 ++++-- lib/page_local.rb | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/page_index.rb b/lib/page_index.rb index 42c9e21..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)) diff --git a/lib/page_local.rb b/lib/page_local.rb index e13fa33..e956f6a 100644 --- a/lib/page_local.rb +++ b/lib/page_local.rb @@ -9,6 +9,18 @@ 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) + else + return nil + end + end + def initialize(infile) @infile = infile super() -- cgit v1.2.3-2-g168b From efbd3731c986a8555869c184cda69ff9b910ce9f Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 23 Dec 2017 15:52:22 -0500 Subject: pdf support --- lib/page_local.rb | 3 +++ lib/page_pdf.rb | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 lib/page_pdf.rb (limited to 'lib') diff --git a/lib/page_local.rb b/lib/page_local.rb index e956f6a..6c70ac3 100644 --- a/lib/page_local.rb +++ b/lib/page_local.rb @@ -16,6 +16,9 @@ class LocalPage < Page 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 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") -- cgit v1.2.3-2-g168b