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

how to adjust the HUGO_BASE_URL? #90

Open
Adeljoo opened this issue Mar 16, 2020 · 5 comments
Open

how to adjust the HUGO_BASE_URL? #90

Adeljoo opened this issue Mar 16, 2020 · 5 comments

Comments

@Adeljoo
Copy link

Adeljoo commented Mar 16, 2020

I want to use another url instead of localhost in production, how can I do that? my URL starts with https instead of http and it does not work.

@gavinr
Copy link

gavinr commented Mar 16, 2020

I think it honors the baseURL property of your hugo config.toml - have you tried changing that?

@znegva
Copy link

znegva commented May 24, 2020

The image seems not to honor the baseURL setting from config-toml

I got it working by providing the Environment variable (HUGO_BASEURL) by:

docker run --rm -P --volume $(PWD):/src --volume ${PWD}/public:/output --env HUGO_BASEURL=https://mycoolwebsite.com jojomi/hugo

I think the baseURL from config.toml should be used if no explicit environment variable is set!


I think this could be achieved by pimping https://github.com/jojomi/docker-hugo/blob/master/run.sh a bit, just pass argument --baseURL="$HUGO_BASEURL" if environment-variable HUGO_BASEURL is set.

I think the same problem exists for themes defined in config.toml, but not provided as environment-variable.

@jojomi
Copy link
Owner

jojomi commented May 30, 2020

@znegva Thanks for your analysis which I think is correct. Would you be able and willing to supply a PR with a patch for this?

@znegva
Copy link

znegva commented Jun 13, 2020

Sorry @jojomi , I dont have much time left for side projects (and testing ;) )

But it should be something like this:

#!/bin/sh

WATCH="${HUGO_WATCH:=false}"
SLEEP="${HUGO_REFRESH_TIME:=-1}"
HUGO_DESTINATION="${HUGO_DESTINATION:=/output}"
echo "HUGO_WATCH:" $WATCH
echo "HUGO_REFRESH_TIME:" $HUGO_REFRESH_TIME
echo "HUGO_THEME:" $HUGO_THEME
echo "HUGO_BASEURL" $HUGO_BASEURL
echo "ARGS" $@

HUGO=/usr/local/sbin/hugo
echo "Hugo path: $HUGO"

BASEURL_ARG="--baseURL=${HUGO_BASEURL}"
if [ "$HUGO_BASEURL" = "" ]; then
   BASEURL_ARG = ""
fi

THEME_ARG="--theme=${HUGO_THEME}"
if [ "$HUGO_THEME" = "" ]; then
   THEME_ARG = ""
fi

while [ true ]
do
    if [[ $HUGO_WATCH != 'false' ]]; then
	    echo "Watching..."
        $HUGO server --watch=true --source="/src" $THEME_ARG --destination="$HUGO_DESTINATION" $BASEURL_ARG --bind="0.0.0.0" "$@" || exit 1
    else
	    echo "Building one time..."
        $HUGO --source="/src" $THEME_ARG --destination="$HUGO_DESTINATION" $BASEURL_ARG "$@" || exit 1
    fi

    if [[ $HUGO_REFRESH_TIME == -1 ]]; then
        exit 0
    fi
    echo "Sleeping for $HUGO_REFRESH_TIME seconds..."
    sleep $SLEEP
done

@Adeljoo
Copy link
Author

Adeljoo commented Jun 17, 2020

If it's not late, I change the --baseURL="$HUGO_BASEURL" in the Dockerfile and also in the config.toml, then was good to go.

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

4 participants