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

How to add json array into metalsmith-collections? #29

Closed
surajdalvi opened this issue Mar 4, 2015 · 6 comments
Closed

How to add json array into metalsmith-collections? #29

surajdalvi opened this issue Mar 4, 2015 · 6 comments

Comments

@surajdalvi
Copy link

I have json array with me and i want to add these array into metalsmith-collections. how i do it please help me?

@thiagodemellobueno
Copy link

@surajdalvi you may want to look at metalsmith-json

@woodyrew
Copy link
Member

woodyrew commented Sep 7, 2015

@surajdalvi Do you want the json as metadata of a collection or to have collections based on the json?

An example of the json and what you're expecting might be useful.

@virajsoni06
Copy link

virajsoni06 commented Jun 14, 2016

Hey @woodyrew, I'm facing a similar problem. What I'm trying to do is have a collection based on the json data

I'm fairly new to Metalsmith and I'm not sure where to begin with

I have the following code in my plugins for generating files from json

"plugins": {
"metalsmith-markdown": {
"smartypants": true,
"smartLists": true,
"gfm": true,
"tables": true
},
"metalsmith-permalinks": {},
"metalsmith-json-to-files": {
"source_path": "./json/"
},
"metalsmith-collections": {
"jsonTest": {}
},
"metalsmith-layouts": {
"engine": 'handlebars',
"directory": './templates',
"partials": './templates/partials',
"default": 'index.hbs'
}
}

And my markdown file has the following YAML matter

title: Albums
layout: portfolio.hbs
json_files:
source_file: jsonTest
filename_pattern: portfolio/:data.slug
as_permalink: true
layout: single.hbs
title: data.slug
pageTitle: data.slug
pageTitle2: data.title.rendered
collection: jsonTest

The problem here is, I have a header.hbs partial in which I want to render the title for the single pages as well. But when I run metalsmith, it is not adding any title in the generated file

Thanks.

@woodyrew
Copy link
Member

@virajsoni06 Do you have a repository I could look at?

@virajsoni06
Copy link

@woodyrew Sorry for the late response, but I figured it out. I added json as metadata into collections

"metalsmith-collections": {
    "posts": {
        "metadata": "./json/blog.json",
        "sortBy":  "date"
    },
},

@woodyrew
Copy link
Member

@lambtron This issue can be closed. (Sorry if you're not the correct person to reference). Could the repo be moved to the metalsmith org?

@webketje webketje closed this as completed Feb 2, 2022
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

5 participants