remove dependency on my bashrc
[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 FileUtils.rm Dir.glob('css/*')
34
35 $db = db_init
36 # date has no type affinity, since floating point (REAL) doesn't
37 # have an appropriate one.
38 $db.execute <<-SQL
39 create table if not exists c (
40 id integer primary key,
41 state text,
42 ip text,
43 date,
44 page text,
45 comment text
46 )
47 SQL
48
49 FileUtils.chmod(0777, '../proposed-comments/comments.sqlite')
50
51 # We assume blog entry files are prefixed by date
52 # so we can just sort the filenames.
53 Dir.glob('../blog/*.md').sort.reverse.each do |file|
54 [feed_entries, blog_list].zip(post(file, true)) { |arr, new| arr << new }
55 end
56 FileUtils.chmod_R(0777, 'blog')
57 FileUtils.mkdir_p('../comments/blog')
58 FileUtils.chmod_R(0777, '../comments')
59
60
61 # main reference doc https://validator.w3.org/feed/docs/atom.html
62 # Reference doc says updated should be last time it changed
63 # but jekyll's rss feed just uses current time, which is easier to get,
64 # so meh, i'll just use that.
65 fwrite('feed.xml', <<EOF)
66 <?xml version="1.0" encoding="UTF-8"?>
67 <feed xmlns="http://www.w3.org/2005/Atom" >
68 <author>
69 <name>Ian Kelling</name>
70 <uri>#{DURL}</uri>
71 </author>
72 <id>#{DURL}</id>
73 <link rel="self" href="#{DURL}"/>
74 <title>Ian Kelling's Blog</title>
75 <updated>#{Time.now.to_datetime.rfc3339}</updated>
76 #{feed_entries.join("\n")}
77 </feed>
78 EOF
79
80 fskel('index.html', DN, File.read('../index.html'))
81
82 stdpage('blog', <<EOF)
83 <ul class="site-nav-list">
84 #{blog_list.join("\n")}
85 </ul>
86 EOF
87
88 if File.exists? ('../resume.md')
89 stdpage('resume', md_to_html(File.read('../resume.md')))
90 end
91
92 stdpage('favorite-things', File.read('../favorite-things.html'))
93
94 # we could use ruby native stuff here, but this was
95 # better documented so meh.
96 # Force because it's cache is not perfect, it definitely misses renamed symlinks.
97
98 ret = 0
99 ["main", "gitweb-site"].each do |basename|
100 cmd = "scss --force --cache-location ../.sass-cache"
101 unless system("#{cmd} ../css/#{basename}.scss css/#{basename}.css")
102 ret = 1
103 end
104 end
105
106 exit ret