hexo-post-parser
TypeScript icon, indicating that this package has built-in type declarations

1.2.14 • Public • Published

JS Parse FrontMatter Markdown Post

Build Release Build Site

Parse FrontMatter Markdown Posts To Javascript Object

Features

  • Parsing HexoJS markdown post
  • Parsing Jekyll markdown post
  • Parsing Hugo markdown post
  • Parsing Frontmatter markdown
  • Post Asset Folder Auto Fix for HexoJS
  • Parse shortcodes - (Show all Shortcodes)
  • Include partials files with html comments
  • Get all images from post body and push them to metadata.photos
  • Auto find meta description when not set

Pre-Requirements

  • Node v18+

Installation

from npm registry

npm i hexo-post-parser # yarn add hexo-post-parser

from github master branch see commit history

npm i hexo-post-parser@https://github.com/dimaslanjaka/hexo-post-parser/tarball/COMMIT_HASH

from github pre-release branch see commit history

npm i hexo-post-parser@https://github.com/dimaslanjaka/hexo-post-parser/raw/COMMIT_HASH/release/hexo-post-parser.tgz

for yarn just replace npm i to yarn add

Configuration needed

  • file _config.yml
url: "https://domain.com/"
root: "/"
permalink: ":year/:month/:title.html"
generator:
  type: 'hexo' # or jekyll
  cache: true # enable caching
  verbose: false # enable verbose
  amp: false # transform shortcodes to amp html

parse post overriden options

const { parsePost } = require('hexo-post-parser');
const filePath = '/path/to/file.md';
parsePost(filePath, {
  shortcodes: {
    youtube: true,
    css: true,
    include: true,
    link: true,
    now: true,
    script: true,
    text: true,
    codeblock: true
  },
  config: {
    generator: {
      cache: false,
      verbose: false,
      amp: false,
      type: 'hexo'
    }
  },
  formatDate: true,
  fix: true,
  sourceFile: filePath,
  defaultThumb: "https://rawcdn.githack.com/dimaslanjaka/public-source/6a0117ddb2ea327c80dbcc7327cceca1e1b7794e/images/no-image-svgrepo-com.svg"
})

read parse options description

Shortcodes

Shortcode Description
<!-- include folder/path.txt --> Include partial files
<!-- script folder/script.js --> Include JS file as html script <script>codes</script>
{% youtube video_id %} transform youtube tag (AMP Supported)

Usage Sample

const fs = require('fs');
(async function(){
  const { parsePost, buildPost } = require('hexo-post-parser');
  const parse = await parsePost('path/to/markdown/file.md');
  // dump parsed post to json
  fs.writeFileSync('path/to/file.json', JSON.stringify(parse, null, 2));
  // build parsed post
  fs.writeFileSync('path/to/file.md', buildPost(parse));
})();

Project Sample

https://github.com/dimaslanjaka/static-blog-generator-hexo

https://github.com/dimaslanjaka/chimeraland

deployed to: www.webmanajemen.com

Argument Parameters

  • --nocache : disable cache
  • --verbose : show all console on verbose

Reference Repositories

Contribute

build compiled js to dist folder

yarn run build

build tarball in release folder

yarn run pack

Package Sidebar

Install

npm i hexo-post-parser

Weekly Downloads

13

Version

1.2.14

License

MIT

Unpacked Size

195 kB

Total Files

86

Last publish

Collaborators

  • dimaslanjaka