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

doc: Add <head> link to RSS feed

This commit is contained in:
Samuel Dionne-Riel 2019-12-02 18:03:55 -05:00
parent 810e18a758
commit fa0a2a5734
4 changed files with 36 additions and 3 deletions

View File

@ -3,6 +3,7 @@ module Processor; end
require_relative "processor/base"
require_relative "processor/article"
require_relative "processor/footer"
require_relative "processor/head"
require_relative "processor/header"
require_relative "processor/page"
require_relative "processor/rss"

View File

@ -0,0 +1,28 @@
module Processor
class Head
attr_reader :page
attr_reader :root_relative
def initialize(page, root_relative)
@page = page
@root_relative = root_relative
end
def head()
[
'<link lang="en" rel="alternate" type="application/rss+xml" title="RSS feed (EN)" href="',
"#{root_relative}index.xml",
'" />',
].join("")
end
def append_to_head(document)
output = document.split("\n")
idx = output.find_index do |line|
line.match(/<\/head>/)
end
output.insert(idx, head)
output.join("\n")
end
end
end

View File

@ -16,12 +16,13 @@ module Processor
].join("")
end
def append_header(document)
def header()
header = ERB.new(File.read(File.join($options["root"], "_support/header.erb")))
rootrel = root_relative
header.result(binding)
end
header = header.result(binding)
def append_header(document)
output = document.split("\n")
idx = output.find_index do |line|
line.match(/<body /)

View File

@ -68,6 +68,9 @@ module Processor
# Prepare output, to make next steps more readable.
@output = @doc.convert
# Adds necessary stuff in <head />
@output = Processor::Head.new(@page, @root_relative).append_to_head(@output)
# Force the site header on the generated page.
@output = Processor::Header.new(@page, @root_relative).append_header(@output)