Jekyll 3 upgrade + syntax

parent 24336c41
ietemplates/ ietemplates/
_site/*
...@@ -13,7 +13,7 @@ kramdown: ...@@ -13,7 +13,7 @@ kramdown:
smart_quotes: ["apos", "apos", "quot", "quot"] smart_quotes: ["apos", "apos", "quot", "quot"]
exclude: ["README.md"] exclude: ["README.md"]
gems: [jekyll-paginate]
paginate: 10 paginate: 10
paginate_path: blog/page:num/ paginate_path: blog/page:num/
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
# attributes in the _config.yml file # attributes in the _config.yml file
# #
# Uses the following attributes in _config.yml: # 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_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_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) # 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,156 +22,143 @@ ...@@ -21,156 +22,143 @@
module Jekyll module Jekyll
class Xml < Page; end
class TileFile < StaticFile
def write(dest)
true
end
end
class TileTemplater < Generator class TileTemplater < Generator
priority :low priority :low
safe true safe true
require 'builder'
# Entry method # Entry method
def generate(site) def generate(site)
generate_config(site) # create tile config file
generate_templates(site) 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
count = [posts.docs.length, 4].min
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 end
end
# Generates ieconfig.xml
def generate_config(site)
# 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 # polling xml
xml = Builder::XmlMarkup.new( :indent=>2) class TilePoll < StaticFile
xml.instruct! :xml, :encoding=>"utf-8" def initialize(site, base, dir, name, post)
super(site, base, dir, name, nil)
xml.browserconfig do |config| @post = post
config.msapplication do |app| end
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
# Create file and add to site
name = "ieconfig.xml"
dest = File.join(site.dest, "/ietemplates/")
validate_dir(dest) def write(dest)
# post.render(site.layouts, site.site_payload)
File.open("#{dest}#{name}", "w") { |f| f.write(xml.target!) } # Create directory if doesn't exist
poll_dir = File.join(dest, @dir)
site.static_files << Jekyll::TileFile.new(site, site.dest, "/ietemplates/", name) FileUtils.mkdir_p(poll_dir)
end
# Build xml tile templates
xml = Builder::XmlMarkup.new( :indent => 2)
xml.instruct! :xml, :encoding => "utf-8"
# Generates tile templates xml.tile do |tile|
def generate_templates(site) tile.visual("lang"=>"en-US", "version"=>"2") do |v|
count = [site.posts.count, 4].min v.binding("template"=>"TileSquare150x150Text04", "branding"=>"logo", "fallback"=>"TileSquareImage") do |b|
b.tag!("text", @post['title'], "id"=>"1")
site.posts.reverse[0..count].each_with_index do |post, index| end
post.render(site.layouts, site.site_payload) v.binding("template"=>"TileWide310x150Text03", "branding"=>"logo", "fallback"=>"TileWideImage") do |b|
b.tag!("text", @post['title'], "id"=>"1")
# Build xml tile templates end
xml = Builder::XmlMarkup.new( :indent => 2) v.binding("template"=>"TileSquare310x310TextList02", "branding"=>"logo", "fallback"=>"TileWideText09") do |b|
xml.instruct! :xml, :encoding => "utf-8" b.tag!("text", @post['title'], "id"=>"1")
b.tag!("text", shorten(strip(@post.content)),"id"=>"2")
xml.tile do |tile| b.tag!("text", "#{@post.date.month}-#{@post.date.day}-#{@post.date.year}", "id"=>"3")
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")
end
v.binding("template"=>"TileWide310x150Text03", "branding"=>"logo", "fallback"=>"TileWideImage") do |b|
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")
end
end end
end end
end
# Create file and add to site poll_path = File.join(poll_dir, @name)
name = "poll#{index+1}.xml" File.open(poll_path, "w") { |f| f.write(xml.target!) }
dest = File.join(site.dest, "/ietemplates/") end
validate_dir(dest)
File.open("#{dest}#{name}", "w") { |f| f.write(xml.target!) } private
site.static_files << Jekyll::TileFile.new(site, site.dest, "/ietemplates/", name)
# Shortens string and adds trailing ellipsis
def shorten(str, count = 30)
if str.length >= count
return str[0, count] << "..."
end end
return str
end 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 # sets ie 11 configs
def validate_path(path) class TileConfig < StaticFile;
path[0] == "/" ? path : "/#{path}" def initialize(site, base, dir, name)
path[path.length-1] == "/" ? path : "#{path}/" super(site, base, dir, name)
return path
end end
def write(dest)
require 'builder'
# Validates directory exists, else creates directory # configs
def validate_dir(dir) tile_color = @site.config["ie_tile_color"] || "#000000"
FileUtils.mkdir_p(dir) tile_small = @site.config["ie_tile_small"]
end 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 # create dir for tile config
def shorten(string, count = 30) config_dir = File.join(dest, @dir)
if string.length >= count FileUtils.mkdir_p(config_dir)
shortened = string[0, count]
splitted = shortened.split(/\s/)
words = splitted.length
splitted[0, words-1].join(" ") + '...'
else
string
end
end
# Strips html tags (not the best) # build xml config
def strip(string) xml = Builder::XmlMarkup.new( :indent=>2)
string.gsub!(/<("[^"]*"|'[^']*'|[^'">])*>/, "") xml.instruct! :xml, :encoding=>"utf-8"
end
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
end # write file
config_path = File.join(config_dir, @name)
File.open(config_path, "w") { |f| f.write(xml.target!) }
end
end
end end
\ No newline at end of file
...@@ -39,7 +39,7 @@ module Jekyll ...@@ -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 we have an @, pass the string through the markdown converter, so that we hit the Moneropedia plugin
if translation.include? '@' if translation.include? '@'
converter = site.getConverterImpl(::Jekyll::Converters::Markdown) converter = site.find_converter_instance(::Jekyll::Converters::Markdown)
translation = converter.convert(translation)[3..-6] translation = converter.convert(translation)[3..-6]
end end
......
...@@ -10,37 +10,28 @@ ...@@ -10,37 +10,28 @@
# Site: http://www.kinnetica.com # Site: http://www.kinnetica.com
# Distributed Under A Creative Commons License # Distributed Under A Creative Commons License
# - http://creativecommons.org/licenses/by/3.0/ # - http://creativecommons.org/licenses/by/3.0/
require 'jekyll/document'
require 'rexml/document' require 'rexml/document'
module Jekyll module Jekyll
class Post class Jekyll::Document
attr_accessor :name attr_accessor :name
def full_path_to_source
File.join(@base, @name)
end
def path_to_source def path_to_source
File.join(@name) File.join(*[@name].compact)
end end
def location_on_server(my_url) def location_on_server(my_url)
location = "#{my_url}#{url}" "#{my_url}#{url}"
location.gsub(/index.html$/, "")
end end
end end
class Page class Page
attr_accessor :name attr_accessor :name
def full_path_to_source
File.join(@base, @dir, @name)
end
def path_to_source def path_to_source
File.join(@dir, @name) File.join(*[@dir, @name].compact)
end end
def location_on_server(my_url) def location_on_server(my_url)
...@@ -49,13 +40,6 @@ module Jekyll ...@@ -49,13 +40,6 @@ module Jekyll
end end
end end
class Layout
def full_path_to_source
File.join(@base, @name)
end
end
# Recover from strange exception when starting server without --auto # Recover from strange exception when starting server without --auto
class SitemapFile < StaticFile class SitemapFile < StaticFile
def write(dest) def write(dest)
...@@ -120,15 +104,15 @@ module Jekyll ...@@ -120,15 +104,15 @@ module Jekyll
# #
# Returns last_modified_date of latest post # Returns last_modified_date of latest post
def fill_posts(site, urlset) def fill_posts(site, urlset)
last_modified_date = nil last_modified_date = nil
site.posts.each do |post| site.collections["posts"].docs.each do |post|
if !excluded?(site, post.name) if !excluded?(site, post.name)
url = fill_url(site, post) url = fill_url(site, post)
urlset.add_element(url) urlset.add_element(url)
end end
path = post.full_path_to_source date = File.mtime(post.path)
date = File.mtime(path)
last_modified_date = date if last_modified_date == nil or date > last_modified_date last_modified_date = date if last_modified_date == nil or date > last_modified_date
end end
...@@ -142,8 +126,7 @@ module Jekyll ...@@ -142,8 +126,7 @@ module Jekyll
def fill_pages(site, urlset) def fill_pages(site, urlset)
site.pages.each do |page| site.pages.each do |page|
if !excluded?(site, page.path_to_source) if !excluded?(site, page.path_to_source)
path = page.full_path_to_source if File.exists?(page.path)
if File.exists?(path)
url = fill_url(site, page) url = fill_url(site, page)
urlset.add_element(url) urlset.add_element(url)
end end
...@@ -151,7 +134,7 @@ module Jekyll ...@@ -151,7 +134,7 @@ module Jekyll
end end
end end
# Fill data of each URL element: location, last modified, # Fill data of each URL element: location, last modified,
# change frequency (optional), and priority. # change frequency (optional), and priority.
# #
# Returns url REXML::Element # Returns url REXML::Element
...@@ -199,9 +182,7 @@ module Jekyll ...@@ -199,9 +182,7 @@ module Jekyll
def fill_location(site, page_or_post) def fill_location(site, page_or_post)
loc = REXML::Element.new "loc" loc = REXML::Element.new "loc"
url = site.config['url'] + site.config['baseurl'] url = site.config['url'] + site.config['baseurl']
loc.text = page_or_post.location_on_server(url)
# the Monero site is served "extensionless", so lose the extensions
loc.text = page_or_post.location_on_server(url).gsub('.html', '').gsub('.php', '')
loc loc
end end
...@@ -210,10 +191,8 @@ module Jekyll ...@@ -210,10 +191,8 @@ module Jekyll
# #
# Returns lastmod REXML::Element or nil # Returns lastmod REXML::Element or nil
def fill_last_modified(site, page_or_post) def fill_last_modified(site, page_or_post)
path = page_or_post.full_path_to_source
lastmod = REXML::Element.new "lastmod" 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) latest_date = find_latest_date(date, site, page_or_post)
if @last_modified_post_date == nil if @last_modified_post_date == nil
...@@ -240,8 +219,7 @@ module Jekyll ...@@ -240,8 +219,7 @@ module Jekyll
layouts = site.layouts layouts = site.layouts
layout = layouts[page_or_post.data["layout"]] layout = layouts[page_or_post.data["layout"]]
while layout while layout
path = layout.full_path_to_source date = File.mtime(layout.path)
date = File.mtime(path)
latest_date = date if (date > latest_date) 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