From 2bd9a148c160a0f0de9ab991c66393c629469c37 Mon Sep 17 00:00:00 2001 From: ranolf Date: Sat, 2 Jun 2018 15:59:29 -0700 Subject: [PATCH] Support publishing to Github Enterprise hosting (#689) * Added support for Github Enterprise GH Pages * Fixed with prettier output * Tweak * Tweak * Tweak --- docs/api-site-config.md | 4 +++- docs/getting-started-publishing.md | 10 ++++++++++ lib/publish-gh-pages.js | 16 +++++++++++----- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/docs/api-site-config.md b/docs/api-site-config.md index 78004db8be44..8f36a49377b1 100644 --- a/docs/api-site-config.md +++ b/docs/api-site-config.md @@ -62,7 +62,7 @@ headerLinks: [ `title` - Title for your website. -`url` - url for your site. +`url` - URL for your website. ### Optional Fields @@ -131,6 +131,8 @@ h1 { `gaGtag` - Set this to `true` if you want to use [global site tags (gtag.js)](https://developers.google.com/gtagjs/) for Google analytics instead of `analytics.js`. +`githubHost` - Hostname of your server. Useful if you are using GitHub Enterprise. + `highlight` - [Syntax highlighting](api-doc-markdown.md) options: * `theme` is the name of the theme used by Highlight.js when highlighting code. You can find the [list of supported themes here](https://github.com/isagalaev/highlight.js/tree/master/src/styles). diff --git a/docs/getting-started-publishing.md b/docs/getting-started-publishing.md index dcc4d454e6cb..228449e4103d 100644 --- a/docs/getting-started-publishing.md +++ b/docs/getting-started-publishing.md @@ -204,3 +204,13 @@ Steps to configure your Docusaurus-powered site on Netlify. 1. Click **Deploy site** You can also configure Netlify to rebuild on every commit to your repo, or only `master` branch commits. + +### Publishing to GitHub Enterprise + +GitHub enterprise installations should work in the same manner as github.com; you only need to identify the organization's GitHub Enterprise host. + +| Name | Description | +| ------------- | ----------------------------------------------- | +| `GITHUB_HOST` | The hostname for the GitHub enterprise server. | + +Alter your `siteConfig.js` to add a property `'githubHost'` which represents the GitHub Enterprise hostname. Alternatively, set an environment variable `GITHUB_HOST` when executing the publish command. diff --git a/lib/publish-gh-pages.js b/lib/publish-gh-pages.js index b31146424eeb..95b2639419ac 100755 --- a/lib/publish-gh-pages.js +++ b/lib/publish-gh-pages.js @@ -35,6 +35,10 @@ const USE_SSH = process.env.USE_SSH; // github.io indicates organization repos that deploy via master. All others use gh-pages. const DEPLOYMENT_BRANCH = PROJECT_NAME.indexOf('.github.io') !== -1 ? 'master' : 'gh-pages'; +const GITHUB_DOMAIN = 'github.com'; +// For GitHub enterprise, allow specifying a different host. +const GITHUB_HOST = + process.env.GITHUB_HOST || siteConfig.githubHost || GITHUB_DOMAIN; if (!ORGANIZATION_NAME) { shell.echo( @@ -52,9 +56,9 @@ if (!PROJECT_NAME) { let remoteBranch; if (USE_SSH === 'true') { - remoteBranch = `git@github.com:${ORGANIZATION_NAME}/${PROJECT_NAME}.git`; + remoteBranch = `git@${GITHUB_HOST}:${ORGANIZATION_NAME}/${PROJECT_NAME}.git`; } else { - remoteBranch = `https://${GIT_USER}@github.com/${ORGANIZATION_NAME}/${PROJECT_NAME}.git`; + remoteBranch = `https://${GIT_USER}@${GITHUB_HOST}/${ORGANIZATION_NAME}/${PROJECT_NAME}.git`; } if (IS_PULL_REQUEST) { @@ -150,9 +154,11 @@ fs.copy( shell.exit(1); } else if (commitResults.code === 0) { // The commit might return a non-zero value when site is up to date. - shell.echo( - `Website is live at: https://${ORGANIZATION_NAME}.github.io/${PROJECT_NAME}` - ); + const websiteURL = + GITHUB_HOST === GITHUB_DOMAIN + ? `https://${ORGANIZATION_NAME}.github.io/${PROJECT_NAME}` // gh-pages hosted repo + : `https://${GITHUB_HOST}/pages/${ORGANIZATION_NAME}/${PROJECT_NAME}`; // GitHub enterprise hosting. + shell.echo(`Website is live at: ${websiteURL}`); shell.exit(0); } }