Welcome to mirror list, hosted at ThFree Co, Russian Federation.

open-graph.html « components « partials « layouts - github.com/reuixiy/hugo-theme-meme.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b4d5240ad27057bd62c8ca210d6438f62f71f9cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!-- http://ogp.me/ -->
<!-- https://developers.facebook.com/docs/sharing/webmasters -->
<!-- https://developers.google.com/web/fundamentals/discovery/social-discovery/ -->
<!-- https://stackoverflow.com/a/29831974 -->
<!-- https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/opengraph.html -->
{{- $Deliver := .Deliver -}}
{{- $description := .description -}}
{{- $keywords := .keywords -}}
<!-- Title -->
{{- partial "components/title.html" $Deliver -}}
{{- $rawTitle := $Deliver.Scratch.Get "rawTitle" -}}
<!-- Auto Detect Images -->
{{- if $Deliver.Site.Params.autoDetectImages -}}
    {{- partial "components/auto-detect-images.html" $Deliver -}}
{{- end -}}
{{- $imgsURL := ($Deliver.Scratch.Get "imgsURL") -}}
<!-- Image absURL -->
{{ with $Deliver.Params.images | default $imgsURL -}}
    {{- $Deliver.Scratch.Delete "image" -}}
    {{- range . -}}
        {{- $image := . | absURL | safeHTML -}}
        {{- $Deliver.Scratch.Add "image" (printf "%s, " $image) -}}
    {{- end -}}
{{ end }}
{{- $image := (split (strings.TrimSuffix ", " ($Deliver.Scratch.Get "image")) ", ") -}}
<!-- Date -->
{{- partial "components/date.html" $Deliver -}}
{{- $pubDate := ($Deliver.Scratch.Get "pubDate") -}}
{{- $modDate := ($Deliver.Scratch.Get "modDate") -}}
<!-- Author -->
{{- partial "components/author.html" $Deliver -}}
{{- $author := ($Deliver.Scratch.Get "author") -}}
<!-- languageCode -->
{{- if $Deliver.Site.IsMultiLingual -}}
    {{- $languageCode := readFile "config.toml" | findRE `languageCode = "([^"]+)` -}}
    {{- with $languageCode -}}
        {{- $Deliver.Scratch.Delete "languageCode" -}}
        {{- range . -}}
            {{- $languageCode := replaceRE `languageCode = "([^"]+)` `$1` . -}}
            {{- $Deliver.Scratch.Add "languageCode" (slice $languageCode) -}}
        {{- end -}}
    {{- end -}}
{{- end -}}
{{- $languageCode := $Deliver.Scratch.Get "languageCode" -}}

<meta property="og:title" content="{{ $rawTitle }}" />
<meta property="og:description" content="{{ $description }}" />
<meta property="og:url" content="{{ $Deliver.Permalink }}" />
<meta property="og:site_name" content="{{ $Deliver.Site.Title }}" />
<meta property="og:locale" content="{{ $Deliver.Site.LanguageCode }}" />
{{- if $Deliver.Site.IsMultiLingual -}}
    {{- range $languageCode -}}
        {{ if ne . $Deliver.Site.LanguageCode }}
            <meta property="og:locale:alternate" content="{{ . }}" />
        {{ end }}
    {{- end -}}
{{- end -}}

{{- with $imgsURL -}}
    <meta property="og:image" content="{{ index $image 0 }}" />
{{ else -}}
    {{ with $Deliver.Site.Params.siteLogo -}}
        <meta property="og:image" content="{{ . | absURL }}" />
    {{ end -}}
{{- end -}}

{{- if and $Deliver.IsPage (in $Deliver.Site.Params.mainSections $Deliver.Section) -}}
    <meta property="og:type" content="article" />
    {{ printf `<meta property="article:published_time" content="%s" />` $pubDate | safeHTML }}
    {{ printf `<meta property="article:modified_time" content="%s" />` $modDate | safeHTML }}
    {{ if not $Deliver.ExpiryDate.IsZero -}}
        {{ printf `<meta property="article:expiration_time" content="%s" />` ($Deliver.ExpiryDate.Format "2006-01-02T15:04:05-07:00") | safeHTML }}
    {{- end }}
    <meta property="article:section" content="{{ $Deliver.Section }}" />
    <meta property="article:tag" content="{{ $keywords }}" />
{{ else -}}
    <meta property="og:type" content="website" />
{{- end }}