Skip to content

Commit

Permalink
Merge pull request #178 from tfsojon/chandu
Browse files Browse the repository at this point in the history
updated Open Graph partial
  • Loading branch information
devopstoday11 committed May 16, 2023
2 parents f662561 + a5da02e commit 4f144a0
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 61 deletions.
Binary file added assets/images/og-image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions config/_default/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ logo_width = "130px"
mainSections = ["blog"]
mobile = "+211234565523"
fullSiteSearch = true

# seo meta data for OpenGraph / Twitter Card
[metadata]
keywords = ["Intelops", "Cloud-Native", "Ai", "DevOps", "SRE", "Kubernetes", "Talent", "Democratize", "Next-Gen"]
description = "DevSecOps concept in development and testing"
author = "Intelops"
image = "images/og-image.jpg" # this image will be used as fallback if a page has no image of its own

[footer]
footer_light = false
# bg_color = "#1e384c"
Expand Down
28 changes: 0 additions & 28 deletions themes/delta/layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,7 @@
<meta name="msapplication-TileColor" content="{{site.Params.variables.color_primary | default `#da532c`}}">
<meta name="theme-color" content="{{site.Params.variables.body_color | default `#ffffff` }}">


{{ "<!-- Open Graph image and Twitter Card metadata -->" | safeHTML }}
{{ $image_path := .Params.image | default site.Params.image -}}
{{ $image_path_local := printf "static/%s" $image_path -}}
{{ $image_ext := trim (path.Ext $image_path | lower) "." -}}
{{ if fileExists $image_path_local -}}
<meta property="og:image" content="{{ $image_path | absURL }}" />
{{/* If not SVG, read image aspect ratio and define Twitter Card and Open Graph width and height */ -}}
{{ if ne $image_ext "svg" -}}
{{ with (imageConfig $image_path_local) -}}
{{ if (and (gt .Width 144) (gt .Height 144)) -}}
<meta name="twitter:image" content="{{ $image_path | absURL }}"/>
<meta name="twitter:card" content="summary{{ if (and (gt .Width 300) (gt .Height 157) (not (eq .Width .Height))) }}_large_image{{ end }}">
{{ end -}}
<meta property="og:image:width" content="{{ .Width }}">
<meta property="og:image:height" content="{{ .Height }}">
{{ end -}}
{{ end -}}
<meta property="og:image:type" content="image/{{ if eq $image_ext `svg` }}svg+xml{{ else }}{{ replaceRE `^jpg$` `jpeg` $image_ext }}{{ end }}">
{{ end -}}
<meta name="twitter:title" content="{{ with .Title }}{{ . }}{{ else }}{{ site.Title }}{{ end }}"/>
<meta name="twitter:description" content="{{ with .Description }}{{ . }}{{ else }}{{ if .IsPage }}{{ .Summary }}{{ else }}{{ with site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}"/>
{{ with site.Social.twitter -}}<meta name="twitter:site" content="@{{ . }}"/>{{ end -}}
{{ range site.Authors }}
{{ with .twitter -}}<meta name="twitter:creator" content="@{{ . }}"/>{{ end -}}
{{ end -}}

{{ partial "opengraph.html" . }}
{{ template "_internal/twitter_cards.html" . }}

<!-- google analytics -->
{{ template "_internal/google_analytics.html" . }}
202 changes: 170 additions & 32 deletions themes/delta/layouts/partials/opengraph.html
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 }}
2 changes: 1 addition & 1 deletion themes/delta/layouts/partials/style.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
{{ end }}
{{ end }}
{{ $styles := $styles | append (resources.Get "scss/style.scss" | resources.ExecuteAsTemplate "style.scss" . | toCSS) }}
{{ $styles := $styles | resources.Concat "/css/style.css" | minify | fingerprint "sha512"}}
{{ $styles := $styles | resources.Concat "/css/style.css" | fingerprint "sha512"}}
<style type="text/css">{{$styles.Content | safeCSS}}</style>

0 comments on commit 4f144a0

Please sign in to comment.