Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to identify a non-Page HTML etc. resource #12274

Closed
jmooring opened this issue Mar 18, 2024 · 12 comments · Fixed by #13353
Closed

Add a way to identify a non-Page HTML etc. resource #12274

jmooring opened this issue Mar 18, 2024 · 12 comments · Fixed by #13353
Assignees
Milestone

Comments

@jmooring
Copy link
Member

jmooring commented Mar 18, 2024

Reference: https://discourse.gohugo.io/t/shortcode-for-iframe-breaking-at-update-hugo-122-x-123-8/48904

Not sure if this is an enhancement or a bug.

The test below obviously passes with v0.122.0 because we blindly copied content page resources (.html, .htm, .adoc, .pdc, .org, .rst, .md) when publishing the site.

By design we are no longer copying content page resources, but I think site and theme authors should be able to publish them with Permalink, RelPermalink, and Publish.

Failing test:

func TestFoo(t *testing.T) {
	t.Parallel()

	files := `
-- hugo.toml --
baseURL = 'https://example.org/'
disableKinds = ['home','rss','section','sitemap','taxonomy','term']
-- content/p1/index.md --
---
title: p1
---
-- content/p1/a.html --
<p>a</p>
-- content/p1/b.html --
<p>b</p>
-- content/p1/c.html --
<p>c</p>
-- layouts/_default/single.html --
|{{ (.Resources.Get "a.html").RelPermalink -}}
|{{ (.Resources.Get "b.html").Permalink -}}
|{{ (.Resources.Get "c.html").Publish }}
`

	b := hugolib.Test(t, files)

	b.AssertFileContent("public/p1/index.html", "|/p1/a.html|https://example.org/p1/b.html|")
	b.AssertFileContent("public/p1/a.html", "<p>a</p>")
	b.AssertFileContent("public/p1/b.html", "<p>b</p>")
	b.AssertFileContent("public/p1/c.html", "<p>c</p>")
}

The workaround is a bit ugly:

{{ ((.Resources.Get "a.html").Content | resources.FromString "/p1/a.html").RelPermalink }}
{{ ((.Resources.Get "b.html").Content | resources.FromString "/p1/b.html").Permalink }}
{{ ((.Resources.Get "c.html").Content | resources.FromString "/p1/c.html").Publish }}
@bep bep removed the NeedsTriage label Mar 19, 2024
@bep bep added this to the v0.124.1 milestone Mar 19, 2024
@bep bep self-assigned this Mar 19, 2024
@bep bep added the NotSure label Mar 19, 2024
@bep bep modified the milestones: v0.124.1, v0.125.0 Mar 19, 2024
@bep
Copy link
Member

bep commented Mar 19, 2024

  • A content file inside a leaf bundle is a headless Page (no RelPermalink); this is how it have always behaved.
  • A Page has no Publish method for good reason: A page can have shortcodes, can be rendered to multiple output formats, so the rendering/publishing needs to be coordinated.
  • I have never seen this in the wild, and I suspect that the few that wants "the old" behaviour for HTML files inside bundles would be surprised if we somehow published these relative to the bundle permalink, so I'm not sure I want to spend time on that, either.

@jmooring
Copy link
Member Author

jmooring commented Mar 19, 2024

Understood. Is there something cleaner than this to just dump the file (and return Permalink/RelPermalink)?

{{ ((.Resources.Get "a.html").Content | resources.FromString "/p1/a.html").RelPermalink }}

Or this?

{{ with .Resources.Get "a.html" }}
  {{ (.Content | resources.FromString .Path).RelPermalink }}
{{ end }}

@bep
Copy link
Member

bep commented Mar 19, 2024

Is there something cleaner than this to just dump the file (and return Permalink/RelPermalink)?

... copy it into ... static?

@jmooring
Copy link
Member Author

OP's use case needs to organize these with the page. I'm recommending second example above, or renaming the resource (e.g., a.txt instead of a.htm).

https://discourse.gohugo.io/t/shortcode-for-iframe-breaking-at-update-hugo-122-x-123-8/48904/9?u=jmooring

@jmooring jmooring closed this as not planned Won't fix, can't repro, duplicate, stale Mar 19, 2024
@bep bep changed the title Unable to publish content page resources with v0.123.0 and later Add a way to identify a non-Page HTML etc. resource Mar 19, 2024
@bep
Copy link
Member

bep commented Mar 19, 2024

I have reopened and relabeled this ... I don't know how to practically do this, but it would be a good idea if we had a way to say that a particular bundled (e.g. HTML) file should be handled as a regular simple resource with a mime type (as in: not a Page).

@jmooring
Copy link
Member Author

Related to #9197.

@jmooring jmooring reopened this Mar 19, 2024
@bep bep modified the milestones: v0.125.0, v0.126.0 Apr 23, 2024
@bep bep modified the milestones: v0.126.0, v0.127.0 May 15, 2024
@bep bep modified the milestones: v0.127.0, v0.128.0 Jun 8, 2024
@bep bep removed this from the v0.128.0 milestone Jun 21, 2024
@bep bep added this to the v0.129.0 milestone Jun 21, 2024
@bep bep modified the milestones: v0.129.0, v0.131.0 Jul 22, 2024
@bep bep modified the milestones: v0.131.0, v0.133.0 Aug 9, 2024
@bep bep modified the milestones: v0.133.0, Unscheduled Aug 29, 2024
@irkode
Copy link

irkode commented Dec 11, 2024

just thinking out loud:

Using .Page.Resource with a page bundle

  • a resource like image or text will show as type *resources.resourceAdapter and dump as Staler.

  • whereas a page resource (.md/.html)* shows at type *hugolib.pageState and dumps as JSON PageObject

  • in a page template the context (. or $) is shows a *hugolib.pageState

both have a ResourceType of page but you may only call .Permalink on the latter one

So at least within the templating there's a different experience incl. inconsistency for users. According to the Docs .Page.Resources returns resource.Resources but it's not exactly like that (at least for end users) cause a Resource has a Publish method.

looks like there is some Go magic interfacing behind ... and somehow obfuscating the details...

Summary:

maybe thinking a bit easy ;-)

If a page source file is processed by a Template its a "Page"
If a page source file is processed using Resource Methods its a "Page Resource" (not a Page)

If a Resource is published - the Content is copied verbatim to the target file

@Whoome
Copy link

Whoome commented Feb 6, 2025

This is essentially a critical issue for us, and has caused us to stop updating Hugo at 122. We have hundreds of html files that are treated as page resources (in our case, these are generated plotly graphs). And, then included in iframes for rendering. Changing the extension just doesn't work since then the files don't render.

Putting everything in the static folder is really not a good solution for us, since we are trying to keep the graphs local with the data they are relative to.

For us, even just turning off or controlling the extensions that are treated as pages would be enough, we don't have html files as content anywhere.

@jmooring
Copy link
Member Author

jmooring commented Feb 6, 2025

@Whoome In case you aren't aware of this...

{{ range .Resources.Match "**.html" }}
  {{ $publishPath := urls.JoinPath $.RelPermalink .Name }}
  {{ (.Content | resources.FromString $publishPath).Publish }}
{{ end }}

Putting the above in a single.html file will publish the HTML files.

@Whoome
Copy link

Whoome commented Feb 6, 2025

No I wasn't aware of that. I just need to drop that anywhere in the theme?

@jmooring
Copy link
Member Author

jmooring commented Feb 6, 2025

in a single.html file

Whichever one renders the pages with the HTML resources.

@bep bep modified the milestones: Unscheduled, v0.144.0 Feb 7, 2025
bep added a commit to bep/hugo that referenced this issue Feb 7, 2025
This is an empty struct for now, but we will most likely expand on that.

```
[[contentTypes]]
[[contentTypes."text/markdown"]]
```

The above means that only Markdown will be considered a content type. E.g. HTML will be treated as plain text.

Fixes gohugoio#12274
bep added a commit to bep/hugo that referenced this issue Feb 7, 2025
This is an empty struct for now, but we will most likely expand on that.

```
[[contentTypes]]
[[contentTypes."text/markdown"]]
```

The above means that only Markdown will be considered a content type. E.g. HTML will be treated as plain text.

Fixes gohugoio#12274
bep added a commit to bep/hugo that referenced this issue Feb 7, 2025
This is an empty struct for now, but we will most likely expand on that.

```
[[contentTypes]]
[[contentTypes."text/markdown"]]
```

The above means that only Markdown will be considered a content type. E.g. HTML will be treated as plain text.

Fixes gohugoio#12274
bep added a commit to bep/hugo that referenced this issue Feb 7, 2025
This is an empty struct for now, but we will most likely expand on that.

```
[[contentTypes]]
[[contentTypes."text/markdown"]]
```

The above means that only Markdown will be considered a content type. E.g. HTML will be treated as plain text.

Fixes gohugoio#12274
bep added a commit to bep/hugo that referenced this issue Feb 7, 2025
This is an empty struct for now, but we will most likely expand on that.

```
[contentTypes]
  [contentTypes.'text/markdown']
```

The above means that only Markdown will be considered a content type. E.g. HTML will be treated as plain text.

Fixes gohugoio#12274
@bep bep closed this as completed in #13353 Feb 8, 2025
@bep bep closed this as completed in c2fb221 Feb 8, 2025
Copy link

github-actions bot commented Mar 2, 2025

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants