mirror of
				https://github.com/Wonderfall/hugo-WonderMod.git
				synced 2025-10-31 11:45:26 +01:00 
			
		
		
		
	json-schema: add support for Rich Results: Json schema for structured data (#36)
* json-schema: init * sameAs can be set through .Site.Params.schema.sameAs * if it is not specified but social-icons exsists, we use social-icons for sameAs vars * .Site.Params.schema.sameAs overrides social-icons * publisherType can be changed via .Site.Params.schema.publisherType
This commit is contained in:
		
							
								
								
									
										65
									
								
								layouts/partials/templates/schema_json.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								layouts/partials/templates/schema_json.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,65 @@ | ||||
| {{ if .IsHome }} | ||||
| <script type="application/ld+json"> | ||||
| { | ||||
|   "@context": "https://schema.org", | ||||
|   "@type": "{{- ( .Site.Params.schema.publisherType | default "Organization") | humanize -}}", | ||||
|   "name": {{ .Site.Title }}, | ||||
|   "url": {{ .Site.BaseURL }}, | ||||
|   "description": {{ .Site.Params.description | plainify | truncate 180 | safeHTML }}, | ||||
|   "thumbnailUrl": {{ .Site.Params.assets.favicon | default "favicon.ico" | absURL }}, | ||||
|   "sameAs": [ | ||||
|     {{- if .Site.Params.schema.sameAs }} | ||||
|       {{ range $i, $e := .Site.Params.schema.sameAs }}{{ if $i }}, {{ end }}{{ $e }}{{ end }} | ||||
|     {{- else}} | ||||
|       {{ range $i, $e := .Site.Params.SocialIcons }}{{ if $i }}, {{ end }}{{ $e.url }}{{ end }} | ||||
|     {{- end}} | ||||
|   ] | ||||
| } | ||||
| </script> | ||||
| {{- else if .IsPage }} | ||||
| <script type="application/ld+json"> | ||||
| { | ||||
|   "@context": "https://schema.org", | ||||
|   "@type": "BlogPosting", | ||||
|   "headline": {{ .Title | plainify}}, | ||||
|   "name": "{{ .Title | plainify }}", | ||||
|   "description": {{ .Summary | plainify | truncate 180 | safeHTML }}, | ||||
|   "keywords": [ | ||||
|     {{- if .Params.keywords }} | ||||
|     {{ range $i, $e := .Params.keywords }}{{ if $i }}, {{ end }}{{ $e }}{{ end }} | ||||
|     {{- else }} | ||||
|     {{ range $i, $e := .Params.tags }}{{ if $i }}, {{ end }}{{ $e }}{{ end }} | ||||
|     {{- end }} | ||||
|   ], | ||||
|   "articleBody": {{ .Content | safeJS | htmlUnescape | plainify }}, | ||||
|   "wordCount" : "{{ .WordCount }}", | ||||
|   "inLanguage": {{ .Language.Lang | default "en-us" }}, | ||||
|   {{ if .Params.cover.image -}} | ||||
|   "image": | ||||
|     {{- if (ne .Params.cover.relative true) -}} | ||||
|     {{ .Params.cover.image | absURL }}, | ||||
|     {{- else -}} | ||||
|     {{ (path.Join .RelPermalink .Params.cover.image ) | absURL }}, | ||||
|     {{- end}} | ||||
|   {{- end}} | ||||
|   "datePublished": {{ .PublishDate }}, | ||||
|   "dateModified": {{ .Lastmod }}, | ||||
|   "author": { | ||||
|     "@type": "Person", | ||||
|     "name": {{ .Params.author | default .Site.Params.author }} | ||||
|   }, | ||||
|   "mainEntityOfPage": { | ||||
|     "@type": "WebPage", | ||||
|     "@id": {{ .Permalink | safeHTML }} | ||||
|   }, | ||||
|   "publisher": { | ||||
|     "@type": "{{- ( .Site.Params.schema.publisherType | default "Organization") | humanize -}}", | ||||
|     "name": {{ .Site.Title }}, | ||||
|     "logo": { | ||||
|       "@type": "ImageObject", | ||||
|       "url": {{ .Site.Params.assets.favicon | default "favicon.ico" | absURL }} | ||||
|     } | ||||
|   } | ||||
| } | ||||
| </script> | ||||
| {{ end }} | ||||
		Reference in New Issue
	
	Block a user
	 Aditya Telange
					Aditya Telange