From 625ea8043e9ecc7375f8db88845ee869ec1e3352 Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Wed, 25 May 2022 20:41:46 -0700 Subject: [PATCH] Render 404 page with templates to reuse the footer --- public/404.html | 10 ++++++---- templates/404.html | 17 ----------------- templates/404.tmpl | 15 +++++++++++++++ tools/generate.go | 18 ++++++++++++++++-- 4 files changed, 37 insertions(+), 23 deletions(-) delete mode 100644 templates/404.html create mode 100644 templates/404.tmpl diff --git a/public/404.html b/public/404.html index 61a5dd0..e9e842c 100644 --- a/public/404.html +++ b/public/404.html @@ -1,7 +1,7 @@ - + Go by Example: Not Found @@ -9,9 +9,11 @@

Go by Example

Sorry, we couldn't find that! Check out the home page?

- + + +
diff --git a/templates/404.html b/templates/404.html deleted file mode 100644 index 61a5dd0..0000000 --- a/templates/404.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - Go by Example: Not Found - - - -
-

Go by Example

-

Sorry, we couldn't find that! Check out the home page?

- -
- - diff --git a/templates/404.tmpl b/templates/404.tmpl new file mode 100644 index 0000000..10aae10 --- /dev/null +++ b/templates/404.tmpl @@ -0,0 +1,15 @@ + + + + + Go by Example: Not Found + + + +
+

Go by Example

+

Sorry, we couldn't find that! Check out the home page?

+{{ template "footer" }} +
+ + diff --git a/tools/generate.go b/tools/generate.go index 58d10c4..a7cda7c 100644 --- a/tools/generate.go +++ b/tools/generate.go @@ -210,7 +210,6 @@ func parseSegs(sourcePath string) ([]*Seg, string) { } func chromaFormat(code, filePath string) string { - lexer := lexers.Get(filePath) if lexer == nil { lexer = lexers.Fallback @@ -340,6 +339,21 @@ func renderExamples(examples []*Example) { } } +func render404() { + if verbose() { + fmt.Println("Rendering 404") + } + tmpl := template.New("404") + _, err := tmpl.Parse(mustReadFile("templates/footer.tmpl")) + check(err) + _, err = tmpl.Parse(mustReadFile("templates/404.tmpl")) + check(err) + file, err := os.Create(siteDir + "/404.html") + check(err) + err = tmpl.Execute(file, "") + check(err) +} + func main() { if len(os.Args) > 1 { siteDir = os.Args[1] @@ -349,12 +363,12 @@ func main() { copyFile("templates/site.css", siteDir+"/site.css") copyFile("templates/site.js", siteDir+"/site.js") copyFile("templates/favicon.ico", siteDir+"/favicon.ico") - copyFile("templates/404.html", siteDir+"/404.html") copyFile("templates/play.png", siteDir+"/play.png") copyFile("templates/clipboard.png", siteDir+"/clipboard.png") examples := parseExamples() renderIndex(examples) renderExamples(examples) + render404() } var SimpleShellOutputLexer = chroma.MustNewLexer(