@scalepublishing/content-parser
Advanced tools
Comparing version 0.0.5 to 0.0.6
{ | ||
"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" | ||
] | ||
} |
@@ -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 | ||
} |
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
4395
6
0
110
1
1
4