fixup gitignore
[iankelling.org] / build.rb
1 #!/usr/bin/env ruby
2 # Copyright (C) 2016 Ian Kelling
3
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 2 of the License, or
7 # (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 require 'fileutils'
18 require 'time'
19 require 'sqlite3'
20
21 Dir.chdir(File.join(File.dirname(__FILE__), '_site'))
22 require_relative 'b'
23 include B
24
25
26 feed_entries = []
27 blog_list = [] # table data
28
29
30 FileUtils.mkdir_p('../proposed-comments')
31 FileUtils.chmod(0777, '../proposed-comments')
32 FileUtils.rm Dir.glob('blog/*')
33
34 $db = db_init
35 # date has no type affinity, since floating point (REAL) doesn't
36 # have an appropriate one.
37 $db.execute <<-SQL
38 create table if not exists c (
39 id integer primary key,
40 state text,
41 ip text,
42 date,
43 page text,
44 comment text
45 )
46 SQL
47
48 FileUtils.chmod(0777, '../proposed-comments/comments.sqlite')
49
50 # We assume blog entry files are prefixed by date
51 # so we can just sort the filenames.
52 Dir.glob('../blog/*.md').sort.reverse.each do |file|
53 [feed_entries, blog_list].zip(post(file, true)) { |arr, new| arr << new }
54 end
55 FileUtils.chmod_R(0777, 'blog')
56 FileUtils.mkdir_p('../comments/blog')
57 FileUtils.chmod_R(0777, '../comments')
58
59
60 # main reference doc https://validator.w3.org/feed/docs/atom.html
61 # Reference doc says updated should be last time it changed
62 # but jekyll's rss feed just uses current time, which is easier to get,
63 # so meh, i'll just use that.
64 fwrite('feed.xml', <<EOF)
65 <?xml version="1.0" encoding="UTF-8"?>
66 <feed xmlns="http://www.w3.org/2005/Atom" >
67 <author>
68 <name>Ian Kelling</name>
69 <uri>#{DURL}</uri>
70 </author>
71 <id>#{DURL}</id>
72 <link rel="self" href="#{DURL}"/>
73 <title>Ian Kelling's Blog</title>
74 <updated>#{Time.now.to_datetime.rfc3339}</updated>
75 #{feed_entries.join("\n")}
76 </feed>
77 EOF
78
79 fskel('index.html', DN, File.read('../index.html'))
80
81 stdpage('blog', <<EOF)
82 <ul class="index">
83 #{blog_list.join("\n")}
84 </ul>
85 EOF
86
87 if File.exists? ('../resume.md')
88 stdpage('resume', md_to_html(File.read('../resume.md')))
89 end
90
91 stdpage('favorite-things', File.read('../favorite-things.html'))