Skip to content

Commit

Permalink
feat(seo): add LD-JSON for some pages
Browse files Browse the repository at this point in the history
  • Loading branch information
macrat committed Mar 24, 2024
1 parent 6729ec0 commit 04ad221
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 12 deletions.
6 changes: 3 additions & 3 deletions builder/autoindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,9 @@ func (g *IndexGenerator) generateConfig(dst fs.Writable, as ArticleList, conf Co
routes = append(routes, Route{
Handle: "miss",
}, Route{
Src: "/(.*)",
Dest: "/404.html",
Check: true,
Src: "/(.*)",
Dest: "/404.html",
Check: true,
Status: 404,
})

Expand Down
2 changes: 1 addition & 1 deletion builder/photos.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (c PhotoConverter) Convert(dst fs.Writable, src Source, conf Config) (Artif
}
}

if err := img.SetArtist("SHIDA Yuma (aka. MacRat)", meta.DateTime.Format("(c)2006 MacRat")); err != nil {
if err := img.SetArtist("SHIDA Yuma (aka. MacRat)", meta.DateTime.Format("CC-BY (c)2006 MacRat")); err != nil {
return nil, err
}

Expand Down
12 changes: 12 additions & 0 deletions builder/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"html/template"
"math"
"path/filepath"
"strconv"
"strings"
"sync"
)

Expand Down Expand Up @@ -41,6 +43,16 @@ func NewTemplateLoader(basePath string) (*TemplateLoader, error) {
}
return x
},
"zfill": func(x, n int) string {
s := strconv.Itoa(x)
if len(s) >= n {
return s
}
return strings.Repeat("0", n-len(s)) + s
},
"concat": func(s ...string) string {
return strings.Join(s, "")
},
"escapetag": EscapeTag,
"tagsize": func(n int) int {
return int(math.Ceil(math.Sqrt(math.Sqrt(float64(n))) * 100))
Expand Down
31 changes: 31 additions & 0 deletions templates/blog/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,37 @@

{{define "description"}}Blanktarに掲載されたブログ記事一覧の{{.TotalPages}}ページ中{{.Page}}ページ目。{{end}}

{{define "head"}}
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{
"@type": "ListItem",
"position": 1,
"name": "blanktar.jp",
"item": "https://blanktar.jp"
},
{
"@type": "ListItem",
"position": 2,
"name": "blog",
"item": "https://blanktar.jp/blog"
{{if gt .Page 1}},
},
{
"@type": "ListItem",
"position": 3,
"name": "{{.Page}}",
"item": "https://blanktar.jp/blog/{{.Page}}"
{{end}}
}
]
}
</script>
{{end}}

{{/* <style> */}}
{{define "style"}}
.blog-articles {
Expand Down
35 changes: 35 additions & 0 deletions templates/blog/month.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,41 @@

{{define "description"}}Blanktarに掲載された{{.Year}}年{{.Month}}月のブログ記事一覧。{{end}}

{{define "head"}}
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{
"@type": "ListItem",
"position": 1,
"name": "blanktar.jp",
"item": "https://blanktar.jp"
},
{
"@type": "ListItem",
"position": 2,
"name": "blog",
"item": "https://blanktar.jp/blog"
},
{
"@type": "ListItem",
"position": 3,
"name": "{{.Year}}",
"item": "https://blanktar.jp/blog/{{.Year}}"
},
{
"@type": "ListItem",
"position": 4,
"name": "{{zfill .Month 2}}",
"item": {{.URL}}
}
]
}
</script>
{{end}}

{{/* <style> */}}
{{define "style"}}
.articles-of-month {
Expand Down
18 changes: 12 additions & 6 deletions templates/blog/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{{if .Image}}
"image": [
{{range .Image}}
"{{.}}",
{{concat "https://blanktar.jp" .}},
{{end}}
],
{{end}}
Expand All @@ -38,20 +38,26 @@
{
"@type": "ListItem",
"position": 2,
"name": "{{.Published.Format "2006"}}",
"item": "https://blanktar.jp/{{.Published.Format "2006"}}"
"name": "blog",
"item": "https://blanktar.jp/blog"
},
{
"@type": "ListItem",
"position": 3,
"name": "{{.Published.Format "01"}}",
"item": "https://blanktar.jp/{{.Published.Format "2006"}}/{{.Published.Format "01"}}"
"name": "{{.Published.Format "2006"}}",
"item": "https://blanktar.jp/blog/{{.Published.Format "2006"}}"
},
{
"@type": "ListItem",
"position": 4,
"name": "{{.Published.Format "01"}}",
"item": "https://blanktar.jp/blog/{{.Published.Format "2006"}}/{{.Published.Format "01"}}"
},
{
"@type": "ListItem",
"position": 5,
"name": "{{.Title}}",
"item": "https://blanktar.jp{{.Path}}"
"item": {{.URL}}
}
]
}
Expand Down
29 changes: 29 additions & 0 deletions templates/blog/year.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,35 @@

{{define "description"}}Blanktarに掲載された{{.Year}}年のブログ記事一覧。{{end}}

{{define "head"}}
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{
"@type": "ListItem",
"position": 1,
"name": "blanktar.jp",
"item": "https://blanktar.jp"
},
{
"@type": "ListItem",
"position": 2,
"name": "blog",
"item": "https://blanktar.jp/blog"
},
{
"@type": "ListItem",
"position": 3,
"name": "{{.Year}}",
"item": {{.URL}}
}
]
}
</script>
{{end}}

{{/* <style> */}}
{{define "style"}}
.articles-of-year {
Expand Down
4 changes: 2 additions & 2 deletions templates/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{{if .Image}}
"image": [
{{range .Image}}
"{{.}}",
{{.}},
{{end}}
],
{{end}}
Expand Down Expand Up @@ -41,7 +41,7 @@
"@type": "ListItem",
"position": {{add (len .BreadCrumb) 1}},
"name": "{{.Title}}",
"item": "https://blanktar.jp{{.Path}}"
"item": {{.URL}}
}
]
}
Expand Down
49 changes: 49 additions & 0 deletions templates/photos/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,39 @@

{{define "head"}}
<meta property="og:image" content="https://blanktar.jp{{ index .VariantPathes 1920 }}>">

<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{
"@type": "ListItem",
"position": 1,
"name": "blanktar.jp",
"item": "https://blanktar.jp"
},
{
"@type": "ListItem",
"position": 2,
"name": "photos",
"item": "https://blanktar.jp/photos"
},
{
"@type": "ListItem",
"position": 3,
"name": "{{.Metadata.DateTime.Year}}",
"item": "https://blanktar.jp/photos/{{.Metadata.DateTime.Year}}"
},
{
"@type": "ListItem",
"position": 4,
"name": "{{.Metadata.DateTime.Format "2006年01月02日"}}",
"item": {{.URL}}
}
]
}
</script>
{{end}}

{{/* <style> */}}
Expand Down Expand Up @@ -47,6 +80,22 @@
{{.Metadata.Comment}}
</div>
{{end}}

{{.Path}}
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "ImageObject",
"contentUrl": {{concat "https://blanktar.jp/" .ImagePath}},
"license": "https://creativecommons.org/licenses/by/4.0/",
"creator": {
"@type": "Person",
"name": "MacRat",
"url": "https://blanktar.jp/about",
},
"creditText": "SHIDA Yuma (aka MacRat)",
}
</script>
</div>
</article>
{{end}}
45 changes: 45 additions & 0 deletions templates/photos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,37 @@

{{define "description"}}MacRatが撮った写真{{end}}

{{define "head"}}
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{
"@type": "ListItem",
"position": 1,
"name": "blanktar.jp",
"item": "https://blanktar.jp"
},
{
"@type": "ListItem",
"position": 2,
"name": "photos",
"item": "https://blanktar.jp/photos"
{{if ne .Path "photos"}}
},
{
"@type": "ListItem",
"position": 3,
"name": "{{.PageName}}",
"item": {{.URL}}
{{end}}
}
]
}
</script>
{{end}}

{{/* <style> */}}
{{define "style"}}
body {
Expand Down Expand Up @@ -85,6 +116,20 @@ <h2>{{$date}}</h2>
width="320"
height="320"
loading="lazy">
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "ImageObject",
"contentUrl": {{concat "https://blanktar.jp/" .ImagePath}},
"license": "https://creativecommons.org/licenses/by/4.0/",
"creator": {
"@type": "Person",
"name": "MacRat",
"url": "https://blanktar.jp/about",
},
"creditText": "SHIDA Yuma (aka MacRat)",
}
</script>
</a>
</li>
{{end}}
Expand Down

0 comments on commit 04ad221

Please sign in to comment.