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 sensible fallback for permalink :token when not backed by a file #9448

Closed
jmooring opened this issue Jan 31, 2022 · 4 comments · Fixed by #11185
Closed

Add sensible fallback for permalink :token when not backed by a file #9448

jmooring opened this issue Jan 31, 2022 · 4 comments · Fixed by #11185
Assignees
Milestone

Comments

@jmooring
Copy link
Member

jmooring commented Jan 31, 2022

WARN 2023/02/17 09:40:41 .File.TranslationBaseName on zero object. Wrap it in if or with: {{ with .File }}{{ .TranslationBaseName }}{{ end }}

This is not a new warning; it exists as far back as v0.55.4, but does not exist in v0.54.0 (I didn't test those in between).

And the warning makes sense. But it took me a couple of minutes to figure out what was causing it.

[permalinks]
tags = "/foo/:filename/"

With this content structure:

content
├── post/
│   └── test.md
└── _index.md

Where content/post/test.md has:

tags = ['tag-a']

This is obviously resolved with:

content/
├── post/
│   └── test.md
├── tags/
│   └── tag-a/
│       └── _index.md   <-- now there's a file
└── _index.md

This was a self-inflicted wound; I'm not even sure what the user was trying to accomplish.

Although the warning message is accurate...

  1. The user wasn't able to identify the cause.
  2. The resulting URL is http://localhost:1313/foo/ instead of http://localhost:1313/foo/something

I'm not sure if this is just a documentation issue, or if we should substitute the slug when there isn't a backing file (if that's even possible) and throw a more descriptive warning.

MRE

git clone --single-branch -b hugo-github-issue-9448 https://github.com/jmooring/hugo-testing hugo-github-issue-9448
cd hugo-github-issue-9448
hugo server
@bep bep removed the NeedsTriage label Mar 8, 2022
@bep bep added this to the v0.94.0 milestone Mar 8, 2022
@bep bep changed the title ".File.TranslationBaseName on zero object" warning triggered by :filename in permalink configuration Add a sensible fallback for permalink :filename when not backed by a file Mar 8, 2022
@bep
Copy link
Member

bep commented Mar 8, 2022

We should try to pick a sensible fallback to the filename in this case, I'm not sure what (I have not looked at the options).

@bep bep modified the milestones: v0.94.0, v0.95.0, v0.96.0 Mar 9, 2022
@bep bep modified the milestones: v0.96.0, v0.97.0 Mar 24, 2022
@bep bep modified the milestones: v0.97.0, v0.98.0 Apr 13, 2022
@bep bep modified the milestones: v0.98.0, v0.99.0 Apr 28, 2022
@bep bep modified the milestones: v0.99.0, v0.100.0 May 24, 2022
@bep bep modified the milestones: v0.100.0, v0.101.0 May 31, 2022
@bep bep modified the milestones: v0.101.0, v0.102.0 Jun 16, 2022
@bep bep modified the milestones: v0.102.0, v0.103.0 Aug 28, 2022
@bep bep modified the milestones: v0.103.0, v0.104.0 Sep 15, 2022
@bep bep modified the milestones: v0.104.0, v0.105.0 Sep 23, 2022
@bep bep modified the milestones: v0.105.0, v0.106.0 Oct 26, 2022
@bep bep modified the milestones: v0.108.0, v0.109.0 Dec 14, 2022
@bep bep modified the milestones: v0.109.0, v0.111.0, v0.110.0 Jan 26, 2023
@bep bep modified the milestones: v0.111.0, v0.112.0 Feb 15, 2023
@bep bep modified the milestones: v0.112.0, v0.113.0 Apr 15, 2023
@bep bep modified the milestones: v0.113.0, v0.115.0 Jun 13, 2023
@jmooring jmooring changed the title Add a sensible fallback for permalink :filename when not backed by a file Add sensible fallback for permalink :token when not backed by a file Jun 26, 2023
@jmooring
Copy link
Member Author

The ".File.TranslationBaseName on zero object" warning will be seen more frequently as users begin to define permalinks for sections (#10847). I think we need fallbacks for:

:title
:slug
:slugorfilename
:filename

Example config:

[languages.de.permalinks.term]
tags = 'my-tags-de/:slug'

@bep bep self-assigned this Jun 26, 2023
@bep
Copy link
Member

bep commented Jun 26, 2023

@jmooring thanks, I merged that permalink issue knowing that it needed some tweaking/testing. The gist of the above is that we should never see that warning from Hugo code.

bep added a commit to bep/hugo that referenced this issue Jun 28, 2023
bep added a commit to bep/hugo that referenced this issue Jun 28, 2023
bep added a commit to bep/hugo that referenced this issue Jun 28, 2023
bep added a commit to bep/hugo that referenced this issue Jun 28, 2023
bep added a commit to bep/hugo that referenced this issue Jun 29, 2023
* Move config loading to the page package
* Fix a lower bound panic for the `:sections` slice syntax.
* Always return the `:title`
* Add some permalinks integration tests
* Also see issues below

Fixes gohugoio#9448
Fixes gohugoio#11184
See gohugoio#8523
bep added a commit to bep/hugo that referenced this issue Jun 29, 2023
* Move config loading to the page package
* Fix a lower bound panic for the `:sections` slice syntax.
* Always return the `:title`
* Add some permalinks integration tests
* Also see issues below

Fixes gohugoio#9448
Fixes gohugoio#11184
See gohugoio#8523
bep added a commit that referenced this issue Jun 29, 2023
* Move config loading to the page package
* Fix a lower bound panic for the `:sections` slice syntax.
* Always return the `:title`
* Add some permalinks integration tests
* Also see issues below

Fixes #9448
Fixes #11184
See #8523
@github-actions
Copy link

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 Jul 21, 2023
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.

2 participants