97 lines
2.4 KiB
Go
97 lines
2.4 KiB
Go
// templates/style.go
|
|
package templates
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
)
|
|
|
|
// PageMetadata holds the frontmatter data
|
|
type PageMetadata struct {
|
|
Title string `toml:"title" yaml:"title"`
|
|
Stylesheet string `toml:"stylesheet" yaml:"stylesheet"`
|
|
Style string `toml:"style" yaml:"style"` // Inline CSS
|
|
Raw map[string]interface{} `toml:"-" yaml:"-"` // Catch-all for other fields
|
|
}
|
|
|
|
// BuildFullPage wraps the content in the HTML shell, injecting metadata.
|
|
func BuildFullPage(content []byte, meta PageMetadata, latestPostsHTML string) []byte {
|
|
var buf bytes.Buffer
|
|
|
|
// Default title if missing
|
|
title := meta.Title
|
|
if title == "" {
|
|
title = "Blog"
|
|
}
|
|
|
|
// Default stylesheet if missing
|
|
cssLink := `<link rel="stylesheet" href="/default.css">`
|
|
if meta.Stylesheet != "" {
|
|
cssLink = fmt.Sprintf(`<link rel="stylesheet" href="%s">`, meta.Stylesheet)
|
|
}
|
|
|
|
buf.WriteString(`<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>`)
|
|
buf.WriteString(title)
|
|
buf.WriteString(`</title>
|
|
`)
|
|
buf.WriteString(cssLink)
|
|
buf.WriteString(`<link rel="icon" type="image/svg+xml" href="/Favicon.svg">`)
|
|
buf.WriteString(`<script src="/theme.js" defer></script>`)
|
|
// MathJax Configuration
|
|
buf.WriteString(`<script>
|
|
MathJax = {
|
|
tex: {
|
|
inlineMath: [['$', '$'], ['\\(', '\\)']]
|
|
},
|
|
svg: {
|
|
fontCache: 'global'
|
|
}
|
|
};
|
|
</script>`)
|
|
buf.WriteString(`<script type="text/javascript" id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js"></script>`)
|
|
|
|
if meta.Style != "" {
|
|
buf.WriteString(`<style>`)
|
|
buf.WriteString(meta.Style)
|
|
buf.WriteString(`</style>`)
|
|
}
|
|
|
|
buf.WriteString(`
|
|
</head>
|
|
<body>
|
|
<header class="main-header">
|
|
<div class="header-content">
|
|
<a href="/" class="header-logo"><img src="/Favicon.svg" alt="Home"></a>
|
|
<h1>`)
|
|
buf.WriteString(title)
|
|
buf.WriteString(`</h1>
|
|
</div>
|
|
</header>
|
|
|
|
<article class="main-content">
|
|
`)
|
|
buf.Write(content)
|
|
buf.WriteString(`
|
|
</article>
|
|
|
|
<aside id="sidebar" class="sidebar">
|
|
<button id="close-sidebar" aria-label="Close Sidebar">×</button>
|
|
<div class="sidebar-content">
|
|
`)
|
|
buf.WriteString(latestPostsHTML)
|
|
buf.WriteString(`
|
|
</div>
|
|
</aside>
|
|
|
|
<div id="read-more-trigger">Read More Posts</div>
|
|
</body>
|
|
</html>`)
|
|
|
|
return buf.Bytes()
|
|
}
|