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

hugo_build - passing baseurl parameter at build time? (-b) #412

Closed
houstonhaynes opened this issue Oct 13, 2019 · 10 comments
Closed

hugo_build - passing baseurl parameter at build time? (-b) #412

houstonhaynes opened this issue Oct 13, 2019 · 10 comments

Comments

@houstonhaynes
Copy link

I've spent quite a bit of time experimenting and reading/researching the Hugo/blogdown documentation and haven't been able to connect the dots yet. I need to trigger the build from a command line (which I can do) but also pass in the "-b" (baseURL) Hugo parameter.

Is there's a pattern for passing in a Hugo build parameter at the command line?

@tcgriffith
Copy link
Collaborator

baseurl is usually set in the config.yaml. could you be more specific about your use case?

@houstonhaynes
Copy link
Author

houstonhaynes commented Oct 14, 2019

I'm not sure how to be more specific. The point of the question is to pass in an override - to avoid a re-write of the baseURL entry in the config.toml - to use the value that's passed in when the build command is executed.

I have both a staging and production instance of the site - and I want to pass in a value so that the refs are correct per-site when I built based on the integration vs master branch of the repo. It's tiered deployment 101 - re-writing the .toml file (that's ostensibly under source control) after check-out somewhat invalidates the fact that the project is built from source. I can certainly do that, but I thought I might ask for advice.

@tcgriffith
Copy link
Collaborator

https://github.com/tcgriffith/owaraisite/blob/master/config.toml

I faced a similar situation like yours. I use "/" as the baseurl so i could deploy it over gh pages and netlify without specifying the baseurl parameter. here is my config.

@houstonhaynes
Copy link
Author

Awesome thanks - was just making my way over to the Netlify page. I'm building a deployment pipeline in GitHub Actions (targeting Azure Blob Static Site/CDN).

I was thinking that TOML might be antagonistic to parameter injection due to some early chatter I read while surfing for options. So I thought transitioning to a YAML file might make sense. I'll take a look at what you've put together. Cheers!

@houstonhaynes
Copy link
Author

Oh - just to follow up after scanning the Netlify TOML reference and your doc - I think using the slash would handicap some of the social links that cascade from that reference. I found that by deploying into my stg. instance with the "/" ref -- social media embeds just broke in a really ugly way.

I looked at some of the notes on alternate build methods and thought about calling hugo directly, but haven't given it a try yet.

I also thought about copying out the entire repo into a new build target folder, and modifying the TOML/YAML value(s) needed so that everything is ephemeral/local. But that seems like too much "squeeze" for not enough "juice". Thanks for the heads-up.

@tcgriffith
Copy link
Collaborator

could you provide your repo? for social links you could provide something like "https://www.github.com" instead of "www.github.com"

I also found this discussion from hugo community, hope this helps:

https://discourse.gohugo.io/t/solved-what-should-be-used-for-the-value-of-site-baseurl/5896/9

@tcgriffith
Copy link
Collaborator

I don't have experience with the gh action.

but for netlify, you could push dev branches/Pull request to github and netlify will deploy the preview in a new url and won't affect the master branch for production, fitting your need for staging and production.

@houstonhaynes
Copy link
Author

According to the source, unless baseurl=“scheme://url.here/” is set, absURL is rendered useless, and that parts of the site don’t get the .Site.BaseURL paramerter they need, thus rendering the site broken in some cases.

...was precisely what I was seeing.

<meta property="og:url" content="/" />

and Leo's Hugo gist suggested what I was hoping to avoid :) which is running hugo directly.

The [potential] problem with doing the ephemeral build (pushing files with modified config into a local directory) is that it may rob Hugo of the handy little feature I was going to take advantage of to embed Git meta info into generated pages. The idea is to do a "proper" CI workflow and generate tests that parse that meta-info after build, then pushes to the static site. Then the idea is to validate against the static site - invalidate the CDN and then do a final check through the "top" to ensure that the latest versions of the pages are pushed up. (and yes, it's a cheat to also warm the cache)

But as they say - it's can't hurt to try... ;)

@yihui
Copy link
Member

yihui commented Oct 15, 2019

hugo_build() is a wrapper function based on hugo_cmd(), so you can actually call the latter directly, e.g.,

blogdown::hugo_cmd(shQuote(c('-b', 'your/custom/base/url')))

@houstonhaynes
Copy link
Author

houstonhaynes commented Oct 15, 2019

Ah - BINGO! A thousand thank-yous!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants