Skip to content

Commit d4a3971

Browse files
committed
Make custom domain configurable in deploy config
1 parent ecea839 commit d4a3971

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

.github/workflows/deploy-github-pages.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ jobs:
3838
env:
3939
GITHUB_ACTIONS: true
4040
GITHUB_REPOSITORY: ${{ github.repository }}
41+
# Set CUSTOM_DOMAIN=true when using custom domain (e.g., opentechschool.org)
42+
# CUSTOM_DOMAIN: true
4143

4244
- name: Upload artifact
4345
uses: actions/upload-pages-artifact@v3

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,15 @@ This website is deployed to GitHub Pages. Every push to the `github-pages-new` b
151151

152152
To test the GitHub Pages build locally with the correct basePath configuration:
153153

154+
Note: We are using `out` instead of `websitenext`, but the github action will copy files from `out` to `websitenext`
155+
154156
```bash
155157
# Build and export with GitHub Pages environment variables
156-
GITHUB_ACTIONS=true GITHUB_REPOSITORY=OpenTechSchool/websitenext npm run build
157-
GITHUB_ACTIONS=true GITHUB_REPOSITORY=OpenTechSchool/websitenext npx next export
158+
GITHUB_ACTIONS=true GITHUB_REPOSITORY=OpenTechSchool/out npm run build
159+
GITHUB_ACTIONS=true GITHUB_REPOSITORY=OpenTechSchool/out npx next export
158160

159161
# The static files will be generated in the 'out' directory
160-
# All asset paths (images, fonts, links) will include the /websitenext basePath
162+
# All asset paths (images, fonts, links) will include the /out basePath
161163
```
162164

163165
**Important:** When building for GitHub Pages, the build process:
@@ -174,6 +176,10 @@ npm run build # Production build (local)
174176
npm run export # Static export (local)
175177
```
176178

179+
### Using a custom domain
180+
181+
Set `CUSTOM_DOMAIN` to true in `deploy-github-pages.yml` when using a custom domain e.g. opentechschool.org
182+
177183
## Contact
178184

179185
Found an issue, a bug or have an idea for a great new feature?

next.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
const path = require('path')
22

33
const isGithubActions = process.env.GITHUB_ACTIONS || false
4+
const hasCustomDomain = process.env.CUSTOM_DOMAIN === 'true'
45

56
let assetPrefix = ''
67
let basePath = ''
78

8-
if (isGithubActions) {
9+
if (isGithubActions && !hasCustomDomain) {
910
const repo = process.env.GITHUB_REPOSITORY.replace(/.*?\//, '')
1011
assetPrefix = `/${repo}/`
1112
basePath = `/${repo}`
@@ -36,5 +37,6 @@ module.exports = {
3637
// Make build-time environment variables available at runtime
3738
NEXT_PUBLIC_GITHUB_ACTIONS: process.env.GITHUB_ACTIONS || 'false',
3839
NEXT_PUBLIC_GITHUB_REPOSITORY: process.env.GITHUB_REPOSITORY || '',
40+
NEXT_PUBLIC_CUSTOM_DOMAIN: process.env.CUSTOM_DOMAIN || 'false',
3941
},
4042
}

pages/_document.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import Document, { Html, Head, Main, NextScript } from 'next/document'
44
export default class MyDocument extends Document {
55
render() {
66
const isGithubActions = process.env.GITHUB_ACTIONS || false
7-
const basePath = isGithubActions ? `/${process.env.GITHUB_REPOSITORY?.replace(/.*?\//, '') || ''}` : ''
7+
const hasCustomDomain = process.env.CUSTOM_DOMAIN === 'true'
8+
const basePath = (isGithubActions && !hasCustomDomain) ? `/${process.env.GITHUB_REPOSITORY?.replace(/.*?\//, '') || ''}` : ''
89

910
return (
1011
<Html lang='en'>

style/style-global.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import css from 'styled-jsx/css'
22
import { mediaquery } from './style.js'
33

44
const isGithubActions = process.env.NEXT_PUBLIC_GITHUB_ACTIONS || false
5-
const basePath = isGithubActions ? `/${process.env.NEXT_PUBLIC_GITHUB_REPOSITORY?.replace(/.*?\//, '') || ''}` : ''
5+
const hasCustomDomain = process.env.NEXT_PUBLIC_CUSTOM_DOMAIN === 'true'
6+
const basePath = (isGithubActions && !hasCustomDomain) ? `/${process.env.NEXT_PUBLIC_GITHUB_REPOSITORY?.replace(/.*?\//, '') || ''}` : ''
67

78
export default css.global`
89
:root {

0 commit comments

Comments
 (0)