Skip to content

Commit

Permalink
faet: JSON-LD (#191)
Browse files Browse the repository at this point in the history
* feat: add JSON-LD
* fix makefile
  • Loading branch information
peaceiris authored Sep 3, 2020
1 parent 84aecc8 commit 116774c
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 6 deletions.
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ BASE_URL := https://hugothemeiris.peaceiris.app/
.PHONY: up
up:
# $(OPEN_BROWSER)
$(DOCKER_COMPOSE) run --rm hugo server --navigateToChanged --bind=0.0.0.0 --buildDrafts --themesDir ../../ --i18n-warnings
$(DOCKER_COMPOSE) up -d
$(DOCKER_COMPOSE) exec hugo hugo \
server --navigateToChanged --bind=0.0.0.0 --buildDrafts --themesDir ../../ --i18n-warnings

.PHONY: hugo
hugo:
Expand All @@ -21,20 +23,20 @@ bumphugo:
.PHONY: build
build:
$(eval opt := --minify --themesDir ../../ --baseURL $(BASE_URL))
$(DOCKER_COMPOSE) run --rm hugo $(opt)
$(DOCKER_COMPOSE) run --rm --entrypoint=hugo hugo $(opt)

.PHONY: test
test:
$(eval opt := --minify --themesDir ../../ --baseURL $(BASE_URL) \
--renderToMemory --i18n-warnings --path-warnings --debug)
$(DOCKER_COMPOSE) run --rm hugo $(opt)
$(DOCKER_COMPOSE) run --rm --entrypoint=hugo hugo $(opt)

.PHONY: metrics
metrics:
$(eval opt := --minify --themesDir ../../ --baseURL $(BASE_URL) \
--renderToMemory --i18n-warnings --path-warnings --debug \
--templateMetrics --templateMetricsHints)
$(DOCKER_COMPOSE) run --rm hugo $(opt)
$(DOCKER_COMPOSE) run --rm --entrypoint=hugo hugo $(opt)

.PHONY: cibuild
cibuild:
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ services:
stdin_open: true
tty: true
working_dir: /src/hugo-theme-iris/exampleSite
entrypoint: sh
entrypoint: bash
2 changes: 2 additions & 0 deletions exampleSite/config/_default/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ languages:
params:
author: peaceiris
description: Hugo IRIS Theme Demo Site
publishdate: '2020-01-01'
twitter:
username: piris314
ogp:
Expand All @@ -53,6 +54,7 @@ languages:
params:
author: peaceiris
description: Hugo IRIS テーマデモサイト
publishdate: '2020-01-01'
twitter:
username: piris314
ogp:
Expand Down
3 changes: 2 additions & 1 deletion exampleSite/content/en/_index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
title: Home
description: Hugo Theme IRIS homepage
date: 2020-01-01T23:00:00.000Z
date: 2020-09-03T23:00:00.000Z
publishdate: 2020-01-01T23:00:00.000Z
---


Expand Down
1 change: 1 addition & 0 deletions layouts/partials/head.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<head>
{{ partial "head/general" . }}
{{ partial "head/json-ld" . }}

{{ with $.Params.slide }}
<style>
Expand Down
46 changes: 46 additions & 0 deletions layouts/partials/head/json-ld.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!-- https://jsonld.com/blog-post/ -->

{{ $OGPImage := "" }}
{{ if .IsHome }}
{{ $OGPImage = $.Site.Params.ogp.image | absURL }}
{{ else }}
{{ with .Params.eyecatch }}
{{ $OGPImage = . | absURL }}
{{ else }}
{{ $OGPImage = $.Site.Params.ogp.image | absURL }}
{{ end }}
{{ end }}

<script type="application/ld+json">
{
"@context" : "http://schema.org",
"@type" : "BlogPosting",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": {{ $.Site.BaseURL }}
},
"name" : {{ .Title }},
"headline" : {{ .Title }},
"description" : {{ if .IsHome }}{{ $.Site.Params.description }}{{ else }}{{ .Description }}{{ end }},
"inLanguage" : {{ $.Site.Language.Lang }},
"image": {{ $OGPImage }},
"author" : {{ $.Site.Params.author }},
"creator" : {{ $.Site.Params.author }},
"publisher": {
"@type": "Organization",
"name": {{ $.Site.Params.author }},
"logo": {
"@type": "ImageObject",
"url": {{ $.Site.Params.ogp.image | absURL }}
}
},
"copyrightYear" : {{ .Lastmod.Format "2006" }},
"datePublished": {{ if .IsHome }}{{ $.Site.Params.PublishDate }}{{ else }}{{ .PublishDate.Format "2006-01-02" }}{{ end }},
"dateModified" : {{ .Lastmod.Format "2006-01-02" }},
"url" : {{ .Permalink }},
"wordCount" : "{{ .WordCount }}",
"keywords" : [ {{ if isset .Params "tags" }}{{ range .Params.tags }}"{{ . }}",{{ end }}{{ end }}"Blog" ],
"genre": [{{ range .Params.tags }}"{{ . }}",{{ end }}"Blog"],
{{ if .IsPage }}"articleBody": {{ .Plain }}{{ end }}
}
</script>

0 comments on commit 116774c

Please sign in to comment.