Created
April 16, 2018 14:04
-
-
Save pmk1c/f192dd30edba2a25c9f352d1e8df8234 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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