middleman / middleman-blog

Blog Engine Extension for Middleman
https://middlemanapp.com
MIT License
325 stars 179 forks source link

Support i18n mount_at_root option in permalinks #364

Open pmk1c opened 6 years ago

pmk1c commented 6 years ago

It would be great if Middleman Blog could handle the mount_at_root option given by the :i18n extension. For example by providing an option to prepend the i18n path root to the articles permalinks.

In one of our projects we have a configuration like this:

# config.rb
activate :i18n, mount_at_root: :de, langs: [:de, :en]

activate :blog do |blog|
  blog.name = 'blog'
  blog.prefix = "{lang}/blog"
  blog.permalink = "{title}.html"
  blog.sources = "{title}.html"
end

With this configuration all german ("de") pages are mounted at root, but the german blog posts are found under /de/blog/…

So for reaching our goal, that the blog posts can be found under /blog/… while the english blog posts remain at /en/blog/…, we use the following configuration and prepend the i18n path root within our own extension:

# config.rb
activate :i18n, mount_at_root: :de, langs: [:de, :en]

activate :blog do |blog|
  blog.name = 'blog'
  blog.sources = "{lang}/blog/{title}.html"
  blog.permalink = "{blog}/{title}.html"
end

activate :blog_prepend_i18n_path do |config|
  config.blog_name = 'blog'
end

This is the extensions code: https://gist.github.com/pmk1c/f192dd30edba2a25c9f352d1e8df8234

So one way for Middleman Blog to fully support :i18n could be to add a configuration option, that prepends the i18n path root to the permalinks of the articles. Leading to a configuration like this:

# config.rb
activate :i18n, mount_at_root: :de, langs: [:de, :en]

activate :blog do |blog|
  blog.name = 'blog'
  blog.sources = "{lang}/blog/{title}.html"
  blog.permalink = "{blog}/{title}.html"
  blog.prepend_i18n_path_root = true
end

But maybe there are better options to support mount_at_root. I'm open for discussion and I'd like to send a PR for this, if we find a solution.

UnclePetros commented 6 years ago

Hello, thank you for this post. It is just what I'm looking for. However I'm relatively new to ruby, so I need a little help in order to install your extension. Here what I've done: I've executed command middleman extension blog_prepend_i18n_path Then I've replaced file in lib directory with your own file (that is blog_prepend_i18n_path.rb). Then I've added values in blog_prepend_i18n_path.gemspec files and I've executed bundle install. All went fine. But extension seems not to be installed in my system, so middleman give an error when building.

Is there anything I forgot?

Thank you.

Regards Pietro

pmk1c commented 5 years ago

You don't need to run middleman extensions blog_prepend_i18n_path. All you have to do is to copy our extension to i.e. your lib folder. Then you can require it in your config.rb file:

# config.rb
require 'lib/blog_prepend_i18n_path'

activate :blog do |config|
  config.blog_name = 'blog'
  …
end

activate :blog_prepend_i18n_path do |config|
  config.blog_name = 'blog'
end

We won't be publishing this hack as a gem. Since we'd rather have middleman-blog handle this in a less hacky way.

markets commented 4 months ago

ℹ️ This issue is stale because it has been open for more than 90 days with no activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.