Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support i18n mount_at_root option in permalinks #364

Open
pmk1c opened this issue Apr 16, 2018 · 3 comments
Open

Support i18n mount_at_root option in permalinks #364

pmk1c opened this issue Apr 16, 2018 · 3 comments

Comments

@pmk1c
Copy link

pmk1c commented Apr 16, 2018

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
Copy link

UnclePetros commented Jun 8, 2018

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
Copy link
Author

pmk1c commented Sep 17, 2018

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.

@github-actions github-actions bot added the Stale label Apr 11, 2024
@markets
Copy link
Member

markets commented Apr 15, 2024

ℹ️ 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.

@github-actions github-actions bot removed the Stale label Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants