0.3.8 • Published 4 years ago

markdown-handler v0.3.8

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

Markdown Handler

Build Status NPM version Dependencies Coverage Status

Mini utility to help you load your markdown files by using the paths to .md files.

Latest Update

0.33

  • added function parseContent to parse individual markdown files.

Features

  • 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.

Installation

Node.js

npm install markdown-handler

Usage Example (ES6)

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);
});

One of the example markdown files

---
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.

Output structure

posts:
  {
    "items": [
      {
        "title": "",
        "content": "",
        "excerpt": "",
        "path": "",
        "metas": {
          "categories": [],
          "tags": [],
          "title": "",
          "date": "",
          "coverimage": ""
        }
      }
    ]
  }

Configurations

VariableDefaultTypeNote
excerptLength30integerThe length of excerpt, excerpt will be generated from the markdown files
defaultThumbnailhttps://i.imgur.com/GzmpA4s.pngstringThe default thumbnail if there is no image in markdown file
mustHaveMetas["title", "categories", "tags", "date"]string arrayThis are the must have metas at the beginning of the markdown file
excerptParsertake the set length from the markdown filefunctionInput is the markdown file and the length of the excerpt, output is the excerpt string
thumbnailParsertake the first image from markdown file as thumbnailfunctionInput is the markdown file, output is the thumbnail string

Meta Data

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.

Example Implementation of the Code

Sporule : A micro blog system that uses markdown-handler

0.3.8

4 years ago

0.3.6

4 years ago

0.3.5

4 years ago

0.3.7

4 years ago

0.3.4

4 years ago

0.3.3

4 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.9

5 years ago

0.2.8

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago