summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2017-01-06 23:47:49 -0500
committerLuke Shumaker <lukeshu@sbcglobal.net>2017-01-06 23:47:49 -0500
commit2db85d4d3bff943629709cacc3d976c24951b8aa (patch)
treec0218e99a0814cbec330c8ede9c821b52457fef5
parent4a3a404a5cb2a8d5be83e28cec5c539928fa30f4 (diff)
index local_input
-rw-r--r--lib/page.rb16
-rw-r--r--lib/page_index.rb29
-rw-r--r--lib/page_remote.rb6
-rw-r--r--src/index.yaml16
-rw-r--r--tmpl/index.md.erb3
5 files changed, 42 insertions, 28 deletions
diff --git a/lib/page.rb b/lib/page.rb
index 64bbaea..f269b75 100644
--- a/lib/page.rb
+++ b/lib/page.rb
@@ -80,4 +80,20 @@ class Page
end
@years
end
+
+ def index_class
+ return ''
+ end
+ def index_link(cururl, depth)
+ # FIXME: This code is super gross.
+ ret = " * <span><a class=\"#{index_class}\" href=\"#{cururl.route_to(url)}\" title=\"Published on #{atom_published.strftime('%Y-%m-%d')}"
+ if atom_updated != atom_published
+ ret += " (updated on #{atom_updated.strftime('%Y-%m-%d')})"
+ end
+ ret += "\">#{atom_title}</a></span><span>"
+ atom_categories.each do |t|
+ ret += t.html
+ end
+ ret += "</span>\n"
+ end
end
diff --git a/lib/page_index.rb b/lib/page_index.rb
index 3e25813..6354c8a 100644
--- a/lib/page_index.rb
+++ b/lib/page_index.rb
@@ -31,23 +31,32 @@ class IndexPage < LocalPage
end
def index_pages
if @pages.nil?
- @pages = []
+ @pages = Set[]
for path in _ls
- if Dir::exist?(path)
- page = IndexPage::new(path)
- @pages.unshift(page)
- @pages += page.index_pages
- else
- @pages.unshift(LocalPage::new(path))
- end
+ @pages.add( Dir::exist?(path) ? IndexPage::new(path) : LocalPage::new(path) )
end
- for data in _metadata['external']
- @pages.unshift(RemotePage::new(data))
+ for data in (_metadata['external'] || [])
+ @pages.add(RemotePage::new(data))
end
end
@pages
end
+ def index_link(cururl, depth)
+ ret = ''
+ unless depth <= 1
+ ret += "<h#{depth}>[#{atom_title}](#{cururl.route_to(url)})</h#{depth}>\n\n"
+ end
+ for page in index_pages.select{|page|not page.is_a?(IndexPage)}.sort_by{|page|page.atom_published}
+ ret += page.index_link(cururl, depth+1)
+ end
+ ret += "\n"
+ for page in index_pages.select{|page|page.is_a?(IndexPage)}.sort_by{|page|page.atom_title}
+ ret += page.index_link(cururl, depth+1)
+ end
+ ret += "\n"
+ return ret.gsub(/\n\n+/, "\n\n")
+ end
def atom_title
_metadata['title']
end
diff --git a/lib/page_remote.rb b/lib/page_remote.rb
index e886283..87f8207 100644
--- a/lib/page_remote.rb
+++ b/lib/page_remote.rb
@@ -29,7 +29,7 @@ class RemotePage < Page
return nil
end
- def page_cagetories
+ def page_categories
@metadata['categories'] || []
end
@@ -52,4 +52,8 @@ class RemotePage < Page
def page_years
return []
end
+
+ def index_class
+ return 'external'
+ end
end
diff --git a/src/index.yaml b/src/index.yaml
index 535f810..4106fdf 100644
--- a/src/index.yaml
+++ b/src/index.yaml
@@ -1,15 +1 @@
-title: ""
-sections:
- "writing": "Writing"
- "dnd": "Dungeons & Dragons"
- "prog": "Programming"
-external:
- - title: "365 Tomorrows: A Simple Lament"
- 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"
- tags: [DM, WP]
+title: "AndrewDM"
diff --git a/tmpl/index.md.erb b/tmpl/index.md.erb
index 680647d..2febcb5 100644
--- a/tmpl/index.md.erb
+++ b/tmpl/index.md.erb
@@ -3,5 +3,4 @@ title: "<%= atom_title %>"
class: "index"
---
-<% index_pages.sort_by{|a|a.atom_published}.reverse.each do |a| %>
- * <span><a <% if a.is_a?(RemotePage) %>class="external" <% end %>href="<%= Config::get.url.route_to(a.url) %>" title="Published on <%= a.atom_published.strftime('%Y-%m-%d') %><% if a.atom_updated != a.atom_published %> (updated on<%= a.atom_updated.strftime('%Y-%m-%d') %>)<% end %>"><%= a.title %></a></span><span><% a.atom_categories.each do |t| %><%= t.html %><% end %></span><% end %>
+<%= index_link(url, 1) %>