@dodiameer/md2pages
v1.0.2
Published
A basic SSG that turns Markdown to HTML pages
Downloads
7
Maintainers
Readme
md2pages
A basic SSG that turns Markdown to HTML pages. It uses md2html, another package I made that wraps around remark and gray-matter, to generate HTML, and then replaces placeholders in a template with the generated HTML and (optional) YAML front-matter data.
Usage
Usage is very simple, as currently it only has one function. Once more functionality is added, there will be a documentation page.
Javascript
const md2pages = require("@dodiameer/md2pages");
const fs = require("fs");
/* HTML Template Can be a multiline string with backticks (`...`)
* or an output of fs.readFile() (or fs.readFileSync). I.E as long
* as you pass a string it should be okay
*/
const htmlTemplate = fs.readFileSync("path/to/template.html"); // Or a multiline string
md2pages.generateHTML(inputDirectory, outputDirectory, {
htmlTemplate: htmlTemplate
});
If no template is provided, it will default to a simple template with the content inside an <article/>
.
HTML template
<html>
<head>
<!-- Anything inside {curly brackets} is considered YAML front-matter data -->
<title>{title}</title>
<!-- Here, {title} will be replaced with the title defined in YAML front-matter -->
</head>
<body>
<article>
<h1>{title}</h1>
<h2>Author: {author}</h2>
{{html}}
<!--
{{html}} is where the generated HTML will be placed. If omitted, generated HTML will not be output. NOTE: this is the only tag with double curly brackets
-->
</article>
</body>
</html>
Note: currently, YAMl front-matter support only works with strings and numbers, meaning you can't use lists or objects. However, there are plans to support this in the near future.
Contributors
- dodiameer (Me)
Note that currently, I'm the only one working on this and I'm just a hobbyist with no work experience. Some code will run badly and have unexpected bugs (features?). I don't recommend using this in a project other than a simple project or a project where you don't mind messy code in your libraries, until I either have proper knowledge or someone with me to give me some guidance. If you do decide to use this or even just give it a try, please tell me what you think. Your advice is priceless and will always be welcome.
Thanks for reading ^__^.