Skip to content

Commit

Permalink
Support publishing to Github Enterprise hosting (#689)
Browse files Browse the repository at this point in the history
* Added support for Github Enterprise GH Pages

* Fixed with prettier output

* Tweak

* Tweak

* Tweak
  • Loading branch information
ranolf authored and yangshun committed Jun 2, 2018
1 parent 93b2ebb commit 2bd9a14
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
4 changes: 3 additions & 1 deletion docs/api-site-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ headerLinks: [

`title` - Title for your website.

`url` - url for your site.
`url` - URL for your website.

### Optional Fields

Expand Down Expand Up @@ -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).
Expand Down
10 changes: 10 additions & 0 deletions docs/getting-started-publishing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
16 changes: 11 additions & 5 deletions lib/publish-gh-pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 2bd9a14

Please sign in to comment.