middleman-template/config.rb

237 lines
6.6 KiB
Ruby

# encoding: UTF-8
# vim: set noet sw=2 ts=2:
###
# Page options, layouts, aliases and proxies
###
require 'asciidoctor'
require 'middleman-asciidoc'
require 'active_support/all'
require 'awesome_print'
require 'font-awesome-sass'
require_relative 'lib/adoc'
require_relative 'lib/gallery'
Haml::TempleEngine.disable_option_validator!
#env = ENV['TARGET'].to_s.downcase
config[:css_dir] = '/assets/styles'
config[:js_dir] = '/assets/scripts'
config[:images_dir] = 'assets/images'
config[:sass_assets_paths] += Array.wrap(FontAwesome::Sass.stylesheets_path)
require 'yaml'
require_relative 'lib/repertoire.rb'
$repertoire = Repertoire.build YAML.load( File.read( 'db/repertoire.yml'), 'db/repertoire.yml', symbolize_names: true)
# Per-page layout changes:
#
# With no layout
page '*.xml', layout: false
page '*.json', layout: false
page '*.txt', layout: false
page 'events/*', layout: :events, data: {type: :events, blog: :events}
page 'gallery/*/*/*/*/*/index.html', layout: :album_image, data: {type: :album_image, blog: :gallery}
page 'gallery/*', layout: :gallery, data: {type: :gallery, blog: :gallery}
page '*.html', layout: :page
#page 'gallery/**/*.webp', layout: false, data: {type: :image}
#page 'gallery/**/*.jpeg', layout: false, data: {type: :image}
ignore '**/.*.sw?'
ignore '.*.sw?'
# With alternative layout
# page "/path/to/file.html", layout: :otherlayout
# Proxy pages (http://middlemanapp.com/basics/dynamic-pages/)
# proxy "/this-page-has-no-template.html", "/template-file.html", locals: {
# which_fake_page: "Rendering a fake page with a local variable" }
# General configuration
activate :i18n, mount_at_root: :de
# Reload the browser automatically whenever files change
configure :development do
activate :livereload
end
configure :production do
activate :deploy,
deploy_method: :rsync,
host: '....',
path: '....',
build_before: true
end
configure :development do
activate :deploy,
deploy_method: :rsync,
host: '....',
path: '....',
build_before: false
end
activate :external_pipeline,
name: :assets,
command: 'rake assets',
source: "assets/build"
#activate :external_pipeline,
# name: :gallery_images,
# command: 'rake gallery:all',
# source: '.cache/gallery'
activate :blog do |events|
# This will add a prefix to all links, template references and source paths
events.name = :events
events.prefix = '/events'
events.permalink = "{year}/{month}/{day}/{title}"
#Matcher for blog source files
#events.sources = "{year}-{month}-{day}-{title}.html"
#events.taglink = "tags/{tag}.html"
events.layout = :events
events.summary_separator = /(READMORE)/
events.summary_length = 256
events.year_link = "{year}.html"
events.month_link = "{year}/{month}.html"
events.day_link = "{year}/{month}/{day}.html"
events.default_extension = ".adoc"
events.tag_template = "tag.html"
events.calendar_template = "calendar.html"
events.publish_future_dated = true
# Enable pagination
events.paginate = true
events.per_page = 20
events.page_link = "page/{num}"
end
activate :blog do |gal|
gal.name = :gallery
gal.prefix = '/gallery'
gal.permalink = "{year}/{month}/{day}/{title}"
gal.sources = "{year}-{month}-{day}-{title}/index.html"
gal.layout = :gallery
gal.default_extension = ".adoc"
gal.paginate = true
gal.per_page = 20
gal.page_link = "page/{num}"
end
activate :asciidoc do |adoc|
adoc.template_dirs = ['asciidoctor-backends/haml/html5']
adoc.template_engine = 'haml'
adoc.template_cache = false
adoc.attributes = {
'source-highlighter' => 'coderay',
'fa-music' => 'pass:[<i class="fas fa-music"></i>]',
'fa-paint-brush' => 'pass:[<i class="fas fa-paint-brush"></i>]',
'ldquo' => "",
'rdquo' => "",
#'template_dirs': ['asciidoctor-backends/haml/html5'],
#'template_engine': 'haml',
#'template_cache': false
}
end
activate :directory_indexes
activate :fonts4web
activate :fonts_css
###
# Helpers
###
helpers do
Months = %w[Jänner Februar März April Mai Juni Juli August September Oktober November Dezember]
def longdate_at time_or_date
d = time_or_date
h = {day: d.day, month: Months[d.month-1], year: d.year}
s =
if Time === d and [d.hour, d.min].any? {|i| 0!=i}
h = h.update hour: d.hour, min: d.min, sec: d.sec
"%<day>d. %<month>s %<year>d %<hour>02d:%<min>02d"
else
"%<day>d. %<month>s %<year>d"
end
s % h
end
def post_times times, alt_time = nil
times =
Array.wrap(times).map do |time|
case time
when Time, Date
{time: time}
when String
{time: Time.parse( time)}
when Hash, Middleman::Util::EnhancedHash
case time[:time]
when Time, Date
time
when String
time.merge time: Time.parse( time[:time])
else
raise "A Time/Date or String-representation as `when.time`-entry expected. Given: #{time[:time].inspect}"
end
else
raise "A Time/Date/String-representation or Hash with time-entry for that as `when`-entry expected. Given: #{time.inspect}"
end
end.map do |t|
if t[:time].beginning_of_day == t
t.merge time: t[:time].to_date
else
t
end
end
times = [{time: alt_time}] if times.empty?
times
end
def active_page? uri
x = [uri.to_s, current_page.url].map {|u| Pathname.new URI.parse(u).path.sub( %r!(.+?)/.*\z!, "\\1") }
x.first == x.last
end
end
# Build-specific configuration
configure :production do
# Minify CSS on build
activate :minify_css
# Minify Javascript on build
activate :minify_javascript
activate :minify_html, preserve_line_breaks: true
end
activate :asset_hash, exts: %w(.css .js)
MiniMagick.configure do |config|
config.cli = :graphicsmagick
config.timeout = 5
end
activate :gallery do |g|
g.basepath = 'source/gallery'
g.thumbnail_size = '256x256'
end
# Historisch waren die Veranstaltungen unter /blog zu finden, statt unter /events:
([''] + %w[2019/02/28/lovefails/ 2019/02/28/ 2019/02/
2019/03/23/klavierkonzert/ 2019/03/23/ 2019/03/
2019/11/16/klaviermatinee-mit-russischer-musik/ 2019/11/16/ 2019/11/
2019/05/17/klavierfestival-wotrubakirche/ 2019/05/17/ 2019/05/
2019/04/29/an-american-in-vienna/ 2019/04/29/ 2019/04/
2019/
2020/02/09/klavierabend-mit-russischer-musik/ 2020/02/09/ 2020/02/
2020/03/15/duo-hudler-grube/ 2020/03/15/
2020/03/19/heimathaus-brunn/ 2020/03/19/ 2020/03/
2020/09/20/klavierabend-breitenfurt/ 2020/09/20/ 2020/09/
2020/10/10/pop-up-konzert/ 2020/10/10/
2020/10/25/pop-up-konzert/ 2020/10/25/ 2020/10/
2020/05/08/klavierfestival-wotrubakirche-2020/ 2020/05/08/ 2020/05/
2020/
2021/04/24/1-kunstlergesprach/
2021/04/24/2-konzert-perchtoldsdorf/ 2021/04/24/ 2021/04/
2021/
tags/konzert/ page/2/
]).each {|d| redirect "blog/#{d}index.html".gsub(%r<//>, '/'), to: "/events/#{d}".gsub(%r<//>, '/') }