Skip to content
This repository was archived by the owner on Jun 26, 2022. It is now read-only.

Commit 3389b9d

Browse files
committed
added new parser
1 parent fe6dc61 commit 3389b9d

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed

drafts/sample_draft_post.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
Title: This is a sample post title, this is served from '/drafts'
1+
---
2+
title: This is a sample post title, this is served from '/drafts'
3+
author: geekodour
4+
labels:
5+
- bug
6+
- help wanted
7+
---
28

39
### How to use `create-react-app` with GraphQL & Apollo
410

drafts/second_post.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
title: This is a sample post title, this is served from '/drafts'
3+
author: geekodour
4+
labels:
5+
- bug
6+
- help wanted
7+
---
8+
9+
### How to use `create-react-app` with GraphQL & Apollo
10+
11+
The easiest way to get started with React apps that are using a GraphQL backend is with [`create-react-app`](https://github.com/facebookincubator/create-react-app) and [Apollo](http://dev.apollodata.com/).
12+
In this tutorial we will learn how to build an Instagram app, where users can view and post images. The complete code for this tutorial is available on [GitHub](https://github.com/graphcool-examples/react-graphql/tree/master/quickstart-with-apollo).
13+
14+
### Getting your GraphQL endpoint
15+
16+
For this tutorial you'll need a GraphQL project with the following schema:
17+
18+
```json
19+
type Post {
20+
id: ID!,
21+
description: String!,
22+
imageUrl: String!
23+
}
24+
```

scripts/utils.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ const fs = require('fs');
66
const map = require('async/map');
77
const slugify = require('slugify');
88
const path = require('path');
9+
const yamlFront = require('yaml-front-matter');
910
const _nunjucks = require('./nunjucks_config.js');
1011
const bc = require('../blog_config.json');
1112
const init = require('./init');
1213

13-
1414
// init nunjucks and blog and env variables
1515
const {nunjucks} = init.init();
1616

@@ -107,12 +107,10 @@ module.exports = {
107107
getOfflineFileContents: function(){
108108
const genPost = (fileName,cb) =>{
109109
let content = fs.readFileSync(path.join(ROOT_DIR,'drafts',fileName),{encoding:"utf8"});
110-
let post = {};
111-
// this part really need a good fix
112-
post.title = content.split("\n")[0].split(" ").slice(1).join(' ').trim();
113-
post.body = content.split("\n").slice(1).join("\n");
110+
const post = yamlFront.loadFront(content);
114111
post.slug = slugify(post.title);
115-
post.html = marked(post.body);
112+
post.html = marked(post.__content);
113+
post.labels = post.labels.map(label=>({name:label}))
116114
cb(null,post);
117115
};
118116

testshit.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const fs = require('fs');
2+
const yamlFront = require('yaml-front-matter');
3+
const content = fs.readFileSync('./drafts/sample_draft_post.md');
4+
const input = `
5+
---
6+
name: Derek Worthen
7+
age: young
8+
contact:
9+
10+
address: some location
11+
pets:
12+
- cat
13+
- dog
14+
- bat
15+
match: !!js/regexp /pattern/gim
16+
run: !!js/function function() { }
17+
---
18+
Some Other content
19+
`;
20+
console.log(JSON.stringify(yamlFront.loadFront(content),null,2));

0 commit comments

Comments
 (0)