Giter VIP home page Giter VIP logo

parse-post's Introduction

@playfulcorgi/parse-post

Parses strings with gray matter in the following format:

---
title: some title here
date: 2017-10-12
permalink: some-permalink-here
---
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed in rebus apertissimis nimium longi sumus. Nos paucis ad haec additis finem faciamus aliquando;<!-- more -->Uterque enim summo bono fruitur, id est voluptate. Fortitudinis quaedam praecepta sunt ac paene leges, quae effeminari virum vetant in dolore. Duo Reges: constructio interrete. Idemque diviserunt naturam hominis in animum et corpus.

All fields inside gray matter are optional and will be null in the output if not used. Gray matter is optional too.

If <!-- more --> exists within the text after gray matter, text before it will be treated as the excerpt, as long as it's not empty, and the whole text (including text before <!-- more -->) as the full contect. If excerpt is provided in the gray matter and not empty, it will be treated as the excerpt only when there's no <!-- more -->.

date field inside gray matter can have multiple formats. It mainly supports the MySQL DATE and DATETIME format.

Example output (used above string as input):

{
  title: 'some title here',
  permalink: 'some-permalink-here',
  date: 1507766400000,
  excerpt: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed in rebus apertissimis nimium longi sumus. Nos paucis ad haec additis finem faciamus aliquando;',
  content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed in rebus apertissimis nimium longi sumus. Nos paucis ad haec additis finem faciamus aliquando;<!-- more -->Uterque enim summo bono fruitur, id est voluptate. Fortitudinis quaedam praecepta sunt ac paene leges, quae effeminari virum vetant in dolore. Duo Reges: constructio interrete. Idemque diviserunt naturam hominis in animum et corpus.'
}

parse-post's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.