kurtsson / jekyll-multiple-languages-plugin

I18n support for Jekyll and Octopress
MIT License
926 stars 203 forks source link

Permalinks with ":categories" inside #38

Closed mohamnag closed 8 years ago

mohamnag commented 9 years ago

I'm using the v1.2.9 of this plugin and I'm having troubles when using the ":categories" in my permalink setting inside _config.yml. The problem is that somehow the i18n and the language name (like en) are added to the categories of all the multilingual posts inside i18n directory.

english is the default language of my website and I have the following directory structure:

_18n
  |- en
  |    |- services
  |    |    |- 2015-04-20-development.md

which I wish to be structured as follows inside the output directory:

_site
  |- services
  |    |- development
  |    |    |- index.html

I have set the following setting in _config.yml file:

permalink: /:categories/:title/

however I get the following structure in output:

_site
  |- _i18n
  |    |- en
  |    |    |- services
  |    |    |    |- development
  |    |    |    |    |- index.html

I'm not sure if this is the default functionality of the jekyll which adds the i18n and en to the categories, but I expect this plugin to remove them from the categories of the post otherwise all permalinks who intend to use categories are useless.

mohamnag commented 9 years ago

I could solve this problem by putting following code in a *.rb file inside _plugin directory:

module Jekyll

  class Post

    alias :populate_categories_org :populate_categories
    def populate_categories
      cats = Array(categories);

      x = cats.index("_i18n")
      cats.delete_at(x) unless x.nil?

      x = cats.index(site.config['lang'])
      cats.delete_at(x) unless x.nil?

      self.categories = cats

      populate_categories_org
    end

  end

end

I hope this would help fixing the problem on this plugin

gitawego commented 9 years ago

thanks a lot. it resolves my problem as well. Hope they could integrate this fix.

kurtsson commented 9 years ago

@gitawego @mohamnag just create a PR and I will integrate it, thanks!

mohamnag commented 9 years ago

I would have loved to, but as I'm not a ruby developer I'm not sure how and where it should be put. I just started by reading some other plugins that I found with similar functionality and made this.

Anthony-Gaudino commented 8 years ago

This is now integrated into 1.4.0. Thank you @mohamnag

mohamnag commented 8 years ago

not a deal! my pleasure.