1
1
mirror of https://github.com/NixOS/mobile-nixos.git synced 2024-12-11 09:04:01 +03:00

doc: Add RSS generation

This commit is contained in:
Samuel Dionne-Riel 2019-12-02 17:18:47 -05:00
parent 74f421bab3
commit 810e18a758
5 changed files with 79 additions and 0 deletions

View File

@ -27,6 +27,10 @@ Processor::Sitemap
.new(Processor::Page.get_sitemap)
.generate()
Processor::RSS
.new(Processor::Page.get_sitemap)
.generate()
# Copying the styles, as needed
if $options["styles_dir"] then
puts "[s] Copying styles"

View File

@ -5,5 +5,6 @@ require_relative "processor/article"
require_relative "processor/footer"
require_relative "processor/header"
require_relative "processor/page"
require_relative "processor/rss"
require_relative "processor/sitemap"
require_relative "processor/toc"

View File

@ -0,0 +1,54 @@
require "date"
module Processor
# TODO: common base class or mixin with Sitemap
class RSS
Path = /^news\//
include ERB::Util
def to_rss(entries)
entry_template = ERB.new(File.read(File.join($options["root"], "_support/rss_entry.xml.erb")))
item_nodes = entries.map do |entry|
entry_template.result(binding)
end
document_template = ERB.new(File.read(File.join($options["root"], "_support/rss.xml.erb")))
document_template.result(binding)
end
attr_reader :sitemap
def strip_unneecessary(contents)
contents
.gsub(/<header.*<\/header>/m, "")
.gsub(/<footer.*<\/footer>/m, "")
end
def full_url(path)
[
"https://mobile.nixos.org",
path
].join("/")
end
def initialize(sitemap)
end
def generate()
puts "[S] Generating sitemap..."
entries = Article.get_article_paths().map do |filename|
entry = Article.new(filename)
{
title: entry.title,
url: full_url(entry.out_path),
date: entry.date,
contents: strip_unneecessary(entry.output),
}
end
File.open(File.join($options["output_dir"], "index.xml"), "w") do |file|
file.write(to_rss(entries))
end
end
end
end

11
doc/_support/rss.xml.erb Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Mobile NixOS news</title>
<description>RSS feed for Mobile NixOS</description>
<lastBuildDate><%= entries.first[:date].rfc822 %></lastBuildDate>
<link>https://mobile.nixos.org/</link>
<atom:link href="https://mobile.nixos.org/index.xml" rel="self" type="application/rss+xml"/>
<%= item_nodes.join("\n") %>
</channel>
</rss>

View File

@ -0,0 +1,9 @@
<item>
<title><%= html_escape(entry[:title]) %></title>
<pubDate><%= html_escape(entry[:date].rfc822) %></pubDate>
<link><%= html_escape(entry[:url]) %></link>
<guid><%= html_escape(entry[:url]) %></guid>
<description>
<%= html_escape(entry[:contents]) %>
</description>
</item>