Mini utility to help you load your markdown files by using the paths to .md files.
- added function parseContent to parse individual markdown files.
- Reads markdown contents by using the paths without pre-build.
- Provides some basic meta data such as tags, categories, date, coverimage but it is flexible to configure.
Node.js
npm install markdown-handler
import MarkdownHandler from 'markdown-handler';
let mdHandler = new MarkdownHandler();
var paths = [
"https://sporule.com/1.md",
"https://sporule.com/2.md",
"https://sporule.com/3.md"
]
mdHandler.loadMds(paths).then(posts => {
console.log(posts);
});
---
title: "This is another Demo Post"
author: "Sporule"
date: "2019-09-10"
categories: "Another Demo"
tags: "tagA,tagD"
coverImage: "https://i.imgur.com/GzmpA4s.png"
---
# Paragraph 1
Lorem ipsum dolor sit amet, nullam putent deserunt mel no, cum periculis intellegebat ne. Noluisse voluptatibus id sed, iudico essent ius et. In mutat mucius probatus eum. Has cu iusto audiam quaeque. Ad idque essent mei.
Mel solet aperiri similique id, ei mutat essent cotidieque eam, tempor ancillae pri te. Est at utroque explicari, eam comprehensam mediocritatem eu. Duis quodsi commune id cum, et eum noluisse consequuntur. Tation nullam conclusionemque mel in, nec volutpat splendide ad, nec ne persecuti intellegebat. Sed antiopam maiestatis rationibus no. Vocibus appetere mea an, no vix habeo dicant probatus.
posts:
{
"items": [
{
"title": "",
"content": "",
"excerpt": "",
"path": "",
"metas": {
"categories": [],
"tags": [],
"title": "",
"date": "",
"coverimage": ""
}
}
]
}
Variable | Default | Type | Note |
---|---|---|---|
excerptLength | 30 |
integer | The length of excerpt, excerpt will be generated from the markdown files |
defaultThumbnail | https://i.imgur.com/GzmpA4s.png |
string | The default thumbnail if there is no image in markdown file |
mustHaveMetas | ["title", "categories", "tags", "date"] |
string array | This are the must have metas at the beginning of the markdown file |
excerptParser | take the set length from the markdown file | function | Input is the markdown file and the length of the excerpt, output is the excerpt string |
thumbnailParser | take the first image from markdown file as thumbnail | function | Input is the markdown file, output is the thumbnail string |
All meta data between at the beginning of the document will be loaded into the item object, for example if you want the color attribute in meta data, you shoud have the markdown files look like:
---
title: "This is another Demo Post"
author: "Sporule"
date: "2019-09-10"
categories: "Another Demo"
tags: "tagA,tagD"
coverImage: "https://i.imgur.com/GzmpA4s.png"
color:"pink"
---
# Paragraph 1
Lorem ipsum dolor sit amet, nullam putent deserunt mel no, cum periculis intellegebat ne. Noluisse voluptatibus id sed, iudico essent ius et. In mutat mucius probatus eum. Has cu iusto audiam quaeque. Ad idque essent mei.
Mel solet aperiri similique id, ei mutat essent cotidieque eam, tempor ancillae pri te. Est at utroque explicari, eam comprehensam mediocritatem eu. Duis quodsi commune id cum, et eum noluisse consequuntur. Tation nullam conclusionemque mel in, nec volutpat splendide ad, nec ne persecuti intellegebat. Sed antiopam maiestatis rationibus no. Vocibus appetere mea an, no vix habeo dicant probatus.
Sporule : A micro blog system that uses markdown-handler