When I run the Hugo command to generate the public folder index file.html has no CSS and the images are not displayed in the browser!
In the config.toml file I have:
baseURL = ''
uglyURLs = true
canonifyURLs = true
relativeURLS=true
And the head.html ( partials ) i have;
<link rel="stylesheet" href="{{ "css/style.css" | relURL}}">
How to make it work and the CSS is displayed ?
Please share a public repository, it’s difficult to help without knowing the code of your project.
baseURL = '' --> INVALID
uglyURLs = true
canonifyURLs = true --> WHY?
relativeURLS=true --> WHY?
Are you trying to open the file directly with your browser, or are you running hugo server
?
I open the file directly with my browser,
I fixed the problem by changing “/css/style.css” with “css/style.css” and for images I changed “/img/image.png” with “…/img/image.png” in the CSS but it’s not enough because every time I generate the public folder I have to make changes to index.html and style.css !
Why? This is an unusual use case.
If the files are server using a web server then the “/” means “webroot”
If you open the file manually that isn’t the same thing - it will be the root of the filesystem
how to display the images correctly without making changes to the /public folder?
I felt that the result was the same when I deploy the site online !
They are not the same thing.
A site that you can navigate via the file system requires special handling in a number of areas, and is a rare requirement / use case.
A site that is served (with either hugo server
or your production server):
-
Must have a valid baseURL
in site configuration.
The absolute URL (protocol, host, path, and trailing slash) of your published site (e.g., https://www.example.org/docs/
).
See https://gohugo.io/getting-started/configuration/#baseurl
-
Should have relativeURLs = false
-
Should have canonifyURLs = false
-
Should probably have uglyURLs = false