Socket
Socket
Sign inDemoInstall

@scalepublishing/content-parser

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.5 to 0.0.6

src/cli.js

21

package.json
{
"name": "@scalepublishing/content-parser",
"version": "0.0.5",
"version": "0.0.6",
"main": "src/parser.js",
"author": "Clément Renaud <clement@scalepublishing.com>",
"homepage": "https://scalepublishing.com",
"license": "MIT",
"type": "module",
"scripts": {
"cli": "node src/cli.js",
"json": "node src/parser.js"
},
"bin": {
"@scalepublishing/content-parser": "node src/cli.js"
},
"devDependencies": {

@@ -14,5 +21,15 @@ "fs-extra": "^10.0.0",

},
"keywords": [
"scale",
"publishing",
"content",
"parser",
"markdown",
"yaml"
],
"files": [
"dist"
"src",
"package.json",
"README.md"
]
}

70

src/parser.js

@@ -1,8 +0,10 @@

import fs from 'fs-extra';
import path from 'path';
import marked from 'marked';
import yaml from 'js-yaml';
import fs from 'fs-extra';
import { listFiles, fileExists } from './utils/files.js'
// parse markdown
const parseMetadata = (markdown) => {
export const parseMetadata = (markdown) => {
const match = /---\n([\s\S]+?)\n---/.exec(markdown);

@@ -17,44 +19,30 @@ if (match) {

const fileExists = async (filePath) => {
if (!await fs.pathExists(filePath)) {
throw new Error(`Path ${filePath} does not exist.`)
export const parseArticle = async (filePath) => {
const raw = await fs.readFile(filePath, 'utf8')
const { metadata, content } = parseMetadata(raw)
// convert to html
const html = marked(content)
// add slug
const slug = filePath.slice(0, -3)
return {
metadata,
slug,
md: content,
html
}
}
export default async (contentsPath, outPath) => {
export default async (contentsPath) => {
// console.log('Exporting SCALE contents...', contentsPath)
const files = await listFiles(path.resolve(contentsPath, 'contents'))
const files = await fs.readdir(path.resolve(contentsPath, 'contents'))
fileExists(contentsPath)
// parse articles
const articles = []
await Promise.all(
files.map( async file => {
const filePath = path.resolve(contentsPath, 'contents', file)
// make sure file exists
fileExists(filePath)
const articles = await Promise.all(
files.map(file => path.resolve(contentsPath, 'contents', file))
.map(filePath => parseArticle(filePath))
)
const raw = await fs.readFile(filePath, 'utf8')
const { metadata, content} = parseMetadata(raw)
// convert to html
const html = marked(content)
// add slug
const slug = file.slice(0, -3)
// prepend title and author
articles.push({
metadata,
slug,
md: content,
html
})
})
)
// parse metadata

@@ -80,11 +68,3 @@ const tocPath = path.resolve(contentsPath, 'toc.yml')

if(outPath) {
// write JSON to disk
await fs.outputJson(path.resolve(outPath, 'issue.json'), issue, { 'spaces' : 4 })
// export as js
await fs.outputFile(path.resolve(outPath, 'issue.js'), `export default ${JSON.stringify(issue, null, 4)}`,)
}
return issue
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc