mirror of
https://github.com/gohugoio/hugo.git
synced 2024-05-13 04:52:48 +00:00
Compare commits
5 commits
83ea0a546d
...
f8577d9c09
Author | SHA1 | Date | |
---|---|---|---|
f8577d9c09 | |||
74ce5dc841 | |||
54a8f0ce21 | |||
38e05bd3c7 | |||
10580fbc22 |
|
@ -68,9 +68,9 @@ title: My Site
|
|||
<meta property="article:published_time" content="2021-02-26T18:02:00-01:00" />
|
||||
<meta property="article:modified_time" content="2021-05-22T19:25:00-01:00" />
|
||||
<meta itemprop="name" content="My Bundle">
|
||||
<meta itemprop="image" content="https://example.org/mybundle/featured-sunset.jpg" />
|
||||
<meta itemprop="datePublished" content="2021-02-26T18:02:00-01:00" />
|
||||
<meta itemprop="dateModified" content="2021-05-22T19:25:00-01:00" />
|
||||
<meta itemprop="image" content="https://example.org/mybundle/featured-sunset.jpg">
|
||||
<meta itemprop="datePublished" content="2021-02-26T18:02:00-01:00">
|
||||
<meta itemprop="dateModified" content="2021-05-22T19:25:00-01:00">
|
||||
|
||||
`)
|
||||
b.AssertFileContent("public/mypage/index.html", `
|
||||
|
@ -81,17 +81,17 @@ title: My Site
|
|||
<meta property="og:image" content="https://example.org/mypage/sample.jpg" />
|
||||
<meta property="article:published_time" content="2021-02-26T18:02:00+01:00" />
|
||||
<meta property="article:modified_time" content="2021-05-22T19:25:00+01:00" />
|
||||
<meta itemprop="image" content="https://example.org/pageimg1.jpg" />
|
||||
<meta itemprop="image" content="https://example.org/pageimg2.jpg" />
|
||||
<meta itemprop="image" content="https://example.local/logo.png" />
|
||||
<meta itemprop="image" content="https://example.org/mypage/sample.jpg" />
|
||||
<meta itemprop="datePublished" content="2021-02-26T18:02:00+01:00" />
|
||||
<meta itemprop="dateModified" content="2021-05-22T19:25:00+01:00" />
|
||||
<meta itemprop="image" content="https://example.org/pageimg1.jpg">
|
||||
<meta itemprop="image" content="https://example.org/pageimg2.jpg">
|
||||
<meta itemprop="image" content="https://example.local/logo.png">
|
||||
<meta itemprop="image" content="https://example.org/mypage/sample.jpg">
|
||||
<meta itemprop="datePublished" content="2021-02-26T18:02:00+01:00">
|
||||
<meta itemprop="dateModified" content="2021-05-22T19:25:00+01:00">
|
||||
`)
|
||||
b.AssertFileContent("public/mysite/index.html", `
|
||||
<meta name="twitter:image" content="https://example.org/siteimg1.jpg" />
|
||||
<meta property="og:image" content="https://example.org/siteimg1.jpg" />
|
||||
<meta itemprop="image" content="https://example.org/siteimg1.jpg" />
|
||||
<meta itemprop="image" content="https://example.org/siteimg1.jpg">
|
||||
`)
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ func New(rs *resources.Spec) *Client {
|
|||
|
||||
// Copy copies r to the new targetPath.
|
||||
func (c *Client) Copy(r resource.Resource, targetPath string) (resource.Resource, error) {
|
||||
key := dynacache.CleanKey(targetPath)
|
||||
key := dynacache.CleanKey(targetPath) + "__copy"
|
||||
return c.rs.ResourceCache.GetOrCreate(key, func() (resource.Resource, error) {
|
||||
return resources.Copy(r, targetPath), nil
|
||||
})
|
||||
|
@ -66,7 +66,7 @@ func (c *Client) Copy(r resource.Resource, targetPath string) (resource.Resource
|
|||
// Get creates a new Resource by opening the given pathname in the assets filesystem.
|
||||
func (c *Client) Get(pathname string) (resource.Resource, error) {
|
||||
pathname = path.Clean(pathname)
|
||||
key := dynacache.CleanKey(pathname)
|
||||
key := dynacache.CleanKey(pathname) + "__get"
|
||||
|
||||
return c.rs.ResourceCache.GetOrCreate(key, func() (resource.Resource, error) {
|
||||
// The resource file will not be read before it gets used (e.g. in .Content),
|
||||
|
|
|
@ -227,3 +227,50 @@ eventDate: 2023-11-01T07:00:00-08:00
|
|||
|
||||
b.AssertFileContent("public/index.html", "2023-11|p9|p8|p7|2023-10|p6|p5|p4|2023-09|p3|p2|p1|")
|
||||
}
|
||||
|
||||
// Issue 10412
|
||||
func TestImageTransformThenCopy(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
|
||||
-- assets/pixel.png --
|
||||
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==
|
||||
-- layouts/index.html --
|
||||
{{- with resources.Get "pixel.png" }}
|
||||
{{- with .Resize "200x" | resources.Copy "pixel.png" }}
|
||||
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}">|{{ .Key }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
`
|
||||
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileExists("public/pixel.png", true)
|
||||
b.AssertFileContent("public/index.html",
|
||||
`<img src="/pixel.png" width="200" height="200">|/pixel.png`,
|
||||
)
|
||||
}
|
||||
|
||||
// Issue 12310
|
||||
func TestUseDifferentCacheKeyForResourceCopy(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
disableKinds = ['page','section','rss','sitemap','taxonomy','term']
|
||||
-- assets/a.txt --
|
||||
This was assets/a.txt
|
||||
-- layouts/index.html --
|
||||
{{ $nilResource := resources.Get "/p1/b.txt" }}
|
||||
{{ $r := resources.Get "a.txt" }}
|
||||
{{ $r = resources.Copy "/p1/b.txt" $r }}
|
||||
{{ $r.RelPermalink }}
|
||||
`
|
||||
|
||||
b, err := hugolib.TestE(t, files)
|
||||
|
||||
b.Assert(err, qt.IsNil)
|
||||
b.AssertFileContent("public/p1/b.txt", "This was assets/a.txt")
|
||||
}
|
||||
|
|
|
@ -15,12 +15,12 @@
|
|||
package debug
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/bep/logg"
|
||||
"github.com/sanity-io/litter"
|
||||
"github.com/spf13/cast"
|
||||
"github.com/yuin/goldmark/util"
|
||||
|
||||
|
@ -108,7 +108,11 @@ type Namespace struct {
|
|||
// Also note that the output from Dump may change from Hugo version to the next,
|
||||
// so don't depend on a specific output.
|
||||
func (ns *Namespace) Dump(val any) string {
|
||||
return litter.Sdump(val)
|
||||
b, err := json.MarshalIndent(val, "", " ")
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// VisualizeSpaces returns a string with spaces replaced by a visible string.
|
||||
|
|
|
@ -43,3 +43,33 @@ disableKinds = ["taxonomy", "term"]
|
|||
|
||||
b.AssertLogContains("timer: name foo count 5 duration")
|
||||
}
|
||||
|
||||
func TestDebugDumpPage(t *testing.T) {
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
baseURL = "https://example.org/"
|
||||
disableLiveReload = true
|
||||
[taxonomies]
|
||||
tag = "tags"
|
||||
-- content/_index.md --
|
||||
---
|
||||
title: "The Index"
|
||||
date: 2012-03-15
|
||||
---
|
||||
-- content/p1.md --
|
||||
---
|
||||
title: "The First"
|
||||
tags: ["a", "b"]
|
||||
---
|
||||
-- layouts/_default/list.html --
|
||||
Dump: {{ debug.Dump . | safeHTML }}
|
||||
Dump Site: {{ debug.Dump site }}
|
||||
Dum site.Taxonomies: {{ debug.Dump site.Taxonomies | safeHTML }}
|
||||
-- layouts/_default/single.html --
|
||||
Dump: {{ debug.Dump . | safeHTML }}
|
||||
|
||||
|
||||
`
|
||||
b := hugolib.TestRunning(t, files)
|
||||
b.AssertFileContent("public/index.html", "Dump: {\n \"Date\": \"2012-03-15T00:00:00Z\"")
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ func init() {
|
|||
[][2]string{
|
||||
{`{{ $m := newScratch }}
|
||||
{{ $m.Set "Hugo" "Rocks!" }}
|
||||
{{ $m.Values | debug.Dump | safeHTML }}`, "map[string]interface {}{\n \"Hugo\": \"Rocks!\",\n}"},
|
||||
{{ $m.Values | debug.Dump | safeHTML }}`, "{\n \"Hugo\": \"Rocks!\"\n}"},
|
||||
},
|
||||
)
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
{{- $siteSeries := .Site.Taxonomies.series }}
|
||||
{{- if $siteSeries }}
|
||||
{{ with .Params.series }}{{- range $name := . }}
|
||||
{{- $series := index $siteSeries ($name | urlize) }}
|
||||
{{- $series := index $siteSeries ((urls.Parse ($name | urlize)).Path) }}
|
||||
{{- range $page := first 6 $series.Pages }}
|
||||
{{- if ne $page.Permalink $permalink }}<meta property="og:see_also" content="{{ $page.Permalink }}" />{{ end }}
|
||||
{{- end }}
|
||||
|
|
|
@ -1,17 +1,56 @@
|
|||
<meta itemprop="name" content="{{ .Title }}">
|
||||
<meta itemprop="description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}">
|
||||
{{- with or .Title site.Title }}
|
||||
<meta itemprop="name" content="{{ . }}">
|
||||
{{- end }}
|
||||
|
||||
{{- if .IsPage -}}
|
||||
{{- $iso8601 := "2006-01-02T15:04:05-07:00" -}}
|
||||
{{ with .PublishDate }}<meta itemprop="datePublished" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />{{ end}}
|
||||
{{ with .Lastmod }}<meta itemprop="dateModified" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />{{ end}}
|
||||
<meta itemprop="wordCount" content="{{ .WordCount }}">
|
||||
{{- with or .Description .Summary site.Params.Description }}
|
||||
<meta itemprop="description" content="{{ . }}">
|
||||
{{- end }}
|
||||
|
||||
{{- $images := partial "_funcs/get-page-images" . -}}
|
||||
{{- range first 6 $images -}}
|
||||
<meta itemprop="image" content="{{ .Permalink }}" />
|
||||
{{- end -}}
|
||||
|
||||
<!-- Output all taxonomies as schema.org keywords -->
|
||||
<meta itemprop="keywords" content="{{ if .IsPage}}{{ range $index, $tag := .Params.tags }}{{ $tag }},{{ end }}{{ else }}{{ range $plural, $terms := .Site.Taxonomies }}{{ range $term, $val := $terms }}{{ printf "%s," $term }}{{ end }}{{ end }}{{ end }}" />
|
||||
{{- $ISO8601 := "2006-01-02T15:04:05-07:00" }}
|
||||
{{- with .PublishDate }}
|
||||
<meta itemprop="datePublished" {{ .Format $ISO8601 | printf "content=%q" | safeHTMLAttr }}>
|
||||
{{- end }}
|
||||
|
||||
{{- with .Lastmod }}
|
||||
<meta itemprop="dateModified" {{ .Format $ISO8601 | printf "content=%q" | safeHTMLAttr }}>
|
||||
{{- end }}
|
||||
|
||||
{{- with .WordCount }}
|
||||
<meta itemprop="wordCount" content="{{ . }}">
|
||||
{{- end }}
|
||||
|
||||
{{- $images := partial "_funcs/get-page-images" . }}
|
||||
{{- range first 6 $images }}
|
||||
<meta itemprop="image" content="{{ .Permalink }}">
|
||||
{{- end }}
|
||||
|
||||
{{- /*
|
||||
Keywords precedence:
|
||||
|
||||
1. Use "keywords" term page titles.
|
||||
2. Use "keywords" from front matter if "keywords" is not a taxonomy.
|
||||
3. Use "tags" term page titles.
|
||||
4. Use term page titles from all taxonomies.
|
||||
|
||||
*/}}
|
||||
{{- $keywords := slice }}
|
||||
{{- range .GetTerms "keywords" }}
|
||||
{{- $keywords = $keywords | append .Title }}
|
||||
{{- else }}
|
||||
{{- with .Keywords }}
|
||||
{{- $keywords = . }}
|
||||
{{- else }}
|
||||
{{- range .GetTerms "tags" }}
|
||||
{{- $keywords = $keywords | append .Title }}
|
||||
{{- else }}
|
||||
{{- range $taxonomy, $_ := site.Taxonomies }}
|
||||
{{- range $.GetTerms $taxonomy }}
|
||||
{{- $keywords = $keywords | append .Title }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- with $keywords }}
|
||||
<meta itemprop="keywords" content="{{ delimit . `,` }}">
|
||||
{{- end -}}
|
||||
|
|
Loading…
Reference in a new issue