mirror of
https://github.com/monero-project/monero-site.git
synced 2024-12-14 04:16:35 +02:00
Merge pull request #87 from mikemcdonald/jekyll3-upgrade
Jekyll3 upgrade
This commit is contained in:
commit
169a09b4c8
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +1,2 @@
|
|||||||
ietemplates/
|
ietemplates/
|
||||||
|
_site/*
|
||||||
|
@ -27,7 +27,7 @@ Pages and formats should be based off existing pages to maintain a consistent lo
|
|||||||
|
|
||||||
## Deployment
|
## Deployment
|
||||||
|
|
||||||
Deploying this website requires Jekyll (2.5+) and the following ruby gems: builder, rubysl-rexml
|
Deploying this website requires Jekyll (3.0+) and the following ruby gems: builder, rubysl-rexml, jekyll-paginate
|
||||||
|
|
||||||
Multiple language support will be added soon.
|
Multiple language support will be added soon.
|
||||||
|
|
||||||
|
@ -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 @@
|
|||||||
# 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,44 +22,116 @@
|
|||||||
|
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
# Create directory if doesn't exist
|
||||||
|
poll_dir = File.join(dest, @dir)
|
||||||
|
FileUtils.mkdir_p(poll_dir)
|
||||||
|
|
||||||
|
|
||||||
|
# Build xml tile templates
|
||||||
|
xml = Builder::XmlMarkup.new( :indent => 2)
|
||||||
|
xml.instruct! :xml, :encoding => "utf-8"
|
||||||
|
|
||||||
|
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")
|
||||||
|
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(strip(@post.content)),"id"=>"2")
|
||||||
|
b.tag!("text", "#{@post.date.month}-#{@post.date.day}-#{@post.date.year}", "id"=>"3")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
poll_path = File.join(poll_dir, @name)
|
||||||
|
File.open(poll_path, "w") { |f| f.write(xml.target!) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# Generates ieconfig.xml
|
private
|
||||||
def generate_config(site)
|
|
||||||
|
|
||||||
# Configs
|
# Shortens string and adds trailing ellipsis
|
||||||
if site.config["ie_tile_color"]
|
def shorten(str, count = 30)
|
||||||
tile_color = "\##{site.config["ie_tile_color"]}"
|
if str.length >= count
|
||||||
else
|
return str[0, count] << "..."
|
||||||
tile_color = "#000000"
|
|
||||||
end
|
end
|
||||||
frequency = site.config["ie_frequency"] || 1440
|
return str
|
||||||
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"]
|
|
||||||
|
|
||||||
# Build xml config
|
# Strips html tags (not the best)
|
||||||
|
def strip(string)
|
||||||
|
string.gsub(/<[^>]*>/, "")
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# sets ie 11 configs
|
||||||
|
class TileConfig < StaticFile;
|
||||||
|
def initialize(site, base, dir, name)
|
||||||
|
super(site, base, dir, name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def write(dest)
|
||||||
|
require 'builder'
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
# create dir for tile config
|
||||||
|
config_dir = File.join(dest, @dir)
|
||||||
|
FileUtils.mkdir_p(config_dir)
|
||||||
|
|
||||||
|
|
||||||
|
# build xml config
|
||||||
xml = Builder::XmlMarkup.new( :indent=>2)
|
xml = Builder::XmlMarkup.new( :indent=>2)
|
||||||
xml.instruct! :xml, :encoding=>"utf-8"
|
xml.instruct! :xml, :encoding=>"utf-8"
|
||||||
|
|
||||||
@ -83,94 +156,9 @@ module Jekyll
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Create file and add to site
|
# write file
|
||||||
name = "ieconfig.xml"
|
config_path = File.join(config_dir, @name)
|
||||||
dest = File.join(site.dest, "/ietemplates/")
|
File.open(config_path, "w") { |f| f.write(xml.target!) }
|
||||||
|
|
||||||
validate_dir(dest)
|
|
||||||
|
|
||||||
File.open("#{dest}#{name}", "w") { |f| f.write(xml.target!) }
|
|
||||||
|
|
||||||
site.static_files << Jekyll::TileFile.new(site, site.dest, "/ietemplates/", name)
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Generates tile templates
|
|
||||||
def generate_templates(site)
|
|
||||||
count = [site.posts.count, 4].min
|
|
||||||
|
|
||||||
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)
|
|
||||||
xml.instruct! :xml, :encoding => "utf-8"
|
|
||||||
|
|
||||||
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")
|
|
||||||
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
|
|
||||||
|
|
||||||
# Create file and add to site
|
|
||||||
name = "poll#{index+1}.xml"
|
|
||||||
dest = File.join(site.dest, "/ietemplates/")
|
|
||||||
|
|
||||||
validate_dir(dest)
|
|
||||||
|
|
||||||
File.open("#{dest}#{name}", "w") { |f| f.write(xml.target!) }
|
|
||||||
site.static_files << Jekyll::TileFile.new(site, site.dest, "/ietemplates/", name)
|
|
||||||
|
|
||||||
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
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
# Validates directory exists, else creates directory
|
|
||||||
def validate_dir(dir)
|
|
||||||
FileUtils.mkdir_p(dir)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
|
|
||||||
# Strips html tags (not the best)
|
|
||||||
def strip(string)
|
|
||||||
string.gsub!(/<("[^"]*"|'[^']*'|[^'">])*>/, "")
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
end
|
@ -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 @@
|
|||||||
# 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
|
|||||||
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
|
|||||||
#
|
#
|
||||||
# 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
|
|||||||
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
|
|||||||
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
|
|||||||
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
|
|||||||
#
|
#
|
||||||
# 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
|
|||||||
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)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user