#!/usr/bin/env ruby
# Copyright (C) 2016 Ian Kelling
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
require 'fileutils'
require 'time'
require 'sqlite3'
Dir.chdir(File.join(File.dirname(__FILE__), '_site'))
require_relative 'b'
include B
feed_entries = []
blog_list = [] # table data
FileUtils.mkdir_p('../proposed-comments')
FileUtils.chmod(0777, '../proposed-comments')
FileUtils.rm Dir.glob('blog/*')
$db = db_init
# date has no type affinity, since floating point (REAL) doesn't
# have an appropriate one.
$db.execute <<-SQL
create table if not exists c (
id integer primary key,
state text,
ip text,
date,
page text,
comment text
)
SQL
FileUtils.chmod(0777, '../proposed-comments/comments.sqlite')
# We assume blog entry files are prefixed by date
# so we can just sort the filenames.
Dir.glob('../blog/*.md').sort.reverse.each do |file|
[feed_entries, blog_list].zip(post(file, true)) { |arr, new| arr << new }
end
FileUtils.chmod_R(0777, 'blog')
FileUtils.mkdir_p('../comments/blog')
FileUtils.chmod_R(0777, '../comments')
# main reference doc https://validator.w3.org/feed/docs/atom.html
# Reference doc says updated should be last time it changed
# but jekyll's rss feed just uses current time, which is easier to get,
# so meh, i'll just use that.
fwrite('feed.xml', <Ian Kelling#{DURL}#{DURL}Ian Kelling's Blog#{Time.now.to_datetime.rfc3339}
#{feed_entries.join("\n")}
EOF
fskel('index.html', DN, File.read('../index.html'))
stdpage('blog', <
#{blog_list.join("\n")}
EOF
if File.exists? ('../resume.md')
stdpage('resume', md_to_html(File.read('../resume.md')))
end
stdpage('favorite-things', File.read('../favorite-things.html'))