summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2017-01-04 17:13:22 -0500
committerLuke Shumaker <lukeshu@sbcglobal.net>2017-01-04 17:13:22 -0500
commit90e593e800e62b1605a8052a54e0ab3371dd3dde (patch)
tree35290948b249e6e756a3fdf6724fc8aa2bb4c6af /bin
parent5e257d407b4abf2be61c656dfb1d383396df35b1 (diff)
implement sections
Diffstat (limited to 'bin')
-rwxr-xr-xbin/index24
-rw-r--r--bin/index.md.erb7
-rwxr-xr-xbin/page2
-rw-r--r--bin/page.html.erb2
-rw-r--r--bin/util.rb8
5 files changed, 39 insertions, 4 deletions
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| %>
* <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 %>
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 @@
<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