summaryrefslogtreecommitdiff
path: root/lib/page_index.rb
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2017-01-06 19:50:45 -0500
committerLuke Shumaker <lukeshu@sbcglobal.net>2017-01-06 19:50:45 -0500
commit7edb003cd1c9b53ffdff11ef85532e39f08db16d (patch)
tree180db82a4af7720508ae2732393401bf4d27cadf /lib/page_index.rb
parent7d875df65221d4da91953cf129a03e76fe8e5d29 (diff)
wip
Diffstat (limited to 'lib/page_index.rb')
-rw-r--r--lib/page_index.rb63
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/page_index.rb b/lib/page_index.rb
new file mode 100644
index 0000000..073537e
--- /dev/null
+++ b/lib/page_index.rb
@@ -0,0 +1,63 @@
+# coding: utf-8
+require 'erb'
+require 'set'
+require 'yaml'
+
+require 'page_local'
+require 'page_remote'
+require 'config'
+
+class IndexPage < LocalPage
+ def initialize(dirname)
+ super(dirname)
+ end
+
+ def _metadata
+ if @metadata.nil?
+ yamlfile = _infile+"/index.yaml"
+ if File::exist?(yamlfile)
+ @metadata = YAML::load(File::read(yamlfile))
+ else
+ @metadata = {}
+ end
+ end
+ @metadata
+ end
+ def _ls
+ @ls ||= Dir::entries(_infile)
+ .select{|fname|not fname.start_with?(".")}
+ .map{|fname|"#{_infile}/#{fname}"}
+ .select{|path|Dir::exist?(path) or Config::get.html_suffixes.include?(File::extname(path).gsub(/^[.]/, ''))}
+ end
+ def pages
+ if @pages.nil?
+ @pages = []
+ for path in _ls
+ if Dir::exist?(path)
+ page = IndexPage::new(path)
+ @pages.unshift(page)
+ @pages += page.pages
+ else
+ @pages.unshift(LocalPage::new(path))
+ end
+ end
+ for data in _metadata['external']
+ @pages.unshift(RemotePage::new(data))
+ end
+ end
+ @pages
+ end
+
+ def _published
+ return nil
+ end
+ def _updated
+ return nil
+ end
+ def _years
+ return Set[]
+ end
+end
+
+ERB::new(File::read("tmpl/index.atom.erb")).def_method(IndexPage, 'atom()', "tmpl/index.atom.erb")
+ERB::new(File::read("tmpl/index.md.erb")).def_method(IndexPage, '_input()', "tmpl/index.md.erb")