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/
|
||||
|
||||
_site/*
|
||||
|
@ -27,7 +27,7 @@ Pages and formats should be based off existing pages to maintain a consistent lo
|
||||
|
||||
## 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.
|
||||
|
||||
|
@ -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,44 +22,116 @@
|
||||
|
||||
|
||||
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)
|
||||
# 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
|
||||
|
||||
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
|
||||
|
||||
|
||||
# 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"
|
||||
# polling xml
|
||||
class TilePoll < StaticFile
|
||||
def initialize(site, base, dir, name, post)
|
||||
super(site, base, dir, name, nil)
|
||||
|
||||
@post = post
|
||||
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
|
||||
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
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
# 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.instruct! :xml, :encoding=>"utf-8"
|
||||
|
||||
@ -83,94 +156,9 @@ module Jekyll
|
||||
end
|
||||
end
|
||||
|
||||
# Create file and add to site
|
||||
name = "ieconfig.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
|
||||
|
||||
|
||||
# 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")
|
||||
# write file
|
||||
config_path = File.join(config_dir, @name)
|
||||
File.open(config_path, "w") { |f| f.write(xml.target!) }
|
||||
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
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user