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 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'bin/index') 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() -- cgit v1.2.3-54-g00ecf