summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimanshu Sardana <himanshusardana2005@gmail.com>2026-03-23 23:37:43 +0000
committerHimanshu Sardana <himanshusardana2005@gmail.com>2026-03-23 23:37:43 +0000
commit25787ba6df487f36d0e59de19e4f8ec7c83bd06b (patch)
tree179da0e520d821919b7ba7dea7446ca9aadbc7be
parent9ce6c42b05b2e316d3aef11c51f114e3ef545fa8 (diff)
feat: add config file parsing
-rw-r--r--config.yaml4
-rw-r--r--main.go35
2 files changed, 24 insertions, 15 deletions
diff --git a/config.yaml b/config.yaml
new file mode 100644
index 0000000..7c0463f
--- /dev/null
+++ b/config.yaml
@@ -0,0 +1,4 @@
+siteTitle: "himanshu.co"
+authorName: "Himanshu Sardana"
+authorRole: "Linux Enthusiast"
+authorBio: "i use arch btw"
diff --git a/main.go b/main.go
index ef90476..a9404f9 100644
--- a/main.go
+++ b/main.go
@@ -20,6 +20,7 @@ import (
"github.com/gomarkdown/markdown/ast"
"github.com/gomarkdown/markdown/html"
"github.com/gomarkdown/markdown/parser"
+ "gopkg.in/yaml.v3"
)
type TOCItem struct {
@@ -219,18 +220,18 @@ func extractText(h *ast.Heading) string {
type PostSummary struct {
Title string
- Slug string // derived from filename, e.g. "my-post" from "my-post.md"
- Date string // from frontmatter, e.g. "Mar 2026"
- Tags []string // from frontmatter (optional)
+ Slug string
+ Date string
+ Tags []string
}
type HomePage struct {
- SiteTitle string
- AuthorName string
- AuthorRole string
- AuthorBio string
+ SiteTitle string `yaml:"siteTitle"`
+ AuthorName string `yaml:"authorName"`
+ AuthorRole string `yaml:"authorRole"`
+ AuthorBio string `yaml:"authorBio"`
Year int
- Posts []PostSummary // sorted newest-first
+ Posts []PostSummary
}
func renderHomePage(summaries []PostSummary, outputDir string) {
@@ -244,13 +245,17 @@ func renderHomePage(summaries []PostSummary, outputDir string) {
}
}
- data := HomePage{
- SiteTitle: "himanshu.co",
- AuthorName: "Himanshu Sardana",
- AuthorRole: "Student",
- AuthorBio: "20 y/o linux enthusiast & software engineer",
- Year: time.Now().Year(),
- Posts: summaries,
+ config, err := os.ReadFile("config.yaml")
+ if err != nil {
+ panic(err)
+ }
+ var data HomePage
+ err = yaml.Unmarshal(config, &data)
+ data.Posts = summaries
+ data.Year = time.Now().Year()
+
+ if err != nil {
+ panic(err)
}
tmpl, err := template.ParseFiles("./home.html")