summaryrefslogtreecommitdiff
path: root/lib
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 /lib
parent4a3a404a5cb2a8d5be83e28cec5c539928fa30f4 (diff)
index local_input
Diffstat (limited to 'lib')
-rw-r--r--lib/page.rb16
-rw-r--r--lib/page_index.rb29
-rw-r--r--lib/page_remote.rb6
3 files changed, 40 insertions, 11 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