Skip to content

Commit

Permalink
feat: add 404 error page
Browse files Browse the repository at this point in the history
  • Loading branch information
macrat committed Jan 16, 2024
1 parent 1e7fd52 commit 7212377
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
1 change: 1 addition & 0 deletions builder/article.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Article struct {
HowTo *HowTo `yaml:"howto"`
BreadCrumb []BreadCrumbItem `yaml:"breadcrumb"`
Layout string `yaml:"layout"`
Hidden bool `yaml:"hidden"`

Markdown []byte `yaml:"-"`
Content template.HTML `yaml:"-"`
Expand Down
13 changes: 10 additions & 3 deletions builder/autoindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,13 +513,20 @@ type SitemapContext struct {
}

func (g *IndexGenerator) generateSitemap(dst fs.Writable, articles ArticleList, conf Config) (ArtifactList, error) {
as := make(ArticleList, 0, len(articles))
for _, a := range articles {
if !a.Hidden {
as = append(as, a)
}
}

targetPath := "sitemap.xml"
result := ArtifactList{Index{
name: targetPath,
sources: articles.Sources(),
sources: as.Sources(),
}}

if fs.ModTime(dst, targetPath).After(articles.ModTime()) {
if fs.ModTime(dst, targetPath).After(as.ModTime()) {
return result, nil
}

Expand All @@ -535,7 +542,7 @@ func (g *IndexGenerator) generateSitemap(dst fs.Writable, articles ArticleList,

err = tmpl.Execute(output, SitemapContext{
URL: "https://blanktar.jp/sitemap.xml",
Pages: articles,
Pages: as,
})
if err != nil {
output.Close()
Expand Down
6 changes: 6 additions & 0 deletions pages/404.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
layout: error.html
title: 404
description: ページが見つかりません
hidden: true
---
41 changes: 41 additions & 0 deletions templates/error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{{define "title"}}{{.Description}} - Blanktar{{end}}

{{/* <style> */}}
{{define "style"}}
html, body {
height: 100%;
}
main {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
overflow: hidden;
}
div > span {
display: flex;
justify-content: center;
align-items: center;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
font-size: 4000%;
opacity: 0.05;
user-select: none;
z-index: -1;
}
{{end}}
{{/* </style> */}}

{{define "body"}}
<main>
<div>
<span>{{.Title}}</span>
<h1>{{.Description}}</h1>
<p><a href="/">トップページに戻る</a></p>
</div>
</main>
{{end}}

0 comments on commit 7212377

Please sign in to comment.