From 2250f33eebd78ecbe861928db0df8e8e67bda0d5 Mon Sep 17 00:00:00 2001 From: Michal Radecki Date: Thu, 16 Dec 2021 15:13:05 +0100 Subject: [PATCH 1/2] feat(project): hash based router for github pages --- scripts/deploy-github.js | 1 + src/App.tsx | 5 ++--- src/components/Router/Router.tsx | 10 ++++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 src/components/Router/Router.tsx diff --git a/scripts/deploy-github.js b/scripts/deploy-github.js index 468680ac4..2a6e7596a 100644 --- a/scripts/deploy-github.js +++ b/scripts/deploy-github.js @@ -77,6 +77,7 @@ function getEnv() { return { ...process.env, SNOWPACK_PUBLIC_BASE_URL: getBaseUrl(), + SNOWPACK_PUBLIC_GITHUB_PAGES: true, } } diff --git a/src/App.tsx b/src/App.tsx index c55040c9d..5d4c99f73 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -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'; @@ -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; @@ -61,7 +60,7 @@ class App extends Component { onValidationError={this.configErrorHandler} onValidationCompleted={this.configValidationCompletedHandler} > - + diff --git a/src/components/Router/Router.tsx b/src/components/Router/Router.tsx new file mode 100644 index 000000000..e2dddf8da --- /dev/null +++ b/src/components/Router/Router.tsx @@ -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 ; + } + return ; +} From 2426b2770e8615af2edfbcc2d3a8b7c5bd03b08e Mon Sep 17 00:00:00 2001 From: Michal Radecki Date: Mon, 20 Dec 2021 12:23:23 +0100 Subject: [PATCH 2/2] fix(project): fix for custom domains base url --- docs/easy-deployments.md | 8 ++++---- scripts/deploy-github.js | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/easy-deployments.md b/docs/easy-deployments.md index c4af18170..486018a7e 100644 --- a/docs/easy-deployments.md +++ b/docs/easy-deployments.md @@ -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`
diff --git a/scripts/deploy-github.js b/scripts/deploy-github.js index 2a6e7596a..af37f8460 100644 --- a/scripts/deploy-github.js +++ b/scripts/deploy-github.js @@ -68,7 +68,7 @@ function getBaseUrl() { return envBaseUrl; } const defaultBaseUrl = customDomain - ? '/' + ? '' : '/' + getGithubDir() + '/'; return defaultBaseUrl; } @@ -111,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')); }