DaveH
January 22, 2025, 3:07pm
1
Hello - Loving content adapters! Many thanks for this feature.
I have uglyURLs = true
set in my hugo.toml
file, which is working on all files except those generated by a content adapter.
Those generated by the content adapter follow the pretty url pattern: file-name/index.html
, where as I need to end up with file-name.html
.
Is there a way to make sure this flag is respected by the adapter? Or have I missed something here? Thanks in advance.
irkode
January 22, 2025, 5:07pm
2
I’m on hugo v0.140.1 and for me that works fine (also with v0.126.0 where that was introduced)
looks like you have something wrong in your code which you would have to share for help.
Try it out:
hugo new theme --themesDir . adapter
cd adapter
set uglyURLS = true
in hugo toml
add BEFORE the first array definition
baseURL = 'https://example.org/'
languageCode = 'en-US'
title = 'My New Hugo Site'
uglyURLs = true
[[menus.main]]
name = 'Home'
pageRef = '/'
weight = 10
[[menus.main]]
name = 'Posts'
pageRef = '/posts'
weight = 20
[[menus.main]]
name = 'Tags'
pageRef = '/tags'
weight = 30
[module]
[module.hugoVersion]
extended = false
min = "0.116.0"
create content adapter in /content/posts/_content.gotpl
{{ $content := dict
"mediaType" "text/markdown"
"value" "Uglyurl"
}}
{{ $page := dict
"content" $content
"kind" "page"
"path" "post-4"
"title" "adpter"
}}
{{ .AddPage $page }}
hugo
will create /public/posts/post-4.html
├───posts
│ │ index.xml
│ │ post-1.html
│ │ post-2.html
│ │ post-3.html
│ │ post-4.html <-- created by the adapter
1 Like
DaveH
January 23, 2025, 8:26am
3
Thanks for the advice - much appreciated.
The screenshot below shows the configs and output from the qa config:
I think this is the key bit from the content adapter as it stands right now
{{ $clinicianBio := dict }}
{{ $brochureClinicianBioCMS := printf "%s/%s/%s" $base_url $api $v }}
{{ with resources.GetRemote $brochureClinicianBioCMS }}
{{ with .Err }}
{{ errorf "Unable to get remote resource %s" $brochureClinicianBioCMS }}
{{ else }}
{{ $clinicianBio = . | transform.Unmarshal }}
{{ $content := dict "mediaType" "text/markdown" "value" $clinicianBio.content }}
{{ $page := dict
"content" $content
"kind" "page"
"path" $clinicianBio.path
"slug" $clinicianBio.path
"url" $clinicianBio.url
"title" $clinicianBio.title
"params" $clinicianBio.params
"layout" "clinician-bio/single"
}}
{{ $.AddPage $page }}
The code above is in a range which is why I can set $clinicianBio to the dot. I am on Hugo version 0.138.
irkode
January 23, 2025, 8:39am
4
thx for sharing some code, but it does not make sense to setup something, that might be exactly yours.
you have a reproducible failure. please provide a runnable repo so we can really check what’s going on.
you have site setup around, remote data…
1 Like
DaveH
January 23, 2025, 9:06am
5
OK thanks. I can’t really do share the repo as it’s a private repo for work. I will have a think and see if I can get to the bottom of it. Thanks again for your help.
irkode
January 23, 2025, 10:17am
6
have you tried to set the default to true? if all your builds use true that does not make sense to me.
Hints
print down the values of these directly after assigning a value to them - maybe you can identify something special for the wrongly generated pages there.
{{ $clinicianBio = . | transform.Unmarshal }}
{{ warnf "%s" ($clinicianBio| jsonify (dict "indent" " ")) }}
...
{{ $page := dict ... }}
{{ warnf "%s" ($page | jsonify (dict "indent" " ")) }}
with that info you might be able to provide a one pager reproducable example by adding your config and ssimple layout around.
you use these
"path" $clinicianBio.path
"slug" $clinicianBio.path
"url" $clinicianBio.url
might be they interfere
DaveH
January 23, 2025, 11:29am
7
irkode:
"url" $clinicianBio.url
I removed the above and that seems to have fixed the problem!!
I have tried different values, and even an empty string, and any value seems to cause the problem.
I don’t understand Hugo well enough to understand what or why this should be.
Many thanks for your help with this. It’s really appreciated.
irkode
January 23, 2025, 11:32am
8
have look here: URL management | Hugo
If you set both slug
and url
in front matter, the url
value takes precedence.
sounds like it is never a good idea to set both
1 Like
system
Closed
January 25, 2025, 11:32am
9
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.