✨feature: Set up templated views and blog support
This commit is contained in:
28
templates/base.html
Normal file
28
templates/base.html
Normal 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 }}
|
||||
14
templates/blog_index_page.html
Normal file
14
templates/blog_index_page.html
Normal 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 }}
|
||||
22
templates/blog_post_page.html
Normal file
22
templates/blog_post_page.html
Normal 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 }}
|
||||
12
templates/category_page.html
Normal file
12
templates/category_page.html
Normal 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
5
templates/footer.html
Normal file
@@ -0,0 +1,5 @@
|
||||
{{ define "footer" }}
|
||||
<footer>
|
||||
<p>© {{ .Year }} Keith Solomon - Go SSG</p>
|
||||
</footer>
|
||||
{{ end }}
|
||||
11
templates/header.html
Normal file
11
templates/header.html
Normal file
@@ -0,0 +1,11 @@
|
||||
{{ define "header" }}
|
||||
<header>
|
||||
<nav>
|
||||
<ul>
|
||||
{{ range .Nav }}
|
||||
<li><a href="{{ .URL }}">{{ .Title }}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
{{ end }}
|
||||
@@ -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>© {{ .Year }} Keith Solomon</p>
|
||||
</footer>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
10
templates/static_page.html
Normal file
10
templates/static_page.html
Normal file
@@ -0,0 +1,10 @@
|
||||
{{ define "static_page" }}
|
||||
{{ template "base" . }}
|
||||
{{ end }}
|
||||
|
||||
{{ define "static_content" }}
|
||||
<article>
|
||||
<h1>{{ .Title }}</h1>
|
||||
{{ .Content }}
|
||||
</article>
|
||||
{{ end }}
|
||||
Reference in New Issue
Block a user