feat: move the blackfriday extension settings out of the render function, improve documentation
Signed-off-by: Izuru Yakumo <yakumo.izuru@chaotic.ninja> git-svn-id: file:///srv/svn/repo/aya/trunk@72 cec141ff-132a-4243-88a5-ce187bd62f94
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// $TheSupernovaDuo: cmd/aya/main.go,v 0.6.3 2023/09/27 22:46:30 yakumo_izuru Exp $
|
||||
// $TheSupernovaDuo: marisa.chaotic.ninja/aya/cmd/aya, v 1.0 2023-10-03 02:34:17, yakumo_izuru Exp $
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"marisa.chaotic.ninja/aya"
|
||||
)
|
||||
|
||||
// Define global constants here
|
||||
const (
|
||||
AYADIR = ".aya"
|
||||
PUBDIR = ".pub"
|
||||
@@ -178,6 +179,7 @@ func render(s string, vars Vars) (string, error) {
|
||||
// Renders markdown with the given layout into html expanding all the macros
|
||||
func buildMarkdown(path string, w io.Writer, vars Vars) error {
|
||||
v, body, err := getVars(path, vars)
|
||||
extensions := blackfriday.CommonExtensions|blackfriday.AutoHeadingIDs|blackfriday.Strikethrough|blackfriday.Footnotes
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -186,7 +188,7 @@ func buildMarkdown(path string, w io.Writer, vars Vars) error {
|
||||
return err
|
||||
}
|
||||
v["content"] = string(blackfriday.Run([]byte(content),
|
||||
blackfriday.WithExtensions(blackfriday.CommonExtensions|blackfriday.AutoHeadingIDs|blackfriday.Strikethrough|blackfriday.Footnotes),
|
||||
blackfriday.WithExtensions(extensions),
|
||||
))
|
||||
if w == nil {
|
||||
out, err := os.Create(filepath.Join(PUBDIR, renameExt(path, "", ".html")))
|
||||
@@ -302,6 +304,8 @@ func buildRaw(path string, w io.Writer) error {
|
||||
}
|
||||
|
||||
// This function passes the files to build to their corresponding functions
|
||||
// As far as I'm aware, Markdown has three possible filename extensions,
|
||||
// but .md is the most common one known.
|
||||
func build(path string, w io.Writer, vars Vars) error {
|
||||
ext := filepath.Ext(path)
|
||||
if ext == ".md" || ext == ".mkd" || ext == ".markdown" {
|
||||
@@ -317,6 +321,9 @@ func build(path string, w io.Writer, vars Vars) error {
|
||||
}
|
||||
}
|
||||
|
||||
// Build everything and store it on PUBDIR
|
||||
// If boolean watch is true, it keeps on going
|
||||
// every time you modify something.
|
||||
func buildAll(watch bool) {
|
||||
lastModified := time.Unix(0, 0)
|
||||
modified := false
|
||||
@@ -391,6 +398,7 @@ func printUsage() {
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// Main loop
|
||||
func main() {
|
||||
if len(os.Args) == 1 {
|
||||
printUsage()
|
||||
|
||||
Reference in New Issue
Block a user