Commit 2158ee61 authored by Maarten de Waard's avatar Maarten de Waard 🤘🏻
Browse files

fix translation_links function for changes in greenhost/website#78

parent 23b5060a
...@@ -10,10 +10,12 @@ class RecursiveNav < ::Middleman::Extension ...@@ -10,10 +10,12 @@ class RecursiveNav < ::Middleman::Extension
super super
end end
helpers do helpers do
# Return a list of links with translated versions of this page # Return a list of links with translated versions of this page
# #
# # Uses global variable `locale`, which is probably set by the config.rb (or
# maybe by I18n
# Also uses global variable current_page which is part of the sitemap
def translation_links def translation_links
links = {} links = {}
locales.select{|l| l != locale}.each do |loc| locales.select{|l| l != locale}.each do |loc|
...@@ -21,8 +23,8 @@ class RecursiveNav < ::Middleman::Extension ...@@ -21,8 +23,8 @@ class RecursiveNav < ::Middleman::Extension
# solutions for blog posts than for other pages. # solutions for blog posts than for other pages.
if current_page.path.start_with? "blog" if current_page.path.start_with? "blog"
# Check if same file exists in other language # Check if same file exists in other language
if File.exists? current_page.source_file.sub("/#{locale}/", "/#{loc}/") if File.exists? current_page.source_file.gsub(/\b#{locale}\b/, "#{loc}")
links[loc] = url_for('/' + current_page.path.sub("/#{locale}/", "/#{loc}/")) links[loc] = url_for('/' + current_page.path.gsub(/\b#{locale}\b/, "#{loc}"))
end end
else else
path = current_page.target.sub("pages/", "").sub(/([\.\/])#{locale}([\.\/])/, "\\1#{loc}\\2") path = current_page.target.sub("pages/", "").sub(/([\.\/])#{locale}([\.\/])/, "\\1#{loc}\\2")
...@@ -35,6 +37,8 @@ class RecursiveNav < ::Middleman::Extension ...@@ -35,6 +37,8 @@ class RecursiveNav < ::Middleman::Extension
links links
end end
# Test en dit is /en/ ook een /en/en/bla test.
class NavNode class NavNode
attr_reader :type attr_reader :type
attr_accessor :children attr_accessor :children
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment