Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
Merge pull request #148 from dillonzq/fix/bad_escape_sequence
Browse files Browse the repository at this point in the history
fix(SEO): some bad escape sequence in JSON-LD
  • Loading branch information
dillonzq authored Mar 14, 2020
2 parents 5716f7d + 984e58e commit 6070846
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
2 changes: 1 addition & 1 deletion exampleSite/config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
baseURL = "/"
baseURL = "https://example.com"
# [en, zh-cn, fr, ...] determines default content language
# [en, zh-cn, fr, ...] 设置默认的语言
defaultContentLanguage = "en"
Expand Down
41 changes: 19 additions & 22 deletions layouts/partials/head/seo.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}",
Expand All @@ -37,9 +40,9 @@
"thumbnailUrl": "{{ .url | absURL }}",
{{- end -}}
{{- with .Site.Copyright -}}
"license": "{{ . }}",
"license": "{{ . | safeJS }}",
{{- end -}}
"name": "{{ .Site.Title }}"
"name": "{{ .Site.Title | safeJS }}"
}
</script>

Expand All @@ -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 }}",
Expand All @@ -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 }}",
Expand All @@ -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 -}}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 6070846

Please sign in to comment.