feature: Set up templated views and blog support

This commit is contained in:
Keith Solomon
2025-04-20 15:39:22 -05:00
parent 463250eb7b
commit 3fe75e9ad5
20 changed files with 580 additions and 255 deletions

28
templates/base.html Normal file
View File

@@ -0,0 +1,28 @@
{{ define "base" }}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{ .Title }}</title>
</head>
<body>
{{ template "header" . }}
<main>
{{- if eq .PageTemplate "blog_index" -}}
{{ template "blog_index_content" . }}
{{- else if eq .PageTemplate "static" -}}
{{ template "static_content" . }}
{{- else if eq .PageTemplate "blog_post" -}}
{{ template "blog_post_content" . }}
{{- else if eq .PageTemplate "category_page" -}}
{{ template "category_content" . }}
{{- else -}}
<p>Unknown PageTemplate: {{ .PageTemplate }}</p>
{{- end -}}
</main>
{{ template "footer" . }}
</body>
</html>
{{ end }}

View File

@@ -0,0 +1,14 @@
{{ define "blog_index_page" }}
{{ template "base" . }}
{{ end }}
{{ define "blog_index_content" }}
<h1>Blog Index</h1>
<ul>
{{ range .Posts }}
<li><a href="/blog/{{ .Slug }}/">{{ .Title }}</a><br>{{ .Description }}</li>
{{ else }}
<li>No posts found.</li>
{{ end }}
</ul>
{{ end }}

View File

@@ -0,0 +1,22 @@
{{ define "blog_post_page" }}
{{ template "base" . }}
{{ end }}
{{ define "blog_post_content" }}
<article>
<h1>{{ .Title }}</h1>
{{ if .Date }}<p><small>{{ .Date }}</small></p>{{ end }}
{{ if .Categories }}
<p>
Categories:
{{ range $i, $cat := .Categories }}
{{ if $i }}, {{ end }}
<a href="/blog/category/{{ $cat | slugify }}/">{{ $cat }}</a>
{{ end }}
</p>
{{ end }}
{{ .Content }}
</article>
{{ end }}

View File

@@ -0,0 +1,12 @@
{{ define "category_page" }}
{{ template "base" . }}
{{ end }}
{{ define "category_content" }}
<h1>{{ .Title }}</h1>
<ul>
{{ range .Posts }}
<li><a href="/blog/{{ .Slug }}/">{{ .Title }}</a><br>{{ .Description }}</li>
{{ end }}
</ul>
{{ end }}

5
templates/footer.html Normal file
View File

@@ -0,0 +1,5 @@
{{ define "footer" }}
<footer>
<p>&copy; {{ .Year }} Keith Solomon - Go SSG</p>
</footer>
{{ end }}

11
templates/header.html Normal file
View File

@@ -0,0 +1,11 @@
{{ define "header" }}
<header>
<nav>
<ul>
{{ range .Nav }}
<li><a href="{{ .URL }}">{{ .Title }}</a></li>
{{ end }}
</ul>
</nav>
</header>
{{ end }}

View File

@@ -1,46 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{ .Title }}</title>
{{ if .Description }}<meta name="description" content="{{ .Description }}">{{ end }}
</head>
<body>
<header>
<nav>
<ul>
{{ range .Nav }}
<li><a href="{{ .URL }}">{{ .Title }}</a></li>
{{ end }}
</ul>
</nav>
</header>
<main>
{{ if .Date }}<small>Published: {{ .Date }}</small>{{ end }}
{{ .Content }}
{{ if .Posts }}
<section>
<h2>Blog Posts</h2>
<ul>
{{ range .Posts }}
<li>
<a href="/blog/{{ .Slug }}/">{{ .Title }}</a>
{{ if .Date }} <small>{{ .Date }}</small>{{ end }}<br>
{{ .Description }}
</li>
{{ end }}
</ul>
</section>
{{ end }}
</main>
<footer>
<p>&copy; {{ .Year }} Keith Solomon</p>
</footer>
</body>
</html>

View File

@@ -0,0 +1,10 @@
{{ define "static_page" }}
{{ template "base" . }}
{{ end }}
{{ define "static_content" }}
<article>
<h1>{{ .Title }}</h1>
{{ .Content }}
</article>
{{ end }}