diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/index | 24 | ||||
-rw-r--r-- | bin/index.md.erb | 7 | ||||
-rwxr-xr-x | bin/page | 2 | ||||
-rw-r--r-- | bin/page.html.erb | 2 | ||||
-rw-r--r-- | bin/util.rb | 8 |
5 files changed, 39 insertions, 4 deletions
@@ -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| %> * <span><a <% if a.is_a?(ExternPage) %>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></span><span><% a.tags.each do |t| %><%= t.html %><% end %></span><% end %> + +<% end %> @@ -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 @@ <meta charset="utf-8"> <title><%= @page.title %><% unless @page.title.empty? %> — <% end %>AndrewDM</title> <link rel="stylesheet" href="/main.css"> - <link rel="alternate" type="application/atom+xml" href="./index.atom" name="web log entries"/> + <link rel="alternate" type="application/atom+xml" href="/index.atom" /> <%= @page.head %> </head> <body<% if @page.class %> 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 |