Jekyll 3 upgrade + syntax

parent 24336c41
......@@ -13,7 +13,7 @@ kramdown:
smart_quotes: ["apos", "apos", "quot", "quot"]
exclude: ["README.md"]
gems: [jekyll-paginate]
paginate: 10
paginate_path: blog/page:num/
......
......@@ -4,6 +4,7 @@
# attributes in the _config.yml file
#
# Uses the following attributes in _config.yml:
# ie_category: - (optional) poll only a specific category of posts
# ie_frequency: - (optional) the frequency of site polling. Options are {30,60,360,720,1440}. Default is 1440 (1 day)
# ie_tile_color: - (optional) the color of the windows 8 pinned background tile
# ie_tile_small: - location of small tile image (For more information of tile sizes visit http://msdn.microsoft.com/en-us/library/dn455106(v=vs.85).aspx)
......@@ -21,87 +22,47 @@
module Jekyll
class Xml < Page; end
class TileFile < StaticFile
def write(dest)
true
end
end
class TileTemplater < Generator
priority :low
safe true
require 'builder'
# Entry method
def generate(site)
generate_config(site)
generate_templates(site)
end
# create tile config file
site.static_files << TileConfig.new(site, site.source, "/ietemplates/", "ieconfig.xml")
# create tile poll files
# create at most 4
category = site.config["ie_category"]
posts = !category ? site.posts : site.categories.has_key?(category) ? site.categories[category] : site.posts
# Generates ieconfig.xml
def generate_config(site)
count = [posts.docs.length, 4].min
# Configs
if site.config["ie_tile_color"]
tile_color = "\##{site.config["ie_tile_color"]}"
else
tile_color = "#000000"
end
frequency = site.config["ie_frequency"] || 1440
tile_small = site.config["ie_tile_small"]
tile_medium = site.config["ie_tile_medium"]
tile_wide = site.config["ie_tile_wide"]
tile_large = site.config["ie_tile_large"]
# Build xml config
xml = Builder::XmlMarkup.new( :indent=>2)
xml.instruct! :xml, :encoding=>"utf-8"
xml.browserconfig do |config|
config.msapplication do |app|
app.tile do |tile|
tile.tag!("square70x70logo", "src"=>"#{tile_small}")
tile.tag!("square150x150logo", "src"=>"#{tile_medium}")
tile.tag!("wide310x150logo", "src"=>"#{tile_wide}")
tile.tag!("square310x310logo", "src"=>"#{tile_large}")
tile.tag!("TileColor", "#{tile_color}")
end
app.notification do |n|
n.tag!("polling-uri", "src"=>"/ietemplates/poll1.xml")
n.tag!("polling-uri2", "src"=>"/ietemplates/poll2.xml")
n.tag!("polling-uri3", "src"=>"/ietemplates/poll3.xml")
n.tag!("polling-uri4", "src"=>"/ietemplates/poll4.xml")
n.tag!("polling-uri5", "src"=>"/ietemplates/poll5.xml")
n.tag!("frequency", "#{frequency}")
n.tag!("cycle", "1")
end
posts.docs.reverse[0..count].each_with_index do |post, index|
site.static_files << TilePoll.new(site, site.source, "/ietemplates/", "poll#{index+1}.xml", post)
end
end
# Create file and add to site
name = "ieconfig.xml"
dest = File.join(site.dest, "/ietemplates/")
end
validate_dir(dest)
File.open("#{dest}#{name}", "w") { |f| f.write(xml.target!) }
site.static_files << Jekyll::TileFile.new(site, site.dest, "/ietemplates/", name)
# polling xml
class TilePoll < StaticFile
def initialize(site, base, dir, name, post)
super(site, base, dir, name, nil)
@post = post
end
def write(dest)
# post.render(site.layouts, site.site_payload)
# Generates tile templates
def generate_templates(site)
count = [site.posts.count, 4].min
# Create directory if doesn't exist
poll_dir = File.join(dest, @dir)
FileUtils.mkdir_p(poll_dir)
site.posts.reverse[0..count].each_with_index do |post, index|
post.render(site.layouts, site.site_payload)
# Build xml tile templates
xml = Builder::XmlMarkup.new( :indent => 2)
......@@ -110,67 +71,94 @@ module Jekyll
xml.tile do |tile|
tile.visual("lang"=>"en-US", "version"=>"2") do |v|
v.binding("template"=>"TileSquare150x150Text04", "branding"=>"logo", "fallback"=>"TileSquareImage") do |b|
b.tag!("text", post.title, "id"=>"1")
b.tag!("text", @post['title'], "id"=>"1")
end
v.binding("template"=>"TileWide310x150Text03", "branding"=>"logo", "fallback"=>"TileWideImage") do |b|
b.tag!("text", post.title, "id"=>"1")
b.tag!("text", @post['title'], "id"=>"1")
end
v.binding("template"=>"TileSquare310x310TextList02", "branding"=>"logo", "fallback"=>"TileWideText09") do |b|
b.tag!("text", post.title, "id"=>"1")
b.tag!("text", shorten(post.data["summary"]),"id"=>"2")
b.tag!("text", "#{post.date.month}-#{post.date.day}-#{post.date.year}", "id"=>"3")
b.tag!("text", @post['title'], "id"=>"1")
b.tag!("text", shorten(strip(@post.content)),"id"=>"2")
b.tag!("text", "#{@post.date.month}-#{@post.date.day}-#{@post.date.year}", "id"=>"3")
end
end
end
# Create file and add to site
name = "poll#{index+1}.xml"
dest = File.join(site.dest, "/ietemplates/")
poll_path = File.join(poll_dir, @name)
File.open(poll_path, "w") { |f| f.write(xml.target!) }
end
validate_dir(dest)
File.open("#{dest}#{name}", "w") { |f| f.write(xml.target!) }
site.static_files << Jekyll::TileFile.new(site, site.dest, "/ietemplates/", name)
private
# Shortens string and adds trailing ellipsis
def shorten(str, count = 30)
if str.length >= count
return str[0, count] << "..."
end
return str
end
# Strips html tags (not the best)
def strip(string)
string.gsub(/<[^>]*>/, "")
end
end
private
# Validates path to make sure there is a leading and trailing slash
def validate_path(path)
path[0] == "/" ? path : "/#{path}"
path[path.length-1] == "/" ? path : "#{path}/"
return path
# sets ie 11 configs
class TileConfig < StaticFile;
def initialize(site, base, dir, name)
super(site, base, dir, name)
end
def write(dest)
require 'builder'
# Validates directory exists, else creates directory
def validate_dir(dir)
FileUtils.mkdir_p(dir)
end
# configs
tile_color = @site.config["ie_tile_color"] || "#000000"
tile_small = @site.config["ie_tile_small"]
tile_medium = @site.config["ie_tile_medium"]
tile_wide = @site.config["ie_tile_wide"]
tile_large = @site.config["ie_tile_large"]
frequency = @site.config["ie_frequency"] || 1440
raise "frequency must be either 30, 60, 360, 720, 1440" unless [30,60,360,720,1440].include?(frequency)
# Shortens string and adds trailing ellipsis
def shorten(string, count = 30)
if string.length >= count
shortened = string[0, count]
splitted = shortened.split(/\s/)
words = splitted.length
splitted[0, words-1].join(" ") + '...'
else
string
end
end
# create dir for tile config
config_dir = File.join(dest, @dir)
FileUtils.mkdir_p(config_dir)
# Strips html tags (not the best)
def strip(string)
string.gsub!(/<("[^"]*"|'[^']*'|[^'">])*>/, "")
end
# build xml config
xml = Builder::XmlMarkup.new( :indent=>2)
xml.instruct! :xml, :encoding=>"utf-8"
xml.browserconfig do |config|
config.msapplication do |app|
app.tile do |tile|
tile.tag!("square70x70logo", "src"=>"#{tile_small}")
tile.tag!("square150x150logo", "src"=>"#{tile_medium}")
tile.tag!("wide310x150logo", "src"=>"#{tile_wide}")
tile.tag!("square310x310logo", "src"=>"#{tile_large}")
tile.tag!("TileColor", "#{tile_color}")
end
app.notification do |n|
n.tag!("polling-uri", "src"=>"/ietemplates/poll1.xml")
n.tag!("polling-uri2", "src"=>"/ietemplates/poll2.xml")
n.tag!("polling-uri3", "src"=>"/ietemplates/poll3.xml")
n.tag!("polling-uri4", "src"=>"/ietemplates/poll4.xml")
n.tag!("polling-uri5", "src"=>"/ietemplates/poll5.xml")
n.tag!("frequency", "#{frequency}")
n.tag!("cycle", "1")
end
end
end
# write file
config_path = File.join(config_dir, @name)
File.open(config_path, "w") { |f| f.write(xml.target!) }
end
end
end
\ No newline at end of file
......@@ -39,7 +39,7 @@ module Jekyll
# If we have an @, pass the string through the markdown converter, so that we hit the Moneropedia plugin
if translation.include? '@'
converter = site.getConverterImpl(::Jekyll::Converters::Markdown)
converter = site.find_converter_instance(::Jekyll::Converters::Markdown)
translation = converter.convert(translation)[3..-6]
end
......
......@@ -10,37 +10,28 @@
# Site: http://www.kinnetica.com
# Distributed Under A Creative Commons License
# - http://creativecommons.org/licenses/by/3.0/
require 'jekyll/document'
require 'rexml/document'
module Jekyll
class Post
class Jekyll::Document
attr_accessor :name
def full_path_to_source
File.join(@base, @name)
end
def path_to_source
File.join(@name)
File.join(*[@name].compact)
end
def location_on_server(my_url)
location = "#{my_url}#{url}"
location.gsub(/index.html$/, "")
"#{my_url}#{url}"
end
end
class Page
attr_accessor :name
def full_path_to_source
File.join(@base, @dir, @name)
end
def path_to_source
File.join(@dir, @name)
File.join(*[@dir, @name].compact)
end
def location_on_server(my_url)
......@@ -49,13 +40,6 @@ module Jekyll
end
end
class Layout
def full_path_to_source
File.join(@base, @name)
end
end
# Recover from strange exception when starting server without --auto
class SitemapFile < StaticFile
def write(dest)
......@@ -120,15 +104,15 @@ module Jekyll
#
# Returns last_modified_date of latest post
def fill_posts(site, urlset)
last_modified_date = nil
site.posts.each do |post|
site.collections["posts"].docs.each do |post|
if !excluded?(site, post.name)
url = fill_url(site, post)
urlset.add_element(url)
end
path = post.full_path_to_source
date = File.mtime(path)
date = File.mtime(post.path)
last_modified_date = date if last_modified_date == nil or date > last_modified_date
end
......@@ -142,8 +126,7 @@ module Jekyll
def fill_pages(site, urlset)
site.pages.each do |page|
if !excluded?(site, page.path_to_source)
path = page.full_path_to_source
if File.exists?(path)
if File.exists?(page.path)
url = fill_url(site, page)
urlset.add_element(url)
end
......@@ -199,9 +182,7 @@ module Jekyll
def fill_location(site, page_or_post)
loc = REXML::Element.new "loc"
url = site.config['url'] + site.config['baseurl']
# the Monero site is served "extensionless", so lose the extensions
loc.text = page_or_post.location_on_server(url).gsub('.html', '').gsub('.php', '')
loc.text = page_or_post.location_on_server(url)
loc
end
......@@ -210,10 +191,8 @@ module Jekyll
#
# Returns lastmod REXML::Element or nil
def fill_last_modified(site, page_or_post)
path = page_or_post.full_path_to_source
lastmod = REXML::Element.new "lastmod"
date = File.mtime(path)
date = File.mtime(page_or_post.path)
latest_date = find_latest_date(date, site, page_or_post)
if @last_modified_post_date == nil
......@@ -240,8 +219,7 @@ module Jekyll
layouts = site.layouts
layout = layouts[page_or_post.data["layout"]]
while layout
path = layout.full_path_to_source
date = File.mtime(path)
date = File.mtime(layout.path)
latest_date = date if (date > latest_date)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment