diff --git a/build.rb b/build.rb index 9522e9a..0e38a85 100644 --- a/build.rb +++ b/build.rb @@ -6,24 +6,25 @@ require 'fileutils' require 'time' require 'json' -# Also requires Pecas +#=> Also requires Inkscape and Pecas Encoding.default_internal = Encoding::UTF_8 Dir.chdir(File.dirname(__FILE__)) -# Variables +#=> Variables $language = 'en-US' +$mariana = 'Mariana Eguaras\'s blog' $site_name = 'Publishing is Coding: Change My Mind' -$site_description = 'A broken english version of some entries published in Mariana Eguaras\'s blog.' +$site_description = 'A broken english version of some entries published in ' + $mariana + '.' $site_keywords = 'publishing, blog, book, ebook, methodology, foss, libre-software, format, markdown, html, epub, pdf, mobi, latex, tex' $site_link = 'https://blog.cliteratu.re' $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` +$head = File.read('template/site/head.html') +$header = File.read('template/site/header.html') +$footer = File.read('template/site/footer.html') $rss = { :channel => { :title => $site_name, @@ -40,10 +41,11 @@ $rss = { :items => [] } } +$xml = [] -# Definitions +#=> Definitions -# Gets date in a proper format +# Gets date in proper format def get_date d, rfc = false d = d.split('-') @@ -82,24 +84,28 @@ def replace_content content, title = 'Main' ] elements.each do |e| - content = content.gsub("$#{e[0]}$", e[1]) + content.gsub!("$#{e[0]}$", e[1]) end if content.split("\n")[0] == '
' - content = content.gsub("Mariana Eguaras's blog", "Mariana Eguaras's blog") + content.gsub!($mariana, "#{$mariana}") end - if title == 'Main' - content.gsub!('href="../', 'href="') - end + if title == 'Main' then content.gsub!('href="../', 'href="') end return content end +# Changes file content +def change_file url, content + file = File.new(url, 'w:UTF-8') + file.puts content + file.close +end + # Converts MD in other formats def convert_md md - content = [] - original = {:link => '', :pubDate => ''} + md_content = [] item = { :guid => $site_link + '/html/' + File.basename(md, '.*'), :title => '', @@ -124,98 +130,129 @@ def convert_md md item[:title] = l.gsub(/^#/, '').strip end - if l =~ /^@original\[.*?\]\s*?$/ - data = item_split(l) - elsif l =~ /^@current\[.*?\]\s*?$/ + if l =~ /^@meta\[.*?\]\s*?$/ data = item_split(l) item[:pubDate] = get_date(data[0], true) item[:category] = data[1] item[:description] = data[2] - content.push( + md_content.push( '

' + get_date(data[0]) + ' | ' + data[1] + ' | ' + - 'EPUB / ' + - 'MOBI / ' + + 'EPUB / ' + + 'MOBI / ' + 'original' + '

' ) else - content.push(l) + md_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 + # Everything is gonna be created in a temporary directory + Dir.mkdir('tmp') + Dir.chdir('tmp') - # Converts MD to HTML + # Some variables that are going to be used + html_name = '../html/' + File.basename(md, '.*') + '.html' + new_md_name = File.basename(md) + cover_url = '../../template/ebooks/' + + # Creates an MD with some changes so it can be converted to HTML + change_file(new_md_name, md_content) system("pc-pandog -i #{new_md_name} -o #{html_name}") - FileUtils.rm(new_md_name) - # EPUB and MOBI goes here + # Will convert HTML to EPUB and MOBI + system("pc-automata --init") + Dir.chdir('epub-automata') - # 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* + + +
+ Imagen de portada +
+ + diff --git a/template/footer.html b/template/site/footer.html similarity index 100% rename from template/footer.html rename to template/site/footer.html diff --git a/template/head.html b/template/site/head.html similarity index 88% rename from template/head.html rename to template/site/head.html index 9db4cf2..e95f44d 100644 --- a/template/head.html +++ b/template/site/head.html @@ -8,7 +8,7 @@ - + diff --git a/template/header.html b/template/site/header.html similarity index 100% rename from template/header.html rename to template/site/header.html