Init
This commit is contained in:
commit
72067ba038
19 changed files with 7758 additions and 0 deletions
8
lib/blogging.rb
Normal file
8
lib/blogging.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
module Nanoc3::Helpers::Blogging
|
||||
# Patch to add analytics param to feed urls
|
||||
alias url_for_without_analytics url_for
|
||||
def url_for(item)
|
||||
url = url_for_without_analytics(item)
|
||||
url.sub(/(\.html|\/)$/, '') + '?utm_source=feed'
|
||||
end
|
||||
end
|
12
lib/default.rb
Normal file
12
lib/default.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require 'nanoc/cachebuster'
|
||||
require 'slim'
|
||||
require 'redcarpet'
|
||||
|
||||
include Nanoc3::Helpers::Rendering
|
||||
include Nanoc3::Helpers::XMLSitemap
|
||||
include Nanoc3::Helpers::Blogging
|
||||
include Nanoc3::Helpers::Filtering
|
||||
include Nanoc3::Helpers::LinkTo
|
||||
include Nanoc3::Helpers::CacheBusting
|
||||
|
||||
Slim::Engine.set_default_options pretty: true
|
9
lib/markdown_html.rb
Normal file
9
lib/markdown_html.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
require 'pygments.rb'
|
||||
|
||||
RubyPython.start python_exe: 'python2.6' if ENV['RACK_ENV'] == 'production'
|
||||
|
||||
class MarkdownHTML < Redcarpet::Render::HTML
|
||||
def block_code(code, language)
|
||||
Pygments.highlight(code, lexer: language)
|
||||
end
|
||||
end
|
86
lib/meta.rb
Normal file
86
lib/meta.rb
Normal file
|
@ -0,0 +1,86 @@
|
|||
# Source: https://github.com/avdgaag/nanoc-template/blob/master/lib/preprocessors.rb
|
||||
|
||||
|
||||
# Generate a sitemap.xml file using Nanoc's own xml_sitemap helper method by
|
||||
# dynamically adding a new item.
|
||||
#
|
||||
# Make items that should not appear in the sitemap hidden. This by default
|
||||
# works on all image files and typical assets, as well as error pages and
|
||||
# htaccess. The is_hidden attribute is only explicitly set if it is absent,
|
||||
# allowing per-file overriding.
|
||||
#
|
||||
# @todo extract hidden file types into configuration file?
|
||||
def create_sitemap
|
||||
return unless @site.config[:output_generated_assets]
|
||||
|
||||
@items.each do |item|
|
||||
if %w{png gif jpg jpeg coffee scss sass less css xml js txt ico}.include?(item[:extension]) ||
|
||||
item.identifier =~ /404|500|htaccess/
|
||||
item[:is_hidden] = true unless item.attributes.has_key?(:is_hidden)
|
||||
end
|
||||
end
|
||||
@items << Nanoc3::Item.new(
|
||||
"<%= xml_sitemap %>",
|
||||
{ :extension => 'xml', :is_hidden => true },
|
||||
'/sitemap/'
|
||||
)
|
||||
end
|
||||
|
||||
# Use special settings from the site configuration to generate the files
|
||||
# necessary for various webmaster tools authentications, such as the services
|
||||
# from Google, Yahoo and Bing.
|
||||
#
|
||||
# This loops through all the items in the `webmaster_tools` setting, using
|
||||
# its properties to generate a new item.
|
||||
#
|
||||
# See config.yaml for more documentation on the input format.
|
||||
def create_webmaster_tools_authentications
|
||||
return unless @site.config[:output_generated_assets]
|
||||
|
||||
@site.config[:webmaster_tools].each do |file|
|
||||
next if file[:identifier].nil?
|
||||
content = file.delete(:content)
|
||||
identifier = file.delete(:identifier)
|
||||
file.merge!(:is_hidden => true)
|
||||
@items << Nanoc3::Item.new(
|
||||
content,
|
||||
file,
|
||||
identifier
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
# Generate a robots.txt file in the root of the site by dynamically creating
|
||||
# a new item.
|
||||
#
|
||||
# This will either output a default robots.txt file, that disallows all
|
||||
# assets except images, and points to the sitemap file.
|
||||
#
|
||||
# You can override the contents of the output of this method using the site
|
||||
# configuration, specifying Allow and Disallow directives. See the config.yaml
|
||||
# file for more information on the expected input format.
|
||||
def create_robots_txt
|
||||
return unless @site.config[:output_generated_assets]
|
||||
|
||||
if @site.config[:robots]
|
||||
content = if @site.config[:robots][:default]
|
||||
<<-EOS
|
||||
User-agent: *
|
||||
Allow: *
|
||||
Sitemap: #{@site.config[:base_url]}/sitemap.xml
|
||||
EOS
|
||||
else
|
||||
[
|
||||
'User-Agent: *',
|
||||
@site.config[:robots][:disallow].map { |l| "Disallow: #{l}" },
|
||||
(@site.config[:robots][:allow] || []).map { |l| "Allow: #{l}" },
|
||||
"Sitemap: #{@site.config[:robots][:sitemap]}"
|
||||
].flatten.compact.join("\n")
|
||||
end
|
||||
@items << Nanoc3::Item.new(
|
||||
content,
|
||||
{ :extension => 'txt', :is_hidden => true },
|
||||
'/robots/'
|
||||
)
|
||||
end
|
||||
end
|
31
lib/shellcmd.rb
Normal file
31
lib/shellcmd.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
require 'open3'
|
||||
|
||||
# This nanoc filter is a general purpose filter that simply pipes
|
||||
# the contents of an item into a given shell command, and sets
|
||||
# the items output to the output of it.
|
||||
#
|
||||
# It is NOT safe to use on large inputs, which will cause I/O
|
||||
# deadlocks. Any safer implementation is encouraged.
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# compile '/static/js/*/' do
|
||||
# # minify JS :)
|
||||
# filter :shellcmd, "java -jar js-compiler.jar"
|
||||
# end
|
||||
#
|
||||
# Written by Vincent Driessen (http://twitter.com/nvie) and
|
||||
# released to the public domain.
|
||||
#
|
||||
# http://nvie.com
|
||||
class ShellCmdFilter < Nanoc3::Filter
|
||||
identifier :shellcmd
|
||||
|
||||
def run(content, params)
|
||||
Open3.popen3(params[:cmd]) do |stdin, stdout, stderr|
|
||||
stdin.write(content)
|
||||
stdin.close
|
||||
stdout.read
|
||||
end
|
||||
end
|
||||
end
|
76
lib/xml_sitemap.rb
Normal file
76
lib/xml_sitemap.rb
Normal file
|
@ -0,0 +1,76 @@
|
|||
# Source: https://github.com/ddfreyne/nanoc/blob/master/lib/nanoc/helpers/xml_sitemap.rb
|
||||
# hacked to remove trailing slash
|
||||
module Nanoc::Helpers
|
||||
|
||||
# Contains functionality for building XML sitemaps that will be crawled by
|
||||
# search engines. See the [Sitemaps protocol site](http://www.sitemaps.org)
|
||||
# for details.
|
||||
module XMLSitemap
|
||||
|
||||
# Builds an XML sitemap and returns it.
|
||||
#
|
||||
# The following attributes can optionally be set on items to change the
|
||||
# behaviour of the sitemap:
|
||||
#
|
||||
# * `changefreq` — The estimated change frequency as defined by the
|
||||
# Sitemaps protocol
|
||||
#
|
||||
# * `priority` — The item's priority, ranging from 0.0 to 1.0, as defined
|
||||
# by the Sitemaps protocol
|
||||
#
|
||||
# The sitemap will also include dates on which the items were updated.
|
||||
# These are generated automatically; the way this happens depends on the
|
||||
# used data source (the filesystem data source checks the file mtimes, for
|
||||
# instance).
|
||||
#
|
||||
# The site configuration will need to have the following attributes:
|
||||
#
|
||||
# * `base_url` — The URL to the site, without trailing slash. For example,
|
||||
# if the site is at "http://example.com/", the `base_url` would be
|
||||
# "http://example.com".
|
||||
#
|
||||
# @example Excluding binary items from the sitemap
|
||||
#
|
||||
# <%= xml_sitemap :items => @items.reject{ |i| i[:is_hidden] || i.binary? } %>
|
||||
#
|
||||
# @option params [Array] :items A list of items to include in the sitemap
|
||||
#
|
||||
# @return [String] The XML sitemap
|
||||
def xml_sitemap(params={})
|
||||
require 'builder'
|
||||
|
||||
# Extract parameters
|
||||
items = params[:items] || @items.reject { |i| i[:is_hidden] }
|
||||
|
||||
# Create builder
|
||||
buffer = ''
|
||||
xml = Builder::XmlMarkup.new(:target => buffer, :indent => 2)
|
||||
|
||||
# Check for required attributes
|
||||
if @site.config[:base_url].nil?
|
||||
raise RuntimeError.new("The Nanoc::Helpers::XMLSitemap helper requires the site configuration to specify the base URL for the site.")
|
||||
end
|
||||
|
||||
# Build sitemap
|
||||
xml.instruct!
|
||||
xml.urlset(:xmlns => 'http://www.sitemaps.org/schemas/sitemap/0.9') do
|
||||
# Add item
|
||||
items.each do |item|
|
||||
item.reps.reject { |r| r.raw_path.nil? }.each do |rep|
|
||||
xml.url do
|
||||
xml.loc @site.config[:base_url] + rep.path.sub(/(\.html|\/)$/, '')
|
||||
xml.lastmod item.mtime.to_iso8601_date unless item.mtime.nil?
|
||||
xml.changefreq item[:changefreq] unless item[:changefreq].nil?
|
||||
xml.priority item[:priority] unless item[:priority].nil?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Return sitemap
|
||||
buffer
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue