-
Notifications
You must be signed in to change notification settings - Fork 3
/
make.rb
57 lines (47 loc) · 1.53 KB
/
make.rb
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
56
57
# -*- coding: utf-8 -*-
require "nokogiri"
require "erb"
require "net/http"
require "icalendar"
require "rss"
require "action_view"
require "redcarpet"
include ActionView::Helpers::DateHelper
Encoding.default_external = "UTF-8"
# fetch page
# re-assemble it into template
# <h2><span class="mw-headline"
# suck in https://labitat.dk/events.ics
#
def make_section(page, title)
sibs = []
el = page.at(%|h1:contains("#{title}")|)
while el = el.next_element
break if el.name == "h1"
sibs << el.to_html
end
sibs.join("\n")
end
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true)
home_page = Nokogiri::HTML(File.read("out/home_page.html"))
about_section = make_section(home_page, "About")
events_section = make_section(home_page, "Events")
connect_section = make_section(home_page, "Connect")
just_visit_us_section = make_section(home_page, "Just Visit Us!")
everything_else_section = make_section(home_page, "Everything else")
template = ERB.new File.read("template.erb")
uri = URI("https://labitat.dk/events.ics")
calendar = Net::HTTP.get(uri)
cal = Icalendar::Calendar.parse(calendar.force_encoding(Encoding::UTF_8)).first
count = 0
events = cal.events.select { |e| e.dtstart > Time.now }.first(5)
wiki_changes = []
url = "https://labitat.dk/w/api.php?hidebots=1&days=30&limit=6&action=feedrecentchanges&feedformat=atom"
URI.open(url) do |rss|
feed = RSS::Parser.parse(rss)
feed.items.each do |item|
wiki_changes << item
end
end
result = template.result
File.write("build/out.html", result)