fix(SEO): some bad escape sequence in JSON-LD

This commit is contained in:
Dillon 2020-03-14 15:43:58 +08:00
parent 5716f7d938
commit 984e58ec0f
3 changed files with 22 additions and 25 deletions

View file

@ -1,4 +1,4 @@
baseURL = "/"
baseURL = "https://example.com"
# [en, zh-cn, fr, ...] determines default content language
# [en, zh-cn, fr, ...] 设置默认的语言
defaultContentLanguage = "en"

View file

@ -20,15 +20,18 @@
{
"@context": "http://schema.org",
"@type": "WebSite",
"url": "{{ relLangURL `/` }}",
"url": "{{ .Permalink }}",
{{- with .Site.LanguageCode -}}
"inLanguage": "{{ . }}",
{{- end -}}
{{- with .Site.Author.name -}}
"author": {
"@type": "Person",
"name": "{{ . }}"
"name": "{{ . | safeJS }}"
},
{{- end -}}
{{- with .Site.Params.description -}}
"description": "{{ . }}",
"description": "{{ . | safeJS }}",
{{- end -}}
{{- with .Site.Params.image -}}
"image": "{{ .url | absURL }}",
@ -37,9 +40,9 @@
"thumbnailUrl": "{{ .url | absURL }}",
{{- end -}}
{{- with .Site.Copyright -}}
"license": "{{ . }}",
"license": "{{ . | safeJS }}",
{{- end -}}
"name": "{{ .Site.Title }}"
"name": "{{ .Site.Title | safeJS }}"
}
</script>
@ -49,19 +52,13 @@
{
"@context": "http://schema.org",
"@type": "BlogPosting",
"headline": "{{ .Title }}",
"headline": "{{ .Title | safeJS }}",
"inLanguage": "{{ .Site.LanguageCode }}",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "{{ .Permalink }}"
},
{{- if ge (.Param "lua.image.width") 696 -}}
"image": {
"@type": "ImageObject",
"url": "{{ .Param "lua.image.url" | absURL }}",
"width": {{ .Param "lua.image.width" }},
"height": {{ .Param "lua.image.height" }}
},
{{- else if ge .Site.Params.image.width 696 -}}
{{- if ge .Site.Params.image.width 696 -}}
"image": {
"@type": "ImageObject",
"url": "{{ .Site.Params.image.url | absURL }}",
@ -76,20 +73,20 @@
"wordcount": {{ .WordCount }},
"url": "{{ .Permalink }}",
{{- if not .PublishDate.IsZero -}}
"datePublished": "{{ .PublishDate.Format "2006-01-02T15:04:05-07:00" }}",
"datePublished": "{{ .PublishDate.Format "2006-01-02" }}",
{{- else if not .Date.IsZero -}}
"datePublished": "{{ .Date.Format "2006-01-02T15:04:05-07:00" }}",
"datePublished": "{{ .Date.Format "2006-01-02" }}",
{{- end -}}
{{- with .Lastmod -}}
"dateModified": "{{ .Format "2006-01-02T15:04:05-07:00" }}",
"dateModified": "{{ .Format "2006-01-02" }}",
{{- end -}}
{{- with .Site.Copyright -}}
"license": "{{ . }}",
"license": "{{ . | safeJS }}",
{{- end -}}
{{- with .Site.Params.publisher -}}
"publisher": {
"@type": "Organization",
"name": "{{ .name }}",
"name": "{{ .name | safeJS }}",
"logo": {
"@type": "ImageObject",
"url": "{{ .logo.url | absURL }}",
@ -98,13 +95,13 @@
}
},
{{- end -}}
{{- with .Site.Author.Name -}}
{{- with .Params.author | default .Site.Author.name | default (T "author") -}}
"author": {
"@type": "Person",
"name": "{{ . }}"
"name": "{{ . | safeJS }}"
},
{{- end -}}
"description": "{{ .Description }}"
"description": "{{ .Description | safeJS }}"
}
</script>
{{- end -}}

View file

@ -12,9 +12,9 @@
"husky": "^4.2.3"
},
"scripts": {
"build": "npx babel src --out-file assets/js/theme.min.js --source-maps",
"build": "npx babel src --out-file assets/js/theme.min.js --source-maps && hugo -v --source=exampleSite --themesDir=../.. -D --gc",
"start": "npm run build && hugo server --source=exampleSite --themesDir=../.. --disableFastRender",
"copy": "hugo -v --source=exampleSite --themesDir=../.. -D --gc --minify && rm -rf resources && cp -rf exampleSite/resources resources"
"copy": "rm -rf resources && cp -rf exampleSite/resources resources"
},
"husky": {
"hooks": {