Currently running into a problem where the blog tag pages do no have the locale included in the URL (thereby ignoring whatever the current language selected is). I think this could be related to i18n, but not sure.
For example, I want the tag page to show up as {lang}/blog/tags/{tag}.html
but it appears the {lang} variable is being ignored. I tried making a function with the blog activation script, but that caused other problems, so I dropped that idea.
The result is that, when clicking a tag (such as Python) it shows every instance of that article (the Japanese, English, and German versions) on a single page. Obviously I want it to only show the current locale, but because the language is being ignored, it’s just grabbing all of them.
Any thoughts on how to fix? Middleman 4 by the way.
Config.rb:
# Page options, layouts, aliases and proxies
activate :syntax
activate :i18n do |i18n|
i18n.path = "/:locale/"
i18n.langs = [:en, :de, :ja]
i18n.lang_map = { :en => :en, :de => :de, :ja => :ja }
i18n.templates_dir = "content"
i18n.mount_at_root = false
end
set :css_dir, './assets/css'
set :js_dir, './assets/js'
# set :images_dir, 'assets/images'
config[:url_root] = 'https://georepublic.info'
# config[:js_dir] = 'assets'
# config[:css_dir] = 'assets'
config[:fonts_dir] = 'assets'
config[:images_dir] = 'assets'
config[:layouts_dir] = 'layouts'
# Per-page layout changes:
# With no layout
page '/*.xml', layout: false
page '/*.json', layout: false
page '/*.txt', layout: false
page "/feed.xml", layout: false
page "/sitemap.xml", layout: false
# With alternative layout
page "/*/error/*.html", :layout => :layout_simple
page "/*/contact/*.html", :layout => :layout_simple
page "/*/imprint/*.html", :layout => :layout_simple
page "/*/disclaimer/*.html", :layout => :layout_simple
page "/*/company/jobs/*.html", :layout => :layout_simple
page "/*/blog/index.html", :layout => :layout_blog_list
# page "/*/blog/p*/*.html", :layout => :layout_blog_list
page "/*/blog/**/*.html", :layout => :layout_blog_article
page "/index.*", :layout => false
page "/*/blog/feed.xml", :layout => false, :directory_index => false
page "/*/contact/send.php", :layout => false, :directory_index => false
page "/*/services/*.html", :layout => :layout_page
page "/*/products/*.html", :layout => :layout_page
page "/*/projects/*.html", :layout => :layout_page
# Ignore certain directories to be generated by the builder
ignore "includes/*"
ignore "*/blog/calendar.html"
ignore "/*/company/newsletter/*"
page "/**/*.html", :layout => :layout_page
# 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" }
###
# Blog
###
activate :blog do |blog|
# This will add a prefix to all links, template references and source paths
blog.prefix = "{lang}/blog/"
blog.default_extension = "md"
blog.permalink = "{year}/{title}"
blog.sources = "{year}/{year}-{month}-{day}-{title}"
blog.summary_generator = nil
# blog.summary_separator = /(READMORE)/
blog.summary_separator = /READMORE/
blog.summary_length = 250
blog.publish_future_dated = false
#tags
blog.taglink = "/tags/{tag}.html"
# blog.taglink = cur_lang("blog/tags/{tag}.html")
blog.tag_template = "content/blog/layout_tag.html"
# blog.tag_template = "content/blog/tag_base.html"
# Enable pagination
blog.paginate = true
blog.per_page = 6
blog.page_link = "p{num}"
end
helpers do
# Returns a localized path with leading language code
def local_path(path, options={})
lang = options[:language] ? options[:language] : I18n.locale.to_s
"/#{lang}/#{path}"
end
# Returns all pages under a certain directory.
def sub_pages(dir, options={})
lang = options[:language] ? options[:language] : I18n.locale.to_s
sitemap.resources.select do |resource|
resource.url.start_with?("/#{lang}/#{dir}/")
end
end
# Returns certain page (ends with directory).
def find_pages(dir, options={})
lang = options[:language] ? options[:language] : I18n.locale.to_s
sitemap.resources.select do |resource|
resource.url.end_with?("/#{lang}/#{dir}/")
end
end
end
configure :development do
activate :livereload do |reload|
reload.no_swf = true
end
end
configure :production do
activate :minify_html
activate :asset_hash, ignore: [/\.jpg\Z/, /\.png\Z/, /\.svg\Z/]
end
# MUST be after :18n and :blog activation
activate :directory_indexes
activate :external_pipeline,
name: :webpack,
command: build? ? 'npm run build' : 'npm run watch',
source: ".tmp/dist",
latency: 1