-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #178 from tfsojon/chandu
updated Open Graph partial
- Loading branch information
Showing
5 changed files
with
179 additions
and
61 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,172 @@ | ||
<meta property="og:title" content="{{ .Title }}" /> | ||
<meta property="og:description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}" /> | ||
<meta property="og:type" content="{{ if .IsPage }}article{{ else }}website{{ end }}" /> | ||
<!-- base url --> | ||
{{ if or (eq site.BaseURL "/") (eq site.BaseURL "http://localhost:1313/") (eq site.BaseURL "http://examplesite.org/") (eq site.BaseURL "https://examplesite.org/") (eq site.BaseURL "http://examplesite.com/") (eq site.BaseURL "https://examplesite.com/") }} | ||
{{ else }} | ||
<base href="{{ .Permalink }}" /> | ||
{{ end }} | ||
|
||
|
||
<!-- meta noindex --> | ||
{{ if .Params.noindex }} | ||
<meta name="robots" content="noindex,nofollow" /> | ||
{{ end }} | ||
|
||
|
||
<!-- meta canonical --> | ||
<link rel="canonical" href="{{ .Permalink }}" itemprop="url" /> | ||
|
||
<!-- multilingual SEO optimizations --> | ||
{{ if .IsTranslated }} | ||
{{ range .AllTranslations }} | ||
<link rel="alternate" hreflang="{{ .Lang }}" href="{{ .Permalink }}" /> | ||
{{ end }} | ||
<link rel="alternate" hreflang="x-default" href="{{ .Permalink }}" /> | ||
{{ end }} | ||
|
||
|
||
<!-- meta keywords --> | ||
{{ if .Params.keywords }} | ||
<meta name="keywords" content="{{ delimit .Params.keywords `, ` }}" /> | ||
{{ else if site.Params.metadata.keywords }} | ||
<meta | ||
name="keywords" | ||
content="{{ delimit site.Params.metadata.keywords `, ` }}" /> | ||
{{ end }} | ||
|
||
|
||
<!-- meta description --> | ||
<meta | ||
name="description" | ||
content="{{ .Params.description | default site.Params.metadata.description }}" /> | ||
|
||
<!-- meta author --> | ||
{{ with site.Params.metadata.author }} | ||
<meta name="author" content="{{ . }}" /> | ||
{{ end }} | ||
|
||
|
||
<!-- meta hugo version --> | ||
{{ hugo.Generator }} | ||
|
||
|
||
<!-- checking og title --> | ||
{{ $title := site.Title }} | ||
{{ if .Params.og_title }} | ||
{{ $title = .Params.og_title }} | ||
<!-- checking page title --> | ||
{{ else if .Title }} | ||
{{ $title = .Title }} | ||
<!-- checking metadata title --> | ||
{{ else if site.Params.metadata.title }} | ||
{{ $title = site.Params.metadata.title }} | ||
{{ end }} | ||
|
||
|
||
<!-- checking og description --> | ||
{{ $description := .Summary }} | ||
{{ if .Params.og_description }} | ||
{{ $description = .Params.og_description }} | ||
<!-- checking page description --> | ||
{{ else if .Params.description }} | ||
{{ $description = .Params.description }} | ||
<!-- checking page description --> | ||
{{ else if site.Params.metadata.description }} | ||
{{ $description = site.Params.metadata.description }} | ||
{{ end }} | ||
|
||
|
||
<!-- checking og image --> | ||
{{ $imagePath := site.Params.metadata.image }} | ||
{{ if .Params.og_image }} | ||
{{ $imagePath = .Params.og_image }} | ||
<!-- checking multiple images --> | ||
{{ else if .Params.images }} | ||
{{ range first 1 .Params.images }} | ||
{{ $imagePath = . }} | ||
{{ end }} | ||
<!-- checking single images --> | ||
{{ else if .Params.image }} | ||
{{ $imagePath = .Params.image }} | ||
{{ end }} | ||
|
||
|
||
<!-- ######### Opengraph and Twitter image meta ############## --> | ||
|
||
<!-- check cdn/static image --> | ||
{{ if or (hasPrefix $imagePath "http") (fileExists (add `static/` (string $imagePath))) }} | ||
<meta name="twitter:card" content="summary_large_image" /> | ||
<meta name="twitter:image" content="{{ $imagePath | absURL }}" /> | ||
<meta property="og:image" content="{{ $imagePath | absURL }}" /> | ||
{{ else }} | ||
<!-- check cdn/static image --> | ||
|
||
<!-- content and assets image path variable --> | ||
{{ $contentImage:= .Resources.GetMatch (printf "*%s*" $imagePath) }} | ||
{{ $assetImage:= fileExists (add `assets/` (string $imagePath)) }} | ||
|
||
|
||
<!-- check image existence --> | ||
{{ if or $contentImage $assetImage }} | ||
<!-- content or assets folder detection --> | ||
{{ if $contentImage }} | ||
{{ .Scratch.Set "image-exists" $contentImage }} | ||
{{ else if $assetImage }} | ||
{{ .Scratch.Set "image-exists" (resources.Get $imagePath) }} | ||
{{ end }} | ||
|
||
{{ $image:= .Scratch.Get "image-exists" }} | ||
|
||
|
||
<!-- image extension --> | ||
{{ $imageExt:= path.Ext $image }} | ||
|
||
|
||
<!-- If not SVG --> | ||
{{ if ne $imageExt `.svg` }} | ||
{{ $imageWidth := $image.Width }} | ||
{{ $imageHeight := $image.Height }} | ||
{{ if (and (gt $imageWidth 144) (gt $imageHeight 144)) }} | ||
<meta property="og:image" content="{{ $image.Permalink }}" /> | ||
<meta name="twitter:image" content="{{ $image.Permalink }}" /> | ||
<meta | ||
name="twitter:card" | ||
content="summary{{ if (and (gt $imageWidth 300) (gt $imageHeight 157) (not (eq $imageWidth $imageHeight))) }} | ||
_large_image | ||
{{ end }}" /> | ||
{{ end }} | ||
<!-- /if image gt 144px --> | ||
<meta property="og:image:width" content="{{ $imageWidth }}" /> | ||
<meta property="og:image:height" content="{{ $imageHeight }}" /> | ||
{{ end }} | ||
|
||
<!-- /if not svg --> | ||
|
||
<meta | ||
property="og:image:type" | ||
content="image/{{ if eq $imageExt `.svg` }} | ||
svg+xml | ||
{{ else }} | ||
{{ replaceRE `^jpg$` `jpeg` $imageExt }} | ||
{{ end }}" /> | ||
{{ end }} | ||
|
||
<!-- /if image exist --> | ||
{{ end }} | ||
<!-- /check cdn/static image --> | ||
<!-- ######### /Opengraph and Twitter image meta ############## --> | ||
|
||
<!-- ######### opengraph others meta ############## --> | ||
<meta property="og:title" content="{{ $title }}" /> | ||
<meta property="og:description" content="{{ $description }}" /> | ||
<meta property="og:type" content="website" /> | ||
<meta property="og:url" content="{{ .Permalink }}" /> | ||
|
||
{{- with $.Params.images -}} | ||
{{- range first 6 . }}<meta property="og:image" content="{{ . | absURL }}" />{{ end -}} | ||
{{- else -}} | ||
{{- $images := $.Resources.ByType "image" -}} | ||
{{- $featured := $images.GetMatch "*feature*" -}} | ||
{{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} | ||
{{- with $featured -}} | ||
<meta property="og:image" content="{{ $featured.Permalink }}"/> | ||
{{- else -}} | ||
{{- with $.Site.Params.images }}<meta property="og:image" content="{{ index . 0 | absURL }}"/>{{ end -}} | ||
{{- end -}} | ||
{{- end -}} | ||
|
||
{{- if .IsPage }} | ||
{{- $iso8601 := "2006-01-02T15:04:05-07:00" -}} | ||
<meta property="article:section" content="{{ .Section }}" /> | ||
{{ with .PublishDate }}<meta property="article:published_time" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />{{ end }} | ||
{{ with .Lastmod }}<meta property="article:modified_time" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />{{ end }} | ||
{{- end -}} | ||
|
||
{{- with .Params.audio }}<meta property="og:audio" content="{{ . }}" />{{ end }} | ||
{{- with .Params.locale }}<meta property="og:locale" content="{{ . }}" />{{ end }} | ||
{{- with .Site.Params.title }}<meta property="og:site_name" content="{{ . }}" />{{ end }} | ||
{{- with .Params.videos }}{{- range . }} | ||
<meta property="og:video" content="{{ . | absURL }}" /> | ||
{{ end }}{{ end }} | ||
|
||
{{- /* Facebook Page Admin ID for Domain Insights */}} | ||
{{- with .Site.Social.facebook_admin }}<meta property="fb:admins" content="{{ . }}" />{{ end }} | ||
<!-- ########## twitter others meta ############### --> | ||
<meta name="twitter:title" content="{{ $title }}" /> | ||
<meta name="twitter:description" content="{{ $description }}" /> | ||
|
||
{{ with site.Social.twitter }} | ||
<meta name="twitter:site" content="@{{ . }}" /> | ||
{{ end }} | ||
{{ range site.Authors }} | ||
{{ with .twitter }}<meta name="twitter:creator" content="@{{ . }}" />{{ end }} | ||
{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters