middleman / middleman-blog

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

Add option `localizable` to separate blog articles per locale #355

Open schmidt opened 6 years ago

schmidt commented 6 years ago

middleman-blog already supports middleman-i18n, so that blog articles can have locales assigned. This locale can be used in the path. And it is used in the article and layout.

But we were trying to separate the articles in different languages completely, similar to the way the localizable folder in middleman-i18n works. With the following configuration:

activate :i18n
activate :blog do |blog|
  blog.sources = "blog/{lang}/{year}-{month}-{day}-{title}.html"
  blog.permalink = "blog/{title}"
end

we were hoping for the following result:

$ find build/blog
build/blog/first-english-article.html
build/blog/second-english-article.html
$ find build/fr/blog
build/fr/blog/premiere-article-francaise.html
build/fr/blog/deuxieme-article-francaise.html

Furthermore, we wanted to have build/blog.html only list English articles, while build/fr/blog.html should list French articles only (and the same tag pages).

Unfortunately, this cannot be achieved using the current features and configuration options of middleman-blog. There are some discussions within this bug tracker and on the internet, which suggest, using separate blog instances for each language, but then we need to duplicate the calendar and tag templates, because each of these can only belong to a single blog instance.

So I went ahead and extended middleman-blog accordingly. Since the separation of blog articles by locale is a change in behaviour, I decided to activate this feature only when a newly introduced configuration option is set. Since I was aiming at the same path structure, as the one that's generated by middleman-i18n and the localizable folder, I've used blog.localizable = true. Another possible name would have been blog.separate_locales = true.

Please let me know, if you're interested in this feature and if I can do anything to help you review or merge these changes.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.3%) to 93.274% when pulling 75630d66a998e419322323cf8b0d9a2e9985c14b on planio-gmbh:localizable into fec110fad6b6535f875ae4d1c6d3ab0f5866228f on middleman:master.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.3%) to 93.274% when pulling 75630d66a998e419322323cf8b0d9a2e9985c14b on planio-gmbh:localizable into fec110fad6b6535f875ae4d1c6d3ab0f5866228f on middleman:master.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.4%) to 93.294% when pulling 75630d66a998e419322323cf8b0d9a2e9985c14b on planio-gmbh:localizable into fec110fad6b6535f875ae4d1c6d3ab0f5866228f on middleman:master.

passatgt commented 6 years ago

I had some issues with this branch using the blog.prefix parameter. The tags are not generated this way. Specifying the prefix manually in the blog.permalink and blog.taglink does work.

passatgt commented 6 years ago

Also, trying to link to a tag archive only works on the main langue:

<%= link_to tag.capitalize, tag_path(tag) %>

For every other language, it just displays "#" in the link's href.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.06%) to 92.996% when pulling 8edc8b43a6e3ff169e1d5c678e26da2e10606dd1 on planio-gmbh:localizable into fec110fad6b6535f875ae4d1c6d3ab0f5866228f on middleman:master.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.04%) to 92.975% when pulling 8edc8b43a6e3ff169e1d5c678e26da2e10606dd1 on planio-gmbh:localizable into fec110fad6b6535f875ae4d1c6d3ab0f5866228f on middleman:master.

coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.4%) to 93.294% when pulling f88cb1507c9602a791684d3dc996a43ab5401fcc on planio-gmbh:localizable into fec110fad6b6535f875ae4d1c6d3ab0f5866228f on middleman:master.

schmidt commented 6 years ago

@passatgt Thanks for taking a look at the proposed changes.

I have just updated the PR to fix tag_path and the corresponding calendar path helpers. This was basically an oversight on my end. Thanks for the pointer.

Could you give me an example of how you wanted to use the blog.prefix option? Then I'll try to take a closer look.

passatgt commented 6 years ago

@schmidt so this is my setup:

activate :blog do |blog|
  blog.localizable = true
  blog.prefix = "support"
  blog.permalink = "{title}.html"
  blog.sources = "{lang}/{year}-{month}-{day}-{title}.html"
  blog.taglink = "category/{tag}.html"
  blog.tag_template= 'support-category.html'
  blog.layout = "support-article"
end

Expected to generate /support/category/something/index.html, however this is not generated at all.

Using the config like this, works as expected:

activate :blog do |blog|
  blog.localizable = true
  #blog.prefix = "support"
  blog.permalink = "support/{title}.html"
  blog.sources = "support/{lang}/{year}-{month}-{day}-{title}.html"
  blog.taglink = "support/category/{tag}.html"
  blog.tag_template= 'support/support-category.html'
  blog.layout = "support-article"
end

Thanks for the tag_path update, i'll check it out.

Update: the tag_path update is working 👍

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.