How to get hugo.toml's configured baseURL during local dev?

During local development with Hugo v0.120.3, when running hugo server -D, it seems .Site.BaseURL gets replaced with localhost.

From the LinkedIn Post Inspector we can see LinkedIn won’t play nice when localhost is in the URL. So to still enable local dev, I would like to access the hugo.toml’s baseURL in certain places of my site when accessing .Site.BaseURL.

So my question is, when running hugo server -D, is there some way to still get access to the hugo.toml’s baseURL (and not localhost)?

There’s almost never a good reason to use .Site.BaseURL in your templates.

When running hugo server, you can specify the baseURL, port, etc.

hugo server --help
1 Like

Yeah I was playing around with this, the issue faced here is the rest of the site no longer works when manually passing hugo server -D --baseURL "https://foo.com".

I am wondering if there’s some way to have .Site.BaseURL be localhost everywhere but one (involving part with LinkedIn sharing). All good if not, it’s sort of snowflake-y thing

Out of curiosity, what would you recommend instead of .Site.BaseURL? Is there some other Hugo variable I should be using instead?

absURL or absLangURL in the docs.

1 Like

Thanks for sharing! Appreciated.

I was just trying absURL "" and it also resolves to localhost when running hugo server -D. Is there some way to have absURL resolve to the published URL? I don’t see anything about that in the absURL docs