Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setMeta and setMetaDefaults not working as expected #662

Closed
thesec opened this issue Sep 30, 2013 · 8 comments
Closed

setMeta and setMetaDefaults not working as expected #662

thesec opened this issue Sep 30, 2013 · 8 comments

Comments

@thesec
Copy link

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
Copy link
Contributor

greduan commented Sep 30, 2013

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

@thesec
Copy link
Author

thesec commented Sep 30, 2013

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

What's the intended behaviour for each though?

@greduan
Copy link
Contributor

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
Copy link
Author

thesec commented Sep 30, 2013

Ah, ic :)

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

collections:
        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
Copy link
Author

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
Copy link
Member

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
Copy link
Author

thesec commented Oct 1, 2013

Thanks Benjamin.

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

@balupton
Copy link
Member

Closing due to age. Ecosystem has likely fixed this. Try again with v6.80 or later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants