1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
| | # Copyright (C) 2015-2016 all contributors <olddoc-public@80x24.org>
# License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
require 'builder'
module Olddoc::NewsAtom # :nodoc:
include Olddoc::History
include Olddoc::Readme
# generates an Atom feed based on git tags in the document directory
def news_atom_xml
project_name, short_desc, _ = readme_metadata
new_tags = tags[0,10]
atom_uri = @rdoc_uri.dup
atom_uri.path += "NEWS.atom.xml"
news_uri = @rdoc_uri.dup
news_uri.path += "NEWS.html"
x = Builder::XmlMarkup.new
x.feed(xmlns: "http://www.w3.org/2005/Atom") do
x.id(atom_uri.to_s)
x.title("#{project_name} news")
x.subtitle(short_desc)
x.link(rel: 'alternate', type: 'text/html', href: news_uri.to_s)
x.updated(new_tags.empty? ? '1970-01-01:00:00:00Z' : new_tags[0][:time])
new_tags.each do |tag|
x.entry do
x.title(tag[:subject])
x.updated(tag[:time])
x.published(tag[:time])
x.author do
x.name(tag[:tagger_name])
x.email(tag[:tagger_email])
end
uri = tag_uri(tag[:tag]).to_s
x.link(rel: "alternate", type: 'text/html', href: uri)
x.id(uri)
x.content(type: :xhtml) do
x.div(xmlns: 'http://www.w3.org/1999/xhtml') do
x.pre(tag[:body])
end
end
end # entry
end # new_tags
end # feed
[ x.target!, new_tags ]
end
def news_atom(dest = "NEWS.atom.xml")
xml, new_tags = news_atom_xml
File.open(dest, "w") { |fp| fp.write(xml) }
unless new_tags.empty?
time = new_tags[0][:ruby_time]
File.utime(time, time, dest)
end
end
end
|