forked from gohugoio/hugo
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add render template hooks for links and images
This commit also revises the change detection for templates used by content files in server mode. Fixes gohugoio#6545 Fixes gohugoio#4663
- Loading branch information
Showing
52 changed files
with
1,394 additions
and
324 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
<a href="{{ .Destination | safeURL }}"{{ with .Title }} title="{{ . }}"{{ end }}>😉😉{{ .Text | safeHTML }} 😉😉</a> |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
THIS IS PARTIAL!!! |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
DELETEME PARTIAL: | ||
|
||
{{ partial "deleteme" }} |
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
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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright 2019 The Hugo Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package hugolib | ||
|
||
import "testing" | ||
|
||
func TestRenderHooks(t *testing.T) { | ||
config := ` | ||
baseURL="https://example.org" | ||
workingDir="/mywork" | ||
` | ||
b := newTestSitesBuilder(t).WithWorkingDir("/mywork").WithConfigFile("toml", config).Running() | ||
b.WithTemplatesAdded("_default/single.html", `{{ .Content }}`) | ||
b.WithTemplatesAdded("shortcodes/myshortcode1.html", `{{ partial "mypartial1" }}`) | ||
b.WithTemplatesAdded("shortcodes/myshortcode2.html", `{{ partial "mypartial2" }}`) | ||
b.WithTemplatesAdded("shortcodes/myshortcode3.html", `SHORT3|`) | ||
b.WithTemplatesAdded("partials/mypartial1.html", `PARTIAL1`) | ||
b.WithTemplatesAdded("partials/mypartial2.html", `PARTIAL2 {{ partial "mypartial3.html" }}`) | ||
b.WithTemplatesAdded("partials/mypartial3.html", `PARTIAL3`) | ||
b.WithTemplatesAdded("_default/_markup/render-link.html", `{{ .Page.Title }}|{{ .Destination | safeURL }}|Title: {{ .Title | safeHTML }}|Text: {{ .Text | safeHTML }}|END`) | ||
b.WithTemplatesAdded("docs/_markup/render-link.html", `Link docs section: {{ .Text | safeHTML }}|END`) | ||
|
||
b.WithContent("blog/p1.md", `--- | ||
title: Cool Page | ||
--- | ||
[First Link](https://www.google.com "Google's Homepage") | ||
{{< myshortcode3 >}} | ||
[Second Link](https://www.google.com "Google's Homepage") | ||
`, "blog/p2.md", `--- | ||
title: Cool Page2 | ||
layout: mylayout | ||
--- | ||
{{< myshortcode1 >}} | ||
[Some Text](https://www.google.com "Google's Homepage") | ||
`, "blog/p3.md", `--- | ||
title: Cool Page3 | ||
--- | ||
{{< myshortcode2 >}} | ||
`, "docs/docs1.md", `--- | ||
title: Docs 1 | ||
--- | ||
[Docs 1](https://www.google.com "Google's Homepage") | ||
`) | ||
b.Build(BuildCfg{}) | ||
b.AssertFileContent("public/blog/p1/index.html", `<p>Cool Page|https://www.google.com|Title: Google's Homepage|Text: First Link|END</p>`, `Text: Second`, "SHORT3|") | ||
b.AssertFileContent("public/blog/p2/index.html", `PARTIAL`) | ||
b.AssertFileContent("public/blog/p3/index.html", `PARTIAL3`) | ||
b.AssertFileContent("public/docs/docs1/index.html", `Link docs section: Docs 1|END`) | ||
|
||
b.EditFiles( | ||
"layouts/_default/_markup/render-link.html", `EDITED: {{ .Destination | safeURL }}|`, | ||
"layouts/docs/_markup/render-link.html", `DOCS EDITED: {{ .Destination | safeURL }}|`, | ||
"layouts/partials/mypartial1.html", `PARTIAL1_EDITED`, | ||
"layouts/partials/mypartial3.html", `PARTIAL3_EDITED`, | ||
"layouts/shortcodes/myshortcode3.html", `SHORT3_EDITED|`, | ||
) | ||
b.Build(BuildCfg{}) | ||
|
||
b.AssertFileContent("public/blog/p1/index.html", `<p>EDITED: https://www.google.com|</p>`, "SHORT3_EDITED|") | ||
b.AssertFileContent("public/blog/p2/index.html", `PARTIAL1_EDITED`) | ||
b.AssertFileContent("public/blog/p3/index.html", `PARTIAL3_EDITED`) | ||
b.AssertFileContent("public/docs/docs1/index.html", `DOCS EDITED: https://www.google.com|</p>`) | ||
|
||
} |
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
Oops, something went wrong.