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

BC-106 GitHub pages custom domain #8

Merged
merged 2 commits into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/easy-deployments.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ Github pages have some [usage limits](https://docs.github.com/en/pages/getting-s

### Usage Instructions

1. Confirm that you can [build this project from source](./build-from-source.md). Be sure to install optional dependencies.
2. Enable the [Github Pages feature](https://docs.github.com/en/pages/getting-started-with-github-pages) for the `gh-pages` branch in your repository.
3. Run `yarn deploy:github`. Be sure to follow the instructions that appear on the screen.
4. (Optional) If you need a customization option, review `yarn deploy:github --help`.
1. (Optional) If you need a customization option, review `yarn deploy:github --help`.
2. Confirm that you can [build this project from source](./build-from-source.md). Be sure to install optional dependencies.
3. Enable the [Github Pages feature](https://docs.github.com/en/pages/getting-started-with-github-pages) for the `gh-pages` branch in your repository.
4. Run `yarn deploy:github`. Be sure to follow the instructions that appear on the screen. If you want to connect your github deployment to a custom domain remember to add `--custom-domain=mydomain.com`

<br />

Expand Down
4 changes: 3 additions & 1 deletion scripts/deploy-github.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function getBaseUrl() {
return envBaseUrl;
}
const defaultBaseUrl = customDomain
? '/'
? ''
: '/' + getGithubDir() + '/';
return defaultBaseUrl;
}
Expand All @@ -77,6 +77,7 @@ function getEnv() {
return {
...process.env,
SNOWPACK_PUBLIC_BASE_URL: getBaseUrl(),
SNOWPACK_PUBLIC_GITHUB_PAGES: true,
}
}

Expand Down Expand Up @@ -110,6 +111,7 @@ function help() {
"--deploy - don't ask for deploy confirmation",
'--deploy-args="--help" - pass arguments to gh-pages, in this case gh-pages --help',
'--github-remote="origin" - select github remote to use to detect github project name, default is "origin"',
'--custom-domain="example.com" - (no slashes) deploy to custom domain instead of github directory',
'',
].join('\n'));
}
Expand Down
5 changes: 2 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { Component } from 'react';
import { BrowserRouter as Router } from 'react-router-dom';
import { I18nextProvider, getI18n } from 'react-i18next';
import type { Config } from 'types/Config';

import Router from './components/Router/Router';
import Root from './components/Root/Root';
import ConfigProvider from './providers/ConfigProvider';
import QueryProvider from './providers/QueryProvider';
Expand All @@ -11,7 +11,6 @@ import './styles/main.scss';
import { restoreWatchHistory } from './stores/WatchHistoryStore';
import { initializeFavorites } from './stores/FavoritesStore';
import { initializeAccount } from './stores/AccountStore';
import { getPublicUrl } from './utils/domHelpers';

interface State {
error: Error | null;
Expand Down Expand Up @@ -61,7 +60,7 @@ class App extends Component {
onValidationError={this.configErrorHandler}
onValidationCompleted={this.configValidationCompletedHandler}
>
<Router basename={getPublicUrl('/')}>
<Router>
<Root error={this.state.error} />
</Router>
</ConfigProvider>
Expand Down
10 changes: 10 additions & 0 deletions src/components/Router/Router.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import { BrowserRouter, HashRouter } from 'react-router-dom';
import type { BrowserRouterProps, HashRouterProps } from 'react-router-dom';

export default function Router(props: BrowserRouterProps | HashRouterProps) {
if (import.meta.env.SNOWPACK_PUBLIC_GITHUB_PAGES) {
return <HashRouter {...props} />;
}
return <BrowserRouter {...props} />;
}