diff options
author | Dillon <dillonzq@outlook.com> | 2020-03-14 10:48:38 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-14 10:48:38 +0300 |
commit | 6070846867a3dad85fed8865cf3b39f19a211b16 (patch) | |
tree | 28dc9d5ddc746d3df662fe3289b1f9b884a406b8 | |
parent | 5716f7d938e1901deabde72958bb61d20f2e509e (diff) | |
parent | 984e58ec0fe7391939bfb912fe047224d4f3a4fe (diff) |
Merge pull request #148 from dillonzq/fix/bad_escape_sequence
fix(SEO): some bad escape sequence in JSON-LD
-rw-r--r-- | exampleSite/config.toml | 2 | ||||
-rw-r--r-- | layouts/partials/head/seo.html | 41 | ||||
-rw-r--r-- | package.json | 4 |
3 files changed, 22 insertions, 25 deletions
diff --git a/exampleSite/config.toml b/exampleSite/config.toml index 6b1ebe4..14e1684 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -1,4 +1,4 @@ -baseURL = "/" +baseURL = "https://example.com" # [en, zh-cn, fr, ...] determines default content language # [en, zh-cn, fr, ...] 设置默认的语言 defaultContentLanguage = "en" diff --git a/layouts/partials/head/seo.html b/layouts/partials/head/seo.html index 5a22286..7fa7996 100644 --- a/layouts/partials/head/seo.html +++ b/layouts/partials/head/seo.html @@ -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 -}} diff --git a/package.json b/package.json index 0739d82..52f3730 100644 --- a/package.json +++ b/package.json @@ -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": { |