Search code examples
githubgithub-pages

Can I define a domain root for links in GitHub pages?


I am creating a user guide for my web app using GitHub pages in the web app's repo.

I want to have links in the user guide to the appropriate pages in the web app. I can hard code the entire thing. But I'd prefer to set the app domain in one place and then use that domain for all urls.

So something like:

ROOT_DOMAIN=MyApp.com

And then in the markdown have [Login](%ROOT_DOMAIN%/account/login). Is there a way to do this?


Solution

  • The default static site generator for GitHub Pages is Jekyll, and it lets you configure the repository base URL in _config.yml via the baseurl setting; see the docs:

    Setting Options and flags
    Base URL
    Serve the website from the given base URL.
    baseurl: URL
    -b, --baseurl URL

    where -b/--baseurl URL is the command line option for the jekyll command, and baseurl: URL is the YAML config setting.