在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):sparkartgroup/gulp-markdown-to-json开源软件地址(OpenSource Url):https://github.com/sparkartgroup/gulp-markdown-to-json开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):gulp-markdown-to-json
The neutral format of JSON opens new possibilities for your handcrafted content. Send it onward to other plugins such as gulp-hb. When their powers combine, you get a static site generator! Pipe to request to send it to a search index or import into a CMS. Write a plugin to tap into the stream if you need a client library. Table of ContentsInstallnpm install gulp-markdown-to-json --save-dev DependenciesThis plugin does not bundle any Markdown parser to keep your options open. BYOM! Pick one of these or write a new parser for fun!
Install, configure, and pass a rendering method to this plugin with a source string as its first argument. Output goes straight into the JSON file’s function render (string) {
const remark = require('remark');
const html = require('remark-html');
return remark().use(html).process(string).toString();
}
Usage
const gulp = require('gulp');
const markdownToJSON = require('gulp-markdown-to-json');
const marked = require('marked');
marked.setOptions({
pedantic: true,
smartypants: true
});
gulp.task('markdown', () => {
gulp.src('./content/**/*.md')
.pipe(markdownToJSON(marked))
.pipe(gulp.dest('.'))
}); Transformed source files flow onward to the destination of your choice with directory structure preserved. Any valid JSON files matched by your
---
slug: bushwick-artisan
title: Wes Anderson pop-up Bushwick artisan
layout: centered
---
## YOLO
Chia quinoa meh, you probably haven't heard of them sartorial Holowaychuk pickled post-ironic. Plaid ugh vegan, Sixpoint 8-bit sartorial artisan semiotics put a bird on it Mission bicycle rights Club-Mate vinyl.
{
"slug": "bushwick-artisan",
"title": "Wes Anderson pop-up Bushwick artisan",
"layout": "centered",
"body": "<h2 id=\"yolo\">YOLO</h2>\n<p>Chia quinoa meh, you probably haven't heard of them sartorial Holowaychuk pickled post-ironic. Plaid ugh vegan, Sixpoint 8-bit sartorial artisan semiotics put a bird on it Mission bicycle rights Club-Mate vinyl.</p>",
"updatedAt": "1970-01-01T00:00:00Z"
} Consolidated OutputGather Markdown files before piping with list-stream to combine output into a single JSON file. Directory structure is preserved and represented as nested JSON for iteration with Handlebars.js and friends. This is handy for navigation and other global content. Valid JSON files are included in the object if matched by your The consolidated file is named const gulp = require('gulp');
const ListStream = require('list-stream');
const markdownToJSON = require('gulp-markdown-to-json');
const marked = require('marked');
gulp.task('markdown', () => {
gulp.src('./content/**/*.md')
.pipe(ListStream.obj())
.pipe(markdownToJSON(marked, 'blog.json'))
.pipe(gulp.dest('.'))
});
{
"blog": {
"blog": {
"title": "ipsum dipsum",
"body": "<p>From west to \"east\"!</p>",
"updatedAt": "1970-01-01T00:00:00Z"
},
"posts": {
"bushwick-artisan": {
"slug": "bushwick-artisan",
"title": "Wes Anderson pop-up Bushwick artisan",
"layout": "centered",
"body": "<h2 id=\"yolo\">YOLO</h2>\n<p>Chia quinoa meh, you probably haven't heard of them sartorial Holowaychuk pickled post-ironic. Plaid ugh vegan, Sixpoint 8-bit sartorial artisan semiotics put a bird on it Mission bicycle rights Club-Mate vinyl.</p>",
"updatedAt": "1970-01-01T00:00:00Z"
}
}
},
"mission": {
...
}
} Specify {
"blog": {
"title": "ipsum dipsum",
"body": "<p>From west to \"east\"!</p>",
"updatedAt": "1970-01-01T00:00:00Z",
"posts": {
...
}
},
"mission": {
...
}
} This avoids redundant-feeling Title Extraction and StrippingDefine titles as Specify
Wes Anderson pop-up Bushwick artisan
====================================
## YOLO
Chia quinoa meh, you probably haven't heard of them sartorial Holowaychuk pickled post-ironic. Plaid ugh vegan, Sixpoint 8-bit sartorial artisan semiotics put a bird on it Mission bicycle rights Club-Mate vinyl.
{
"title": "Wes Anderson pop-up Bushwick artisan",
"body": "<h2 id=\"yolo\">YOLO</h2>\n<p>Chia quinoa meh, you probably haven't heard of them sartorial Holowaychuk pickled post-ironic. Plaid ugh vegan, Sixpoint 8-bit sartorial artisan semiotics put a bird on it Mission bicycle rights Club-Mate vinyl.</p>",
"updatedAt": "1970-01-01T00:00:00Z"
} TransformsTo change or add to the JSON data for each file, specify a transform function and return your desired object. This function is passed the default data and the Vinyl file object for the source file. For example: gulp.src('./content/**/*.md')
.pipe(ListStream.obj())
.pipe(markdownToJSON(marked, 'blog.json', (data, file) => {
delete data.body;
data.path = file.path;
return data;
}))
.pipe(gulp.dest('.')) API
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论