From 5449dca686d7bdbd5f09acd4e9fd8647535acde9 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 3 Jan 2017 20:18:45 -0500 Subject: index.yaml partial support --- Makefile | 18 ++++++++---------- bin/index | 19 ++++++++++++++++--- bin/index.atom.erb | 8 ++++---- bin/index.md.erb | 2 +- bin/util.rb | 1 - src/dnd/index.yaml | 3 ++- src/index.yaml | 3 ++- 7 files changed, 33 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 87fd94f..be186c8 100644 --- a/Makefile +++ b/Makefile @@ -17,8 +17,6 @@ html.src = $(shell find src -type f \( -false $(foreach s,$(html.suffixes), -o - html.out = $(call patsubst-all,$(addprefix src/%.,$(html.suffixes)),out/%.html,$(html.src)) html.out += $(foreach d,$(sort $(dir $(patsubst src/%,out/%,$(html.src)))),$dindex.html $dindex.atom) -mydir = $(patsubst %/,%,$(patsubst out/%,%,$(dir $@))) - all: $(html.out) out/main.css .PHONY: all @@ -43,14 +41,14 @@ out/%.css: src/%.scss out/%.css: out/%.scss scss --stdin < $< > $@ -out/index.md : $(bin/index) bin/index.md.erb .var.html.src $(html.src) bin/write-atomic - bin/index md '$(mydir)' $(filter $(patsubst out%,src%,$(@D))/%,$^) | bin/write-atomic $@ -out/%/index.md : $(bin/index) bin/index.md.erb .var.html.src $(html.src) bin/write-atomic - bin/index md '$(mydir)' $(filter $(patsubst out%,src%,$(@D))/%,$^) | bin/write-atomic $@ -out/index.atom : $(bin/index) bin/index.atom.erb .var.html.src $(html.src) bin/write-atomic - bin/index atom '$(mydir)' $(filter $(patsubst out%,src%,$(@D))/%,$^) | bin/write-atomic $@ -out/%/index.atom: $(bin/index) bin/index.atom.erb .var.html.src $(html.src) bin/write-atomic - bin/index atom '$(mydir)' $(filter $(patsubst out%,src%,$(@D))/%,$^) | bin/write-atomic $@ +index.all = $(html.src) $(shell find src -type f -name index.yaml) +index.filter = $(filter-out %/index.yaml,$(filter $(@D)/% $(patsubst out%,src%,$(@D))/%,$1)) +index.cmd = bin/index $(patsubst .%,%,$(suffix $@)) $(@D) $(call index.filter,$^) | bin/write-atomic $@ +index.dep = $(bin/index) bin/index.$1.erb .var.index.all $(index.all) bin/write-atomic Makefile +out/index.md : $(call index.dep,md) ; $(index.cmd) +out/%/index.md : $(call index.dep,md) ; $(index.cmd) +out/index.atom : $(call index.dep,atom) ; $(index.cmd) +out/%/index.atom : $(call index.dep,atom) ; $(index.cmd) serve: serve-8000 serve-%: all diff --git a/bin/index b/bin/index index 4f41c5d..2443380 100755 --- a/bin/index +++ b/bin/index @@ -1,16 +1,29 @@ #!/usr/bin/env ruby # -*- coding: utf-8 -*- load 'util.rb' +require 'yaml' +# ARGV[0] template = "bin/index.#{ARGV.shift}.erb" +erb = ERB.new(File.read(template)); +erb.filename = template + +# ARGV[1] @path = ARGV.shift +indexyaml = @path.sub('out', 'src')+'/index.yaml' +if File.exists?(indexyaml) + metadata = YAML::load(File.read(indexyaml)) +else + metadata = {} +end + +# ARGV[2..] @pages = [] for filename in ARGV do @pages.push(Page.new(filename)) end - -erb = ERB.new(File.read(template)); -erb.filename = template +# main +@title = metadata['title'] || @path.sub('out', '') erb.run() diff --git a/bin/index.atom.erb b/bin/index.atom.erb index 0667088..1afbf8c 100644 --- a/bin/index.atom.erb +++ b/bin/index.atom.erb @@ -1,7 +1,7 @@ - AndrewDM.me <%= @path %> + AndrewDM.me <%= @title %> @@ -11,9 +11,9 @@ <% @pages.sort_by{|p| p.updated}.reverse.each do |page| %> - - - https://lukeshu.com/blog/<%= page.slug %>.html + + + https://andrewdm.me/<%= page.url %> <%= page.updated.rfc3339 %> <%= page.published.rfc3339 %> <%= page.title %> diff --git a/bin/index.md.erb b/bin/index.md.erb index 621a323..ce5e030 100644 --- a/bin/index.md.erb +++ b/bin/index.md.erb @@ -1,5 +1,5 @@ --- -title: "<%= @path %>" +title: "<%= @title %>" class: "index" --- diff --git a/bin/util.rb b/bin/util.rb index 1318f28..05808b7 100644 --- a/bin/util.rb +++ b/bin/util.rb @@ -115,7 +115,6 @@ class Page def author ; @author ||= Person.new( pandoc['author'] || "Andrew Murrell") ; end def license ; @license ||= License.new(pandoc['license'] || "CC BY-SA-3.0") ; end - def slug ; @slug ||= infile.sub(/\..*$/,'').sub(/^.*\//,'') ; end def content ; @content ||= pandoc.to('html5 '+(pandoc['pandoc_flags']||'')) ; end def head ; @head ||= pandoc['html_head_extra'] ; end def class ; @class ||= pandoc['class'] ; end diff --git a/src/dnd/index.yaml b/src/dnd/index.yaml index 6e83a31..a0a0868 100644 --- a/src/dnd/index.yaml +++ b/src/dnd/index.yaml @@ -1,5 +1,6 @@ +title: "Dungeons & Dragons" external: - title: "Waterdeep Bazaar: Marketplace Generator" - url: "/dnd/WaterdeepBazaar/WaterdeepBazaar.html" + url: "dnd/WaterdeepBazaar/WaterdeepBazaar.html" published: "2015-12-14" tags: [DM, WP] diff --git a/src/index.yaml b/src/index.yaml index 3532b53..c61e1b6 100644 --- a/src/index.yaml +++ b/src/index.yaml @@ -1,3 +1,4 @@ +title: "" sections: "writing": "Writing" "dnd": "Dungeons & Dragons" @@ -8,6 +9,6 @@ external: published: "2013-12-03" tags: [FF] - title: "Waterdeep Bazaar: Marketplace Generator" - url: "/dnd/WaterdeepBazaar/WaterdeepBazaar.html" + url: "dnd/WaterdeepBazaar/WaterdeepBazaar.html" published: "2015-12-14" tags: [DM, WP] -- cgit v1.2.3