These are chat archives for jescalan/roots

27th
Jun 2016
Jeff Escalante
@jescalan
Jun 27 2016 00:02
huh, weird :(
Alex
@trautmaa
Jun 27 2016 17:39
@jescalan For publishing a page of json data: we use roots-records and in app.coffee call hook: (res) -> res.contents for the piece of content, then to publish we have a file allContent.jade, contents of which are != JSON.stringify(records.allContent)
Jeff Escalante
@jescalan
Jun 27 2016 17:39
@trautmaa context?
Alex
@trautmaa
Jun 27 2016 17:41

Hi everyone! I'm trying to figure out how to publish json data on build - does anyone have experience with this? I'd like to make a call to an API on site build, grab some json, and publish it to mysite.com/json.json. Is this possible? I've been trying to do this using jade templating, but I think jade will always wrap the data with <body> tags

Going back to my question from a couple weeks ago :)

Jeff Escalante
@jescalan
Jun 27 2016 17:41
haha yeah sorry, i cant keep all this in my head at once
so dynamic content has a function that writes data to a json file on publish
i might check that out for reference
very generally, you can use the after hook in app.coffee
Perry Kibler
@javaporter
Jun 27 2016 22:59
@tkraak are you using preview api with contentful-roots? If so, do you have an example of how you have it set up? Ideally, I'd like to have one Netlify server hooked to my git dev branch with the preview api (so the dev branch always previews drafts), and the live (master branch) not using preview (obviously). @biilmann might know this as well
Tom Kraak
@tkraak
Jun 27 2016 23:17
@javaporter sorry, I haven't gone there yet, but I'm very curious to know how all that ties together
have you done anything with filters yet?
Perry Kibler
@javaporter
Jun 27 2016 23:37
not yet, but I'm pretty sure I know how that's going to work and I have to do it anyway, what are you filtering by, date, alphanumeric?
Perry Kibler
@javaporter
Jun 27 2016 23:55

@tkraak So, one of things I do is to feature some 'stories'. I have tons of stories, but only some are 'featured', if they are, I do extra stuff with them (sparkles and glitter and etc.). There may be a cleaner way to do this, but how it I do it is that in app.coffee, I have this:

featuredStories:
          id: 'stories'
          template: 'views/stories/_story.jade'
          path: (entry) -> "#{ entry.slug }"
          filters: { 'fields.keyword': ['featured'] }

This compares to normal stories:

story:
          id: 'stories'
          template: 'views/stories/_story.jade'
          path: (entry) -> "#{ entry.slug }"

And then I just call them in normally:

h3 Featured Stories
      ul
        - for post in contentful.featuredStories
          li: a(href= post._url)= post.title

This only pulls in the stories that have the keyword: "featured".