Cannot modify site.tags from Jekyll plugin #1244

Closed
liamzebedee opened this Issue Jun 27, 2013 · 8 comments

Comments

Projects
None yet
4 participants
@liamzebedee

I had asked for help on the mailing list a couple of days ago but I have received no reply.

I'm developing a plugin to facilitate multilingual Jekyll sites, and as part of this I have to categorise posts according to their language.

I'm trying to tag the post according to its language, so I have overwritten the aggregate_post_info method, but when I print the site.tags variable, it is empty.

module Jekyll
    class Site

        alias_method :_aggregate_post_info, :aggregate_post_info
        def aggregate_post_info(post)
            _aggregate_post_info(post)
            @tags[post.data['lang']] << post
        end

    end
end
@parkr

This comment has been minimized.

Show comment Hide comment
@parkr

parkr Jun 27, 2013

Owner

Why not add a tag with the lang on your post:

---
title: "Guten Morgen"
tags: [de, morning]
---

Instead of using @tags, try using self.tags.

Owner

parkr commented Jun 27, 2013

Why not add a tag with the lang on your post:

---
title: "Guten Morgen"
tags: [de, morning]
---

Instead of using @tags, try using self.tags.

@liamzebedee

This comment has been minimized.

Show comment Hide comment
@liamzebedee

liamzebedee Jun 27, 2013

Why not add a tag with the lang on your post?

Because I have already detected the language and for the purposes of simplicity I require that it is automatically tagged as such (wherein not doing so would be contrary to the purpose of the plugin — seamless localisation).

I have tried using self.tags to no avail.

Why not add a tag with the lang on your post?

Because I have already detected the language and for the purposes of simplicity I require that it is automatically tagged as such (wherein not doing so would be contrary to the purpose of the plugin — seamless localisation).

I have tried using self.tags to no avail.

@parkr

This comment has been minimized.

Show comment Hide comment
@parkr

parkr Jun 27, 2013

Owner

Try a generator:

class LanguageTagGenerator < Jekyll::Generator
  def generate(site)
    site.posts.each do |post|
      site.tags[post.data['lang']] ||= []
      site.tags[post.data['lang']] << post
    end
  end
end
Owner

parkr commented Jun 27, 2013

Try a generator:

class LanguageTagGenerator < Jekyll::Generator
  def generate(site)
    site.posts.each do |post|
      site.tags[post.data['lang']] ||= []
      site.tags[post.data['lang']] << post
    end
  end
end
@parkr

This comment has been minimized.

Show comment Hide comment
@parkr

parkr Jun 27, 2013

Owner

Monkey-patching Jekyll internals can be hairy sometimes :)

Owner

parkr commented Jun 27, 2013

Monkey-patching Jekyll internals can be hairy sometimes :)

@liamzebedee

This comment has been minimized.

Show comment Hide comment
@liamzebedee

liamzebedee Jun 27, 2013

Thanks that was a good idea, but for some reason, it still doesn't work.

    class LanguageTagGenerator < Generator
        priority :lowest
        def generate(site)
            site.posts.each do |post|
                lang = post.data['lang'].to_s
                site.tags[lang] ||= []
                site.tags[lang] << post
            end
            puts site.tags
        end
    end

And yet the output from my console as a result of puts site.tags shows an array of posts mapped to their language. But it is gone.

The only other active plugin I use is jekyll-asset-pipeline, which shouldn't have any effect.

Thanks that was a good idea, but for some reason, it still doesn't work.

    class LanguageTagGenerator < Generator
        priority :lowest
        def generate(site)
            site.posts.each do |post|
                lang = post.data['lang'].to_s
                site.tags[lang] ||= []
                site.tags[lang] << post
            end
            puts site.tags
        end
    end

And yet the output from my console as a result of puts site.tags shows an array of posts mapped to their language. But it is gone.

The only other active plugin I use is jekyll-asset-pipeline, which shouldn't have any effect.

@liamzebedee

This comment has been minimized.

Show comment Hide comment
@liamzebedee

liamzebedee Jun 29, 2013

I'm still experiencing this issue and it seems that it is a bug of sorts, could I have it labelled as a bug?

I'm still experiencing this issue and it seems that it is a bug of sorts, could I have it labelled as a bug?

@zedwarth

This comment has been minimized.

Show comment Hide comment
@zedwarth

zedwarth Apr 1, 2014

Is this still an issue?

@liamzebedee it looks like you finished your plugin. Did you use a work around? Do you have any more insight as to why the site.tags variable was empty?

zedwarth commented Apr 1, 2014

Is this still an issue?

@liamzebedee it looks like you finished your plugin. Did you use a work around? Do you have any more insight as to why the site.tags variable was empty?

@liamzebedee

This comment has been minimized.

Show comment Hide comment
@liamzebedee

liamzebedee Apr 4, 2014

@zedwarth I didn't end up finding out why site.tags was empty, but I managed to find a work around by overriding the read_yaml method instead.

@zedwarth I didn't end up finding out why site.tags was empty, but I managed to find a work around by overriding the read_yaml method instead.

@liamzebedee liamzebedee closed this Apr 4, 2014

@jekyllbot jekyllbot locked and limited conversation to collaborators Feb 27, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.