From 90e593e800e62b1605a8052a54e0ab3371dd3dde Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 4 Jan 2017 17:13:22 -0500 Subject: implement sections --- Makefile | 21 ++++++++++++++++----- TODO.org | 1 - bin/index | 24 +++++++++++++++++++++++- bin/index.md.erb | 7 ++++++- bin/page | 2 +- bin/page.html.erb | 2 +- bin/util.rb | 8 ++++++++ src/index.yaml | 1 + src/writing/index.yaml | 6 ++++++ 9 files changed, 62 insertions(+), 10 deletions(-) create mode 100644 src/writing/index.yaml diff --git a/Makefile b/Makefile index dc232dd..28677ff 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,10 @@ html.suffixes = md org html.src = $(shell find src -type f \( -false $(foreach s,$(html.suffixes), -o -name '*.$s' ) \)) # Translate the source filenames into output filenames 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) +html.dirs = $(sort $(patsubst src%,out%, \ + $(patsubst %/,%,$(dir $(html.src))) \ + $(shell find src -name index.yaml -printf '%h\n'))) +html.out += out/index.atom $(addsuffix /index.html,$(html.dirs)) all: $(html.out) out/main.css .PHONY: all @@ -45,10 +48,18 @@ index.all = $(filter-out %/ChangeLog.md %/index.md,$(html.src) $(shell find src 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) +out/index.md : $(call index.dep,md) + @mkdir -p $(@D) + $(index.cmd) +out/%/index.md : $(call index.dep,md) + @mkdir -p $(@D) + $(index.cmd) +out/index.atom : $(call index.dep,atom) + @mkdir -p $(@D) + $(index.cmd) +out/%/index.atom : $(call index.dep,atom) + @mkdir -p $(@D) + $(index.cmd) serve: serve-8000 serve-%: all diff --git a/TODO.org b/TODO.org index 647e96e..bad2593 100644 --- a/TODO.org +++ b/TODO.org @@ -1,6 +1,5 @@ * functionality - tag filtering -- categories (writing/programming/dnd) * style - org tables * wish diff --git a/bin/index b/bin/index index 48968a3..c04618d 100755 --- a/bin/index +++ b/bin/index @@ -15,7 +15,7 @@ webpath = (@path+'/').sub(/^(src|out)\//, '/') if type == 'atom' webpath += 'index.atom' end -@url = URI::parse('https://www.andrewdm.me') + webpath +@url = URI::parse('https://www.andrewdm.me/') + webpath indexyaml = @path.sub('out', 'src')+'/index.yaml' if File.exists?(indexyaml) @@ -36,4 +36,26 @@ end # main @title = metadata['title'] || @path.sub('out', '') + +def guess_section(page) + for path in @sections.keys do + if @url.route_to(page.url).to_s.start_with?(path+'/') + return path + end + end + return '' +end + +@sections = { '' => {'head' => '', 'body' => []} } +(metadata['sections'] || []).each do |path, name| + @sections[path] = { + 'head' => name, + 'body' => [] + } +end +for page in @pages do + section = page.section || guess_section(page) + @sections[section]['body'].push(page) +end + erb.run() diff --git a/bin/index.md.erb b/bin/index.md.erb index 05ec43f..a3ec547 100644 --- a/bin/index.md.erb +++ b/bin/index.md.erb @@ -3,5 +3,10 @@ title: "<%= @title %>" class: "index" --- -<% @pages.sort_by{|a|a.published}.reverse.each do |a| %> +<% @sections.keys.sort.each do |path| %> +<% unless path.empty? %>## [<%= @sections[path]['head'] %>](<%= path %>)<% end %> + +<% @sections[path]['body'].sort_by{|a|a.published}.reverse.each do |a| %> * class="external" <% end %>href="<%= @url.route_to(a.url) %>" title="Published on <%= a.published.strftime('%Y-%m-%d') %><% if a.updated != a.published %> (updated on<%= a.updated.strftime('%Y-%m-%d') %>)<% end %>"><%= a.title %><% a.tags.each do |t| %><%= t.html %><% end %><% end %> + +<% end %> diff --git a/bin/page b/bin/page index 1b631cf..ee62a95 100755 --- a/bin/page +++ b/bin/page @@ -5,7 +5,7 @@ require 'uri' template = "bin/page.#{ARGV[0]}.erb" @page = Page.new(ARGV[1]) -@url = URI::parse('https://www.andrewdm.me') + @page.absoutpath +@url = URI::parse('https://www.andrewdm.me/') + @page.absoutpath erb = ERB.new(File.read(template)); erb.filename = template diff --git a/bin/page.html.erb b/bin/page.html.erb index 4ee5473..e2dc9fe 100644 --- a/bin/page.html.erb +++ b/bin/page.html.erb @@ -4,7 +4,7 @@ <%= @page.title %><% unless @page.title.empty? %> — <% end %>AndrewDM - + <%= @page.head %> class="<%= @page.class %>"<% end %>> diff --git a/bin/util.rb b/bin/util.rb index b2dcd40..cd7974b 100644 --- a/bin/util.rb +++ b/bin/util.rb @@ -236,6 +236,10 @@ class Page end @breadcrumbs end + + def section + return nil + end end def html_escape(html) @@ -291,4 +295,8 @@ class ExternPage end return Date.parse(str) end + + def section + return @metadata['section'] + end end diff --git a/src/index.yaml b/src/index.yaml index 931c08e..535f810 100644 --- a/src/index.yaml +++ b/src/index.yaml @@ -8,6 +8,7 @@ external: url: "http://365tomorrows.com/12/03/a-simple-lament/" published: "2013-12-03" tags: [FF] + section: "writing" - title: "Waterdeep Bazaar: Marketplace Generator" url: "/dnd/WaterdeepBazaar/WaterdeepBazaar.html" published: "2015-12-14" diff --git a/src/writing/index.yaml b/src/writing/index.yaml new file mode 100644 index 0000000..a04bb2d --- /dev/null +++ b/src/writing/index.yaml @@ -0,0 +1,6 @@ +title: "Writing" +external: + - title: "365 Tomorrows: A Simple Lament" + url: "http://365tomorrows.com/12/03/a-simple-lament/" + published: "2013-12-03" + tags: [FF] -- cgit v1.2.3