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

Already on GitHub? Sign in to your account

setMeta and setMetaDefaults not working as expected #662

thesec opened this Issue Sep 30, 2013 · 7 comments


None yet
3 participants

thesec commented Sep 30, 2013

Trying to overwrite documents' meta info in docpad.coffee I tried

I. setMetaDefaults at first but it seems that urls gets not set?

II. ... switching to setMeta then urls does not get reset when already defined in YAML?

Is both the expected behaviour?

What I'd somehow expected is setMetaDefaults to set the defaults for any key passed in and setMeta to set any key to the value passed in, hence overwriting both default and a documents' property if defined in YAML.

Want to back this issue? Place a bounty on it! We accept bounties via Bountysource.


greduan commented Sep 30, 2013

Could you please provide the code that shows how you're using it? Thanks! :)

thesec commented Sep 30, 2013

Sure, I can commit it later ... :)

What's the intended behaviour for each though?


greduan commented Sep 30, 2013

I don't personally have the knowledge of what each one does exactly, I do know setMetaDefaults can modify a file's meta since I've used it a little while ago.

thesec commented Sep 30, 2013

Ah, ic :)

Here's how I use it to allow posts for multiple site areas:

        myCollection: ->
            @getCollection("html").findAllLive({relativeOutDirPath: /someFolder/}, [{filename:1}]).on "add", (model) ->
                area_urls = []
                area_urls.push model.getMeta("urls")...
                for area in model.getMeta("areas")
                    area_urls.push("/" + (area.replace /\s/g, "") + "/somePath/" + (model.getMeta("title").replace /\s/g, ""))
                model.setMeta({layout: "article", urls: area_urls})

Within YAML I set urls e.g. to

urls: ["/first", "/second"]

... and doing so just now ... it actually works ... tadaaa :D

... seems like some automagic got it working. Reverting to previous versions did not reveal a typo, different YAML or else :/

thesec commented Sep 30, 2013

So setMeta now seems to work as I expected it to.

How is setMetaDefaults supposed to work?
Set defaults which are overwritten by YAML for the same?
Does it set the default value for any key given?


balupton commented Oct 1, 2013

setMetaDefaults works by only setting values if they are still their default values, if a particular property has already been changed to a non-default value, the property is not set by setMetaDefaults. Is is useful for setting defaults via collection listeners, that can then be over-ridden on a as-needed basis by your document's meta data.

thesec commented Oct 1, 2013

Thanks Benjamin.

Where can the MetaDefaults and their respective default values be found and looked at?

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