How can I access posts' fontmatter in an extension?

I’m looking at making an extension that expands on the middleman-blog extension to add a bunch of site-specific material. In order to do that, I’d like to have posts’ frontmatters contain information which should be accessible to the extension during the before_render and after_render hooks.

The most likely way to get at this information seems to be the locs parameter to both of those hooks, but I can’t seem to get the frontmatter data to consistently and predictably show up in that parameter. The documentation on this subject is sparse, so I’m wondering, a) what data is locs supposed to contain, and b) how can I use it to examine the front matter of each post?

Here is a snippet I use in config.rb - anything that works here will be available in an extension.

You may need to use the ready do also

# Get all the french tags
sitemap.resources.select{ | d | d.data.template }.each do | resource |

    # Split path on first slash
    split = resource.path.split( File::SEPARATOR )

    # Check if locale exists
    if @locales.include? split[ 0 ].to_sym

        # Add metadata
        resource.add_metadata options: {
            locale: split[ 0 ].to_sym
        }

    end

end

Thanks for replying.

I’m having a little trouble understanding how the code you posted works. Would you mind explaining it a little? In particular, I don’t get what locales have to do with frontmatter.