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

Open
jmooring opened this issue Mar 18, 2024 · 6 comments
Open

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

jmooring opened this issue Mar 18, 2024 · 6 comments
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants