From c274f8b4c83cd841bd05a768b8b59442dae69a58 Mon Sep 17 00:00:00 2001
From: NikaZhenya
Date: Wed, 3 Oct 2018 23:17:11 -0500
Subject: [PATCH] Creation of 'build.rb'
---
build.rb | 113 +++++-
css/extra.css | 44 ++-
css/styles.css | 812 ++++++++++++++++++++++++++++++++++++++
html/entry001.html | 56 +++
html/entry002.html | 56 +++
index.html | 45 +++
md/entry001.md | 27 +-
template/footer.html | 19 +-
template/head.html | 6 +-
template/header.html | 3 +-
ttf/bitter-bold.ttf | Bin 0 -> 68284 bytes
ttf/bitter-bolditalic.ttf | Bin 0 -> 74528 bytes
ttf/bitter-italic.ttf | Bin 0 -> 74200 bytes
ttf/bitter-regular.ttf | Bin 0 -> 71920 bytes
14 files changed, 1136 insertions(+), 45 deletions(-)
create mode 100644 css/styles.css
create mode 100644 html/entry001.html
create mode 100644 html/entry002.html
create mode 100644 index.html
create mode 100644 ttf/bitter-bold.ttf
create mode 100644 ttf/bitter-bolditalic.ttf
create mode 100644 ttf/bitter-italic.ttf
create mode 100644 ttf/bitter-regular.ttf
diff --git a/build.rb b/build.rb
index 47da13a..02122b5 100644
--- a/build.rb
+++ b/build.rb
@@ -6,6 +6,8 @@ require 'fileutils'
require 'time'
require 'json'
+# Also requires Pecas
+
Encoding.default_internal = Encoding::UTF_8
Dir.chdir(File.dirname(__FILE__))
@@ -19,6 +21,9 @@ $site_img = 'icon.png'
$author_name = 'Nika Zhenya'
$author_email = 'nika.zhenya@cliteratu.re'
$date = Time.now.to_s.split(' ')[0]
+$head = `cat template/head.html`
+$header = `cat template/header.html`
+$footer = `cat template/footer.html`
$rss = {
:channel => {
:title => $site_name,
@@ -61,6 +66,36 @@ def get_date d, rfc = false
end
end
+# Replaces strings
+def replace_content content, title = 'Main'
+ elements = [
+ ['language', $language],
+ ['site_name', $site_name],
+ ['site_description', $site_description],
+ ['site_keywords', $site_keywords],
+ ['site_link', $site_link],
+ ['site_img', $site_img],
+ ['author_name', $author_name],
+ ['author_email', $author_email],
+ ['date', get_date($date)],
+ ['title', title]
+ ]
+
+ elements.each do |e|
+ content = content.gsub("$#{e[0]}$", e[1])
+ end
+
+ if content.split("\n")[0] == ''
+ content = content.gsub("Mariana Eguaras's blog", "Mariana Eguaras's blog")
+ end
+
+ if title == 'Main'
+ content.gsub!('href="../', 'href="')
+ end
+
+ return content
+end
+
# Converts MD in other formats
def convert_md md
content = []
@@ -75,10 +110,14 @@ def convert_md md
:pubDate => ''
}
+ # Gets properties from MD
def item_split s
return s.gsub(/@\S+\['(.*?)'\]/, '\1').strip.split('\',\'')
end
+ puts "Building '" + File.basename(md) + "'…"
+
+ # Analizes MD
file = File.open(md, 'r:UTF-8')
file.each_with_index do |l, i|
if i == 0
@@ -87,27 +126,59 @@ def convert_md md
if l =~ /^@original\[.*?\]\s*?$/
data = item_split(l)
- content.push(
- 'Spanish: ' +
- get_date(data[0]) + ' | ' +
- '' +
- 'source
'
- )
elsif l =~ /^@current\[.*?\]\s*?$/
data = item_split(l)
item[:pubDate] = get_date(data[0], true)
item[:category] = data[1]
item[:description] = data[2]
content.push(
- 'English: ' +
+ '
' +
get_date(data[0]) + ' | ' +
- data[1] + '
'
+ data[1] + ' | ' +
+ 'EPUB / ' +
+ 'MOBI / ' +
+ 'original' +
+ '
'
)
else
content.push(l)
end
end
+ # Creates an MD with some changes
+ html_name = 'html/' + File.basename(md, '.*') + '.html'
+ new_md_name = 'html/' + File.basename(md)
+ new_md = File.new(new_md_name, 'w:UTF-8')
+ new_md.puts content
+ new_md.close
+
+ # Converts MD to HTML
+ system("pc-pandog -i #{new_md_name} -o #{html_name}")
+ FileUtils.rm(new_md_name)
+
+ # EPUB and MOBI goes here
+
+ # Changes some things for the final HTML
+ write = false
+ new_html = []
+ html = File.open(html_name, 'r:UTF-8')
+ html.each do |l|
+ if write && l !~ /^\s*