Skip to content

Qs-F/gen

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

cmd gen

Gen logo

cmd gen is a tool to output static htmls from markdown.

Test GoDoc Go Report Card

Installation

go get github.com/Qs-F/gen

Usage

# Example - see _example directory
gen -base _example/ -src _example/content -dst _example/dist

Features

import directive

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 directive

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>

embedded value

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.

License

MIT License

Copyright

Copyright 2020 de-liKeR / たふみ @CreatorQsF

About

cmd gen is a tool to output static htmls from markdowns with import feature for other markdown.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •