ignore more temp files
[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 technotes_list = []
62 Dir.glob('../technical-notes/*.md').sort.each do |file|
63 technotes_list << techpost(file)
64 end
65
66 stdpage('technical-notes', <<EOF)
67 <ul class="site-nav-list">
68 #{technotes_list.join("\n")}
69 </ul>
70 EOF
71
72
73 # main reference doc https://validator.w3.org/feed/docs/atom.html
74 # Reference doc says updated should be last time it changed
75 # but jekyll's rss feed just uses current time, which is easier to get,
76 # so meh, i'll just use that.
77 fwrite('feed.xml', <<EOF)
78 <?xml version="1.0" encoding="UTF-8"?>
79 <feed xmlns="http://www.w3.org/2005/Atom" >
80 <author>
81 <name>Ian Kelling</name>
82 <uri>#{DURL}</uri>
83 </author>
84 <id>#{DURL}</id>
85 <link rel="self" href="#{DURL}"/>
86 <title>Ian Kelling's Blog</title>
87 <updated>#{Time.now.to_datetime.rfc3339}</updated>
88 #{feed_entries.join("\n")}
89 </feed>
90 EOF
91
92 fskel('index.html', DN, File.read('../index.html'))
93
94 stdpage('blog', <<EOF)
95 <ul class="site-nav-list">
96 #{blog_list.join("\n")}
97 </ul>
98 EOF
99
100 if File.exists? ('../resume.md')
101 stdpage('resume', md_to_html(File.read('../resume.md')))
102 end
103
104 stdpage('favorite-things', File.read('../favorite-things.html'))
105 stdpage('about-me', File.read('../about-me.html'))
106
107 # we could use ruby native stuff here, but this was
108 # better documented so meh.
109 # Force because it's cache is not perfect, it definitely misses renamed symlinks.
110
111 ret = 0
112 ["main", "gitweb-site"].each do |basename|
113 cmd = "scss --force --cache-location ../.sass-cache"
114 unless system("#{cmd} ../css/#{basename}.scss css/#{basename}.css")
115 ret = 1
116 end
117 end
118
119 exit ret