diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2017-01-06 23:47:49 -0500 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2017-01-06 23:47:49 -0500 |
commit | 2db85d4d3bff943629709cacc3d976c24951b8aa (patch) | |
tree | c0218e99a0814cbec330c8ede9c821b52457fef5 /lib/page_index.rb | |
parent | 4a3a404a5cb2a8d5be83e28cec5c539928fa30f4 (diff) |
index local_input
Diffstat (limited to 'lib/page_index.rb')
-rw-r--r-- | lib/page_index.rb | 29 |
1 files changed, 19 insertions, 10 deletions
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 |