aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-07-24 21:49:40 +0700
committerShulhan <ms@kilabit.info>2022-07-24 21:49:40 +0700
commitb1ac34fb775bcf0d15ac61de7dcbb6c30d03f46d (patch)
tree6e9479db8f1ce1d0f3b503b2e246a4fceb11a49f
parent73584411dcb3563e373e5b4d6c6a40cc0656bfc6 (diff)
downloadciigo-b1ac34fb775bcf0d15ac61de7dcbb6c30d03f46d.tar.xz
all: generate HTML meta data and replace the top header title
The following metadata are rendered based on the same asciidoc attributes: author, description, generator, and keywords. This changes also replace the topbar title with the document title, cleanup the HTML header syntax by replacing "/>" with ">", trim leading and trailing spaces on Body and embedded CSS.
-rw-r--r--ciigo.go4
-rw-r--r--filehtml.go10
-rw-r--r--template_index_html.go22
3 files changed, 19 insertions, 17 deletions
diff --git a/ciigo.go b/ciigo.go
index d2a719b..ec03f46 100644
--- a/ciigo.go
+++ b/ciigo.go
@@ -25,10 +25,6 @@ const (
internalTemplatePath = "_internal/.template"
)
-const (
- metadataStylesheet = "stylesheet"
-)
-
// nolint: gochecknoglobals
var (
defExcludes = []string{
diff --git a/filehtml.go b/filehtml.go
index 96c6e21..202c605 100644
--- a/filehtml.go
+++ b/filehtml.go
@@ -12,6 +12,10 @@ import (
"git.sr.ht/~shulhan/asciidoctor-go"
)
+const (
+ metadataStylesheet = "stylesheet"
+)
+
// fileHtml represent an HTML metadata for header and its body.
type fileHtml struct {
Title string
@@ -42,7 +46,11 @@ func (fhtml *fileHtml) unpackAdocMetadata(doc *asciidoctor.Document) {
switch k {
case metadataStylesheet:
fhtml.Styles = append(fhtml.Styles, v)
- default:
+ case asciidoctor.MetaNameAuthorNames:
+ fhtml.Metadata[asciidoctor.MetaNameAuthor] = v
+ case asciidoctor.MetaNameDescription,
+ asciidoctor.MetaNameGenerator,
+ asciidoctor.MetaNameKeywords:
fhtml.Metadata[k] = v
}
}
diff --git a/template_index_html.go b/template_index_html.go
index f6d617c..5dad59b 100644
--- a/template_index_html.go
+++ b/template_index_html.go
@@ -6,25 +6,25 @@ package ciigo
const templateIndexHTML = `<!DOCTYPE html>
<html>
<head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1" />
- <meta name="theme-color" content="#375EAB" />
-
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <meta name="theme-color" content="#375EAB">
+ {{range $k, $v := .Metadata -}}
+ <meta name="{{$k}}" content="{{$v}}">
+ {{end -}}
<title>{{.Title}}</title>
-
<style>
- {{.EmbeddedCSS}}
+ {{- .EmbeddedCSS -}}
</style>
-
{{- range .Styles}}
- <link rel="stylesheet" href="{{.}}" />
+ <link rel="stylesheet" href="{{.}}">
{{- end}}
</head>
<body>
<div class="topbar">
<div class="container">
<div class="top-heading">
- <a href="/">ciigo</a>
+ <a href="/">{{.Title}}</a>
</div>
<div class="menu">
<form class="item" action="/_internal/search">
@@ -36,11 +36,9 @@ const templateIndexHTML = `<!DOCTYPE html>
<div class="page">
<div class="container">
- {{.Body}}
+ {{- .Body -}}
</div>
- <!-- .container -->
</div>
- <!-- .page -->
<div class="footer">
Powered by <a