mirror of
https://github.com/gohugoio/hugo.git
synced 2024-05-19 07:42:48 +00:00
Compare commits
7 commits
f6e540a7e0
...
6b18ce341b
Author | SHA1 | Date | |
---|---|---|---|
6b18ce341b | |||
68e95327f7 | |||
9cd7db61d3 | |||
c892e75fbc | |||
4255d13d3e | |||
c8b9f9f81c | |||
e8ae77830b |
2
go.mod
2
go.mod
|
@ -55,7 +55,7 @@ require (
|
|||
github.com/niklasfasching/go-org v1.7.0
|
||||
github.com/olekukonko/tablewriter v0.0.5
|
||||
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58
|
||||
github.com/pelletier/go-toml/v2 v2.2.1
|
||||
github.com/pelletier/go-toml/v2 v2.2.2
|
||||
github.com/rogpeppe/go-internal v1.12.0
|
||||
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd
|
||||
github.com/sanity-io/litter v1.5.5
|
||||
|
|
4
go.sum
4
go.sum
|
@ -376,8 +376,8 @@ github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N
|
|||
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
||||
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2DcNVpwGmV9E1BkGknEliJkfwQj0=
|
||||
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y=
|
||||
github.com/pelletier/go-toml/v2 v2.2.1 h1:9TA9+T8+8CUCO2+WYnDLCgrYi9+omqKXyjDtosvtEhg=
|
||||
github.com/pelletier/go-toml/v2 v2.2.1/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
|
||||
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
|
||||
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
|
||||
github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s=
|
||||
github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw=
|
||||
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
|
||||
|
|
|
@ -67,6 +67,7 @@ type pageCommon struct {
|
|||
page.InSectionPositioner
|
||||
page.OutputFormatsProvider
|
||||
page.PageMetaProvider
|
||||
page.PageMetaInternalProvider
|
||||
page.Positioner
|
||||
page.RawContentProvider
|
||||
page.RelatedKeywordsProvider
|
||||
|
|
|
@ -184,6 +184,7 @@ func (h *HugoSites) newPage(m *pageMeta) (*pageState, *paths.Path, error) {
|
|||
ResourceNameTitleProvider: m,
|
||||
ResourceParamsProvider: m,
|
||||
PageMetaProvider: m,
|
||||
PageMetaInternalProvider: m,
|
||||
RelatedKeywordsProvider: m,
|
||||
OutputFormatsProvider: page.NopPage,
|
||||
ResourceTypeProvider: pageTypesProvider,
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
# Release env.
|
||||
# These will be replaced by script before release.
|
||||
HUGORELEASER_TAG=v0.125.4
|
||||
HUGORELEASER_COMMITISH=cc3574ef4f41fccbe88d9443ed066eb10867ada2
|
||||
HUGORELEASER_TAG=v0.125.5
|
||||
HUGORELEASER_COMMITISH=c8b9f9f81c375f5b391e61bae711ee63fc76c1fd
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -225,9 +225,6 @@ type PageMetaProvider interface {
|
|||
// to the source of this Page. It will be relative to any content root.
|
||||
Path() string
|
||||
|
||||
// This is for internal use only.
|
||||
PathInfo() *paths.Path
|
||||
|
||||
// The slug, typically defined in front matter.
|
||||
Slug() string
|
||||
|
||||
|
@ -253,6 +250,12 @@ type PageMetaProvider interface {
|
|||
Weight() int
|
||||
}
|
||||
|
||||
// PageMetaInternalProvider provides internal page metadata.
|
||||
type PageMetaInternalProvider interface {
|
||||
// This is for internal use only.
|
||||
PathInfo() *paths.Path
|
||||
}
|
||||
|
||||
// PageRenderProvider provides a way for a Page to render content.
|
||||
type PageRenderProvider interface {
|
||||
// Render renders the given layout with this Page as context.
|
||||
|
@ -273,6 +276,7 @@ type PageWithoutContent interface {
|
|||
RenderShortcodesProvider
|
||||
resource.Resource
|
||||
PageMetaProvider
|
||||
PageMetaInternalProvider
|
||||
resource.LanguageProvider
|
||||
|
||||
// For pages backed by a file.
|
||||
|
|
|
@ -17,9 +17,8 @@ package page
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/gohugoio/hugo/config"
|
||||
"time"
|
||||
)
|
||||
|
||||
func MarshalPageToJSON(p Page) ([]byte, error) {
|
||||
|
@ -39,7 +38,6 @@ func MarshalPageToJSON(p Page) ([]byte, error) {
|
|||
isNode := p.IsNode()
|
||||
isPage := p.IsPage()
|
||||
path := p.Path()
|
||||
pathc := p.Path()
|
||||
slug := p.Slug()
|
||||
lang := p.Lang()
|
||||
isSection := p.IsSection()
|
||||
|
@ -65,7 +63,6 @@ func MarshalPageToJSON(p Page) ([]byte, error) {
|
|||
IsNode bool
|
||||
IsPage bool
|
||||
Path string
|
||||
Pathc string
|
||||
Slug string
|
||||
Lang string
|
||||
IsSection bool
|
||||
|
@ -90,7 +87,6 @@ func MarshalPageToJSON(p Page) ([]byte, error) {
|
|||
IsNode: isNode,
|
||||
IsPage: isPage,
|
||||
Path: path,
|
||||
Pathc: pathc,
|
||||
Slug: slug,
|
||||
Lang: lang,
|
||||
IsSection: isSection,
|
||||
|
|
|
@ -1,12 +1,18 @@
|
|||
{{- $images := partial "_funcs/get-page-images" . -}}
|
||||
{{- with index $images 0 -}}
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:image" content="{{ .Permalink }}">
|
||||
{{- else -}}
|
||||
<meta name="twitter:card" content="summary">
|
||||
{{- end -}}
|
||||
<meta name="twitter:title" content="{{ .Title }}">
|
||||
<meta name="twitter:description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end -}}">
|
||||
{{- $images := partial "_funcs/get-page-images" . }}
|
||||
{{- with index $images 0 }}
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:image" content="{{ .Permalink }}">
|
||||
{{- else }}
|
||||
<meta name="twitter:card" content="summary">
|
||||
{{- end }}
|
||||
|
||||
{{- with or .Title site.Title site.Params.title | plainify }}
|
||||
<meta name="twitter:title" content="{{ . }}">
|
||||
{{- end }}
|
||||
|
||||
{{- with or .Description .Summary site.Params.description | plainify | htmlUnescape | chomp }}
|
||||
<meta name="twitter:description" content="{{ . }}">
|
||||
{{- end }}
|
||||
|
||||
{{- $twitterSite := "" }}
|
||||
{{- with site.Params.social }}
|
||||
|
|
|
@ -411,3 +411,80 @@ series: [series-1]
|
|||
`<meta property="og:description" content="m n and **o** can't.">`,
|
||||
)
|
||||
}
|
||||
|
||||
// Issue 12433
|
||||
func TestTwitterCards(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
capitalizeListTitles = false
|
||||
disableKinds = ['rss','sitemap','taxonomy','term']
|
||||
[markup.goldmark.renderer]
|
||||
unsafe = true
|
||||
[params]
|
||||
description = "m <em>n</em> and **o** can't."
|
||||
[params.social]
|
||||
twitter = 'foo'
|
||||
-- layouts/_default/list.html --
|
||||
{{ template "_internal/twitter_cards.html" . }}
|
||||
-- layouts/_default/single.html --
|
||||
{{ template "_internal/twitter_cards.html" . }}
|
||||
-- content/s1/p1.md --
|
||||
---
|
||||
title: p1
|
||||
images: [a.jpg,b.jpg]
|
||||
---
|
||||
a <em>b</em> and **c** can't.
|
||||
-- content/s1/p2.md --
|
||||
---
|
||||
title: p2
|
||||
---
|
||||
d <em>e</em> and **f** can't.
|
||||
<!--more-->
|
||||
-- content/s1/p3.md --
|
||||
---
|
||||
title: p3
|
||||
summary: g <em>h</em> and **i** can't.
|
||||
---
|
||||
-- content/s1/p4.md --
|
||||
---
|
||||
title: p4
|
||||
description: j <em>k</em> and **l** can't.
|
||||
---
|
||||
-- content/s1/p5.md --
|
||||
---
|
||||
title: p5
|
||||
---
|
||||
`
|
||||
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/s1/p1/index.html", `
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:image" content="/a.jpg">
|
||||
<meta name="twitter:title" content="p1">
|
||||
<meta name="twitter:description" content="a b and c can’t.">
|
||||
<meta name="twitter:site" content="@foo">
|
||||
`,
|
||||
)
|
||||
|
||||
b.AssertFileContent("public/s1/p2/index.html",
|
||||
`<meta name="twitter:card" content="summary">`,
|
||||
`<meta name="twitter:description" content="d e and f can’t.">`,
|
||||
)
|
||||
|
||||
b.AssertFileContent("public/s1/p3/index.html",
|
||||
`<meta name="twitter:description" content="g h and i can’t.">`,
|
||||
)
|
||||
|
||||
// The markdown is intentionally not rendered to HTML.
|
||||
b.AssertFileContent("public/s1/p4/index.html",
|
||||
`<meta name="twitter:description" content="j k and **l** can't.">`,
|
||||
)
|
||||
|
||||
// The markdown is intentionally not rendered to HTML.
|
||||
b.AssertFileContent("public/s1/p5/index.html",
|
||||
`<meta name="twitter:description" content="m n and **o** can't.">`,
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue