cmd gen
is a tool to output static htmls from markdown.
go get github.com/Qs-F/gen
# Example - see _example directory
gen -base _example/ -src _example/content -dst _example/dist
in front matter, you can import other markdown.
---
import:
- content/a.md
---
Likewise, write the path to the file from base path without first slash.
import
is useful, like you can import with namespace. For more cases, please see _example/*/content
directory.
---
named:
import:
- content/a.md
---
you can access with {{ .named.hogehoge }} in a.md.
layout is optional. If you want to output whole html with embedded markdown content in html file, this helps.
---
title: hello
layout: layout/index.html
---
## Hoge page
This is new page.
write the path of layout file from base
without slash in layout
.
And in layout file, you have to write special variable {{ .__content__ }}
to show markdown content.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{ .title }}</title>
</head>
<body>
<article>
{{ .__content__ }}
</article>
</body>
</html>
in your markdown file, you can even write following:
---
field1: "{{ .field2 }} is the best"
field2: golang
---
{{ field1 }}
This will be formed out as
<p>golang is the best</p>
more complex example:
content/a.md
---
who: "{{ .name }}"
name: "{{ .b.name }}"
b:
import:
- content/b.md
display: "{{ .who }} wrote this file"
---
{{ .display }}
content/b.md
---
name: たふみ
---
then
dist/a.html
<p>たふみ wrote this file</p>
(no dist/b.html
, cuz b.md only contains variable.)
Note:
- You CANNOT use variable for the yaml key. e.g.
{{ .key }}: hello
is invalid. - No DFS implmented, so cyclic import can cause undefined behavior.
MIT License
Copyright 2020 de-liKeR / たふみ @CreatorQsF