article-data
Extract data from your markdown article
Install
npm install --save article-data
Usage
; const input = `# title _24 july 2015_ desc ![alt](http://yo.io/) content1 content2`; const article = ;articletitletext; // titlearticledatetext; // 24 july 2015articledesctext; // descarticleimagesrc; // http://yo.io/articlecontenthtml; // <p>desc</p> // <p><img src="http://yo.io/" alt="" /></p> // <p>content1</p> // <p>content2</p>
API
extract(input, dateFormat, dateLocale)
Return object { title, date, desc, image, content }
.
I hope that all fields have self-explanatory names. Anyway, desc
and content
should be explained further: desc
— first paragraph without date, content
input without title and date. All the fields are objects with such fields:
- title, desc, content:
text
andhtml
- date:
text
,html
,unix
andmoment
- image:
alt
,src
andhtml
Also everything in returned object has node
field, which is an AST node, see commonmark API.
input
Required
Type: String
Markdown string.
dateFormat
Required
Type: String
Momentjs format for date, e.g. D MMMM YYYY
.
dateLocale
Required
Type: String
One of 83 available in momentjs locales, e.g. en
or fr
.
Related
- get-md-title — get title from markdown article
- get-md-date — get date from markdown article
- get-md-desc — get content from markdown article
- get-md-image — get image from markdown article
- get-md-content — get content from markdown article
License
MIT © Vladimir Starkov