summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2017-01-09 17:09:27 -0500
committerLuke Shumaker <lukeshu@sbcglobal.net>2017-01-09 17:09:27 -0500
commita70b39250252962df17670cee743d01d1a6f7c16 (patch)
tree58c390dfd181953cb790d3edfc57e79a5406ff08 /lib
parent5022d1a0df1534b1cbec1cbee23568f201ea1cc6 (diff)
fix
Diffstat (limited to 'lib')
-rw-r--r--lib/page.rb4
-rw-r--r--lib/page_index.rb9
-rw-r--r--lib/page_local.rb4
-rw-r--r--lib/person.rb2
-rw-r--r--lib/sitegen.rb26
5 files changed, 19 insertions, 26 deletions
diff --git a/lib/page.rb b/lib/page.rb
index 98223c5..20f9701 100644
--- a/lib/page.rb
+++ b/lib/page.rb
@@ -1,4 +1,5 @@
# coding: utf-8
+require 'erb'
require 'set'
require 'category'
@@ -97,3 +98,6 @@ class Page
ret += "</span>\n"
end
end
+
+ERB::new(File::read("tmpl/page.atom.erb")).def_method(Page, 'atom()', "tmpl/page.atom.erb")
+ERB::new(File::read("tmpl/page.html.erb")).def_method(Page, 'html()', "tmpl/page.html.erb")
diff --git a/lib/page_index.rb b/lib/page_index.rb
index fed7e5f..66b528a 100644
--- a/lib/page_index.rb
+++ b/lib/page_index.rb
@@ -3,9 +3,10 @@ require 'erb'
require 'set'
require 'yaml'
+require 'config'
require 'page_local'
require 'page_remote'
-require 'config'
+require 'person'
class IndexPage < LocalPage
def initialize(dirname)
@@ -71,6 +72,9 @@ class IndexPage < LocalPage
def atom_title
_metadata['title']
end
+ def atom_author
+ Person::new(_metadata['author'] || Config::get.default_author)
+ end
def local_intype
return 'markdown'
@@ -95,6 +99,9 @@ class IndexPage < LocalPage
end
@depends
end
+ def url
+ @outurl ||= Config::get.url + local_outfile.sub(/^out/, '').sub(/\/index\.html$/, '/')
+ end
def local_srcurl
return nil
end
diff --git a/lib/page_local.rb b/lib/page_local.rb
index da8689d..7121c8e 100644
--- a/lib/page_local.rb
+++ b/lib/page_local.rb
@@ -1,6 +1,5 @@
# coding: utf-8
require 'date'
-require 'erb'
require 'set'
require 'config'
@@ -121,6 +120,3 @@ class LocalPage < Page
@outurl ||= Config::get.url + local_outfile.sub(/^out/, '')
end
end
-
-ERB::new(File::read("tmpl/page.atom.erb")).def_method(LocalPage, 'atom()', "tmpl/page.atom.erb")
-ERB::new(File::read("tmpl/page.html.erb")).def_method(LocalPage, 'html()', "tmpl/page.html.erb")
diff --git a/lib/person.rb b/lib/person.rb
index 6882dd2..6ad1569 100644
--- a/lib/person.rb
+++ b/lib/person.rb
@@ -20,7 +20,7 @@ class Person
elsif not uri.nil?
return "<a href=\"#{uri}\">#{name}</a>"
else
- return @name
+ return name
end
end
def atom
diff --git a/lib/sitegen.rb b/lib/sitegen.rb
index 765cfbd..ca0c4bf 100644
--- a/lib/sitegen.rb
+++ b/lib/sitegen.rb
@@ -65,12 +65,14 @@ module Sitegen
when @mk[target].nil?
raise "No rule to make target '#{target}'. Stop."
when target.end_with?(".atom")
- write_ifchanged(target) do |file|
+ puts "atom #{target}"
+ write_atomic(target) do |file|
file.puts('<?xml version="1.0" encoding="utf-8"?>')
file.print(@mk[target].atom)
end
when target.end_with?(".html")
- write_ifchanged(target) do |file|
+ puts "html #{target}"
+ write_atomic(target) do |file|
file.print(@mk[target].html)
end
else
@@ -78,10 +80,9 @@ module Sitegen
end
end
- def self.write_ifchanged(outfilename)
+ def self.write_atomic(outfilename)
tmpfilename = "#{File::dirname(outfilename)}/.tmp#{File::basename(outfilename)}"
- # Write our stuff to tmpfile
FileUtils::mkdir_p(File::dirname(tmpfilename))
tmpfile = File::new(tmpfilename, 'wb')
begin
@@ -92,21 +93,6 @@ module Sitegen
raise e
end
tmpfile.close
-
- # Now see if we should replace outfile with tmpfile
- same = false
- begin
- if FileUtils::compare_file(tmpfilename, outfilename)
- same = true
- end
- rescue Errno::ENOENT
- end
-
- # And actually do so
- if same
- File::unlink(tmpfilename)
- else
- File::rename(tmpfilename, outfilename)
- end
+ File::rename(tmpfilename, outfilename)
end
end