GenGo

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 7d4316ff226987fd92794ba434795fa77c097470
parent 97bf857970371f500b665a9b01f9d65bd3e61e7a
Author: Tyler Clark <tyler.clark@foxide.xyz>
Date:   Thu, 23 Apr 2026 17:29:51 -0400

Adding ability to use template to generate custom header/footer

This commit add the ability to use pandoc's built-in `--template` flag
for the header/footer of the generated site. This can potentially be
used for more advanced things though.
Also including a template file that will likely change over time.

Diffstat:
Mmain.go | 23++++++++++++++++++++---
Atemplate.html | 34++++++++++++++++++++++++++++++++++
2 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/main.go b/main.go @@ -4,7 +4,8 @@ /*****************************************************************/ /* DONE: Basic functionality for converting markdown/org to html */ /* DONE: Recursively mirroring dir structure of source files */ -/* TODO: Prepend and append header and footer on HTML files */ +/* DONE: Prepend and append header and footer on HTML files */ +/* TODO: Ignore non-valid file types and directories in the src */ /* TODO: RSS generator built in */ /* TODO: Sitemap generator */ /*****************************************************************/ @@ -78,16 +79,32 @@ func RemoveExt(filename string) string { return filename[:len(filename)-len(path.Ext(filename))] } +/* This function converts the markdown files using pandoc and allows for a user defined template */ +/* with pandoc's `--template` flag. A default should be included as an example, and will potentially */ +/* need to be maintained over time as pandoc changes. The function will then put the output string */ +/* Into the corresponding file */ + +/* TODO: Add functionality to ignore non valid file types and entire directories */ func ConvertFile(filepath, filename, destination string) error { fmt.Println("Converting following file to HTML:", filename) oFile := RemoveExt(filename) - cmd := exec.Command("pandoc", filepath + "/" + filename, "-o", destination + "/" + oFile + ".html") + cmd := exec.Command("pandoc", "-s", "--template", "template.html", filepath + "/" + filename) output, err := cmd.Output() if err != nil { fmt.Println("Error:", err) return err } - fmt.Println(string(output)) + file, err := os.Create(destination + "/" + oFile + ".html") + if err != nil { + panic(err) + } + defer file.Close() + + _, err = file.WriteString(string(output)) + if err != nil { + panic(err) + } + return nil } diff --git a/template.html b/template.html @@ -0,0 +1,34 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="utf-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1" /> + <link rel="icon" type="image/png" href="/favicon.png" /> + <link rel="stylesheet" type="text/css" href="/style.css" /> + <title>Tyler's website</title> + </head> + + <body> + <header> + <h1>Tyler's Site</h1> + </header> + <nav> + <a class="button" href="https://foxide.xyz/">home</a>&emsp; + <a class="button" href="https://foxide.xyz/articles.html">articles</a>&emsp; + <a class="button" href="https://foxide.xyz/projects.html">projects</a>&emsp; + <a class="button" href="https://foxide.xyz/consulting.html">consulting</a>&emsp; + <a class="button" href="https://git.foxide.xyz/">code</a>&emsp; + <a class="button" href="https://foxide.xyz/rss.xml">RSS Feed</a>&emsp; + </nav> + <article> + $body$ + </article> + <footer> + <p> + Comments or suggestions?<br /> + Contact me: <a href="mailto:tyler.clark@foxide.xyz">tyler.clark@foxide.xyz</a> + </p> + </footer> + </article> + </body> +</html>