From 90e593e800e62b1605a8052a54e0ab3371dd3dde Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 4 Jan 2017 17:13:22 -0500 Subject: implement sections --- bin/index | 24 +++++++++++++++++++++++- bin/index.md.erb | 7 ++++++- bin/page | 2 +- bin/page.html.erb | 2 +- bin/util.rb | 8 ++++++++ 5 files changed, 39 insertions(+), 4 deletions(-) (limited to 'bin') 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 -- cgit v1.2.3