view cmd/aya/markdown.go @ 89:744541fee713 draft

Ayaya, why did I do that again?
author yakumo.izuru
date Sun, 04 May 2025 02:19:10 +0000
parents 5583ff07e384
children
line wrap: on
line source

// Renders markdown with the given layout into html expanding all the macros
package main

import (
	"io"
	"os"
	"path/filepath"
	"github.com/russross/blackfriday/v2"
)

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
        }
        content, err := render(body, v)
        if err != nil {
                return err
        }
        v["content"] = string(blackfriday.Run([]byte(content),
                blackfriday.WithExtensions(extensions),
        ))
        if w == nil {
                out, err := os.Create(filepath.Join(PUBDIR, renameExt(path, "", ".html")))
                if err != nil {
                        return err
                }
                defer out.Close()
                w = out
        }
        return buildHTML(filepath.Join(AYADIR, v["layout"]), w, v)
}