Skip to content

Commit

Permalink
HOME_REDIRECT
Browse files Browse the repository at this point in the history
  • Loading branch information
abernier committed Aug 11, 2024
1 parent 5300b0e commit d9e0234
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ on:
required: false
type: string
default: 'https://github.com/${{ github.repository }}/raw/${{ github.ref_name }}'
home_redirect:
required: true
type: string
default: '/getting-started/introduction'

jobs:
build-job:
Expand All @@ -32,16 +36,16 @@ jobs:
-e MDX \
-e NEXT_PUBLIC_LIBNAME \
-e OUTPUT=export \
-e HOME_REDIRECT \
-e INLINE_IMAGES_ORIGIN \
ghcr.io/pmndrs/docs:app-router npm run build
env:
BASE_PATH: ${{ steps.configurepages.outputs.base_path }}
MDX: ${{ inputs.mdx }}
NEXT_PUBLIC_LIBNAME: ${{ inputs.libname }}
HOME_REDIRECT: ${{ inputs.home_redirect }}
INLINE_IMAGES_ORIGIN: ${{ inputs.inline_images_origin }}
- run: ls -al ${{ inputs.mdx }}

- uses: actions/upload-pages-artifact@v3
with:
path: ${{ inputs.mdx }}/out${{ steps.configurepages.outputs.base_path }}
42 changes: 31 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,50 @@
| var | description | default |
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| `MDX`\* | Path to `*.mdx` folder<br>NB: can be relative or absolute | none |
| `NEXT_PUBLIC_LIBNAME`\* | Library name | none |
| `BASE_PATH` | base path for the final URL | none |
| `DIST_DIR` | Path to the output folder | none |
| `OUTPUT` | Set to `export` for static `out`put | none |
| `HOME_REDIRECT` | Where the home should redirect | none |
| `INLINE_IMAGES_ORIGIN` | [Origin](https://developer.mozilla.org/en-US/docs/Web/API/URL/origin) for inlining relative images<br>Eg: in a `/advanced/introduction.mdx` file, `<img src="./dog.png" />` becomes `<img src="https://github.com/pmndrs/uikit/raw/main/advanced/dog.png" />`<br> NB: if none, don't use relative images | none |

# dev

```sh
$ MDX=~/code/pmndrs/react-three-fiber/docs \
NEXT_PUBLIC_LIBNAME="React Three Fiber" \
BASE_PATH= \
DIST_DIR= \
OUTPUT=export \
HOME_REDIRECT=/getting-started/introduction \
INLINE_IMAGES_ORIGIN= \
npm run dev
```

http://localhost:3000/getting-started/introduction
Then go to: http://localhost:3000

> [!TIP]
> If `HOME_REDIRECT=` empty, `/` will not redirect, and instead displays an index of libraries.
# build

```sh
$ rm -rf out; \
\
MDX=~/code/pmndrs/react-three-fiber/docs \
NEXT_PUBLIC_LIBNAME="React Three Fiber" \
BASE_PATH= \
DIST_DIR= \
OUTPUT=export \
HOME_REDIRECT=/getting-started/introduction \
INLINE_IMAGES_ORIGIN= \
npm run build && \
\
npx serve out
```

http://localhost:3000/getting-started/introduction

| var | description | default |
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| `MDX`\* | Path to `*.mdx` folder<br>NB: can be relative or absolute | none |
| `NEXT_PUBLIC_LIBNAME`\* | Library name | none |
| `BASE_PATH` | base path for the final URL | none |
| `DIST_DIR` | Path to the output folder | none |
| `OUTPUT` | Set to `export` for static `out`put | none |
| `INLINE_IMAGES_ORIGIN` | [Origin](https://developer.mozilla.org/en-US/docs/Web/API/URL/origin) for inlining relative images<br>Eg: in a `/advanced/introduction.mdx` file, `<img src="./dog.png" />` becomes `<img src="https://github.com/pmndrs/uikit/raw/main/advanced/dog.png" />`<br> NB: if none, don't use relative images | none |

\* Required

# Docker
Expand All @@ -45,17 +59,23 @@ $ export BASE_PATH=/react-three-fiber; \
export MDX=./docs; \
export NEXT_PUBLIC_LIBNAME="React Three Fiber"; \
export OUTPUT=export; \
export HOME_REDIRECT=/getting-started/introduction; \
export INLINE_IMAGES_ORIGIN=; \
\
rm -rf "$MDX/out"; \
\
docker run --rm --init -it \
-v "$MDX":/app/docs \
-e BASE_PATH \
-e DIST_DIR="$MDX/out$BASE_PATH" \
-e MDX \
-e NEXT_PUBLIC_LIBNAME \
-e OUTPUT \
-e HOME_REDIRECT \
-e INLINE_IMAGES_ORIGIN \
pmndrs-docs npm run build && \
\
npx -y serve "$MDX/out"
```

Then go to http://localhost:3000/react-three-fiber/getting-started/introduction
Then go to: http://localhost:3000/react-three-fiber
3 changes: 2 additions & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ const libs: Record<string, Library> = {
}

export default function Page() {
if (process.env.OUTPUT === 'export') redirect('/getting-started/introduction')
const HOME_REDIRECT = process.env.HOME_REDIRECT
if (HOME_REDIRECT) redirect(HOME_REDIRECT)

return (
<>
Expand Down

0 comments on commit d9e0234

Please sign in to comment.