- v1.6.3Latest
- v1.6.2
- v1.6.1
- v1.6.0
- v1.5.1
- v1.5.0
- v1.4.0
- v1.3.1
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1.1
- v1.1.0
- v1.0.0
- v1.0.0-beta.3
- v1.0.0-beta.2
- v1.0.0-beta.1
- v1.0.0-alpha.4
- v1.0.0-alpha.3
- v1.0.0-alpha.2
- v1.0.0-alpha.1
- v0.12.2
- v0.12.1
- v0.12.0
- v0.11.0
- v0.10.3
- v0.10.2
- v0.10.1
- v0.10.0
- v0.9.8
- v0.9.7
- v0.9.6
- v0.9.5
- v0.9.4
- v0.9.3
- v0.9.2
- v1.9.2
- v0.9.1
- v0.9.0
- v0.8.7
- v0.8.7
- v0.8.7
- v0.8.7
- v0.8.7
- v0.8.6
- v0.8.5
- v0.8.4
- v0.8.3
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.30
- v0.6.0
- v0.5.0
- v0.4.1
- v0.4.0
- v0.3.0
- v0.2.0
- v0.1.1
- v0.1.0
- 0.7.29
- 0.7.28
- 0.7.27
- 0.7.26
- 0.7.25
- 0.7.24
- 0.7.23
- 0.7.22
- 0.7.21
- 0.7.20
- 0.7.19
- 0.7.18
- 0.7.17
- 0.7.16
- 0.7.15
- 0.7.14
- 0.7.14-debug.1
- 0.7.13
- 0.7.12
- 0.7.11
- 0.7.10
- 0.7.9
- 0.7.8
- 0.7.7
- 0.7.6
- 0.7.5
- 0.7.4
- 0.7.3
- 0.7.2
- 0.7.1
- 0.7.0
- 0.7.0-debug.2
- 0.7.0-debug.1
Pagic
The easiest way to generate static html page from markdown
Getting Started
Installation
npm install pagic -g
Markdown + Layout => HTML
Letβs say we have a project like this:
docs/
βββ public/
βββ src/
βββ _layout.js
βββ index.md
The _layout.js
is a simple javascript module which contains a template string:
module.exports = function ({ title, content }) {
return `
<!doctype html>
<html>
<head>
<title>${title}</title>
</head>
<body>
${content}
</body>
</html>
`
};
The index.md
is a simple markdown file:
# Pagic
The easiest way to generate static html page from markdown
Then run
pagic
Weβll get an index.html
file in public
directory:
docs/
βββ public/
| βββ index.html
βββ src/
βββ _layout.js
βββ index.md
The content should be:
<!doctype html>
<html>
<head>
<title>Pagic</title>
</head>
<body>
<h1 id="pagic">Pagic</h1>
<p>The easiest way to generate static html page from markdown</p>
</body>
</html>
Here we use markdown-it with plugins markdown-it-anchor and markdown-it-title to parse the markdown file.
Copy Other Files
If there are other files which are not ended with .md
or start with _
, we will simply copy them:
docs/
βββ public/
| βββ css
| | βββ site.css
| βββ index.html
βββ src/
βββ css
| βββ site.css
βββ _layout.js
βββ index.md
Sub Page and Sub Layout
We can have sub directory which contains markdown files.
Sub directory can also have a _layout.js
file.
In this case, only markdown files in sub directory will use sub/_layout.js
as the template.
If we cannot find a _layout.js
in the sub directory, weβll recursively find the _layout.js
in the parent directory.
docs/
βββ public/
| βββ css
| | βββ site.css
| βββ index.html
| βββ sub
| βββ index.html
βββ src/
βββ css
| βββ site.css
βββ _layout.js
|ββ index.md
βββ sub
βββ _layout.js
βββ index.md
relativeToRoot
The last thing, we can get the relativeToRoot
variable in the _layout.js
, this helps us insert the relative resources:
module.exports = function ({ title, content, relativeToRoot }) {
return `
<!doctype html>
<html>
<head>
<title>${title}</title>
<link rel="stylesheet" href="${relativeToRoot}/css/site.css" />
</head>
<body>
${content}
</body>
</html>
`
};
Options
There are some options while using the cli:
-s <path>
,--src-dir=<path>
: Change the src directory, default issrc
-d <path>
,--dist-dir=<path>
: Change the dist directory, default isdist
-w
,--watch
: Watch for src directory change
Use It as a Node Module
Itβs also able to use it as a node module:
npm install pagic --save
const pagic = requrie('pagic');
pagic({
srcDir: 'src',
distDir: 'public'
});