Skip to content

Instantly share code, notes, and snippets.

@pmk1c
Created April 16, 2018 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmk1c/f192dd30edba2a25c9f352d1e8df8234 to your computer and use it in GitHub Desktop.
Save pmk1c/f192dd30edba2a25c9f352d1e8df8234 to your computer and use it in GitHub Desktop.
class BlogPrependI18nPath < Middleman::Extension
option :blog_name, 'blog'
def after_configuration
manipulator = Manipulator.new(@app, options)
@app.sitemap.register_resource_list_manipulator(:"fix_i18n_article_paths_#{options.blog_name}", manipulator)
end
class Manipulator
def initialize(app, options)
@app = app
@options = options
end
def manipulate_resource_list(resources)
blog.data.articles.each do |article|
language_path = i18n.path_root(article.locale).gsub(%r{^/}, '')
destination_path = Pathname(language_path).join(article.destination_path).to_s
article.destination_path = destination_path
end
resources
end
private
def blog
@blog ||= @app.extensions[:blog].values.find { |i| i.options.name == @options.blog_name }
end
def i18n
@i18n ||= @app.extensions[:i18n]
end
end
end
::Middleman::Extensions.register(:blog_prepend_i18n_path, BlogPrependI18nPath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment