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

generator #282

Merged
merged 84 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
8d72067
wip
abernier Aug 8, 2024
c328aba
no more home
abernier Aug 9, 2024
7f8f33e
MDX + LIBNAME
abernier Aug 9, 2024
eeffd78
Codesandbox[embed]
abernier Aug 9, 2024
e64566e
MenuContext
abernier Aug 9, 2024
f4e92d8
Menu
abernier Aug 9, 2024
fc7566b
cache fetchCSB
abernier Aug 9, 2024
ab6b35f
toc fix
abernier Aug 9, 2024
b85183d
bin
abernier Aug 9, 2024
df6fd4a
Dockerfile
abernier Aug 9, 2024
c8c7891
docker workflow
abernier Aug 9, 2024
c425a6e
reusable + caller
abernier Aug 9, 2024
c91f85d
sample docs
abernier Aug 9, 2024
fc0e660
NEXT_PUBLIC_LIBNAME fix
abernier Aug 9, 2024
bf3d25f
doc
abernier Aug 9, 2024
5adda21
DIST_DIR base on BASE_PATH
abernier Aug 9, 2024
49a502d
doc
abernier Aug 10, 2024
31551f0
fix: nav grouping
abernier Aug 10, 2024
c8f9434
remove docs
abernier Aug 10, 2024
6e73f9c
fixing tailwind issue
abernier Aug 10, 2024
5efb2d7
doc
abernier Aug 10, 2024
9c62212
npm + working bin
abernier Aug 10, 2024
2ead74e
doc
abernier Aug 10, 2024
c35c0f5
more dockerignored files
abernier Aug 10, 2024
08d2fed
-p-memoize
abernier Aug 10, 2024
9a69316
npm up
abernier Aug 10, 2024
1a59d50
node 22
abernier Aug 10, 2024
a8a0b94
rm unused pkg
abernier Aug 10, 2024
9916610
clsx up
abernier Aug 10, 2024
896587a
OUTPUT
abernier Aug 10, 2024
37f5bcd
node 18
abernier Aug 10, 2024
4d09210
legacy homepage
abernier Aug 10, 2024
f869d8e
preparing the redirects
abernier Aug 10, 2024
2ca7488
more redirects
abernier Aug 11, 2024
694dcda
react-three-a11y
abernier Aug 11, 2024
fe20bdc
semantic-release-action
abernier Aug 11, 2024
afb385f
semantic_version: 24
abernier Aug 11, 2024
406bb85
release.config.mjs
abernier Aug 11, 2024
f3f64f9
fix: missing exports
abernier Aug 11, 2024
fdb958e
tweaks
abernier Aug 11, 2024
47204de
feat: INLINE_IMAGES_ORIGIN
abernier Aug 11, 2024
ac6925e
fix: inline_images_origin
abernier Aug 11, 2024
79f910c
fix: inline images bug
abernier Aug 11, 2024
5300b0e
fix: more redirs
abernier Aug 11, 2024
d9e0234
HOME_REDIRECT
abernier Aug 11, 2024
13eedab
doc
abernier Aug 11, 2024
c6eec21
doc
abernier Aug 11, 2024
15de64e
example values
abernier Aug 11, 2024
631d943
doc
abernier Aug 11, 2024
5c51411
doc
abernier Aug 11, 2024
f50edd0
-redirs
abernier Aug 11, 2024
c9040ca
doc
abernier Aug 11, 2024
c39f32a
doc
abernier Aug 11, 2024
54a4cf9
tweaks
abernier Aug 11, 2024
0a3b0bf
local INLINE_IMAGES_ORIGIN support
abernier Aug 12, 2024
7c7d5ac
doc
abernier Aug 12, 2024
fc2a330
rn
abernier Aug 12, 2024
37b04e0
smooth scroll
abernier Aug 12, 2024
57b0515
fix: search
abernier Aug 12, 2024
ed6b3fe
fix: footer nav
abernier Aug 12, 2024
7699441
EDIT_ORIGIN
abernier Aug 12, 2024
c78cec8
doc
abernier Aug 12, 2024
3842ca4
.docs
abernier Aug 12, 2024
d48f66c
svg icon + metadata
abernier Aug 14, 2024
afa7f30
metadataImage
abernier Aug 14, 2024
4e91439
doc
abernier Aug 14, 2024
32c82f5
Update README.md
abernier Aug 14, 2024
c65c147
baseurl
abernier Aug 14, 2024
fd43b89
Merge branch 'app-router' of https://github.com/pmndrs/docs into app-…
abernier Aug 14, 2024
9be3e2d
-inline_images_baseurl
abernier Aug 14, 2024
3e7d202
doc
abernier Aug 14, 2024
8cca855
doc
abernier Aug 14, 2024
b28eaf8
Update README.md
abernier Aug 14, 2024
1fc5570
image tweaks
abernier Aug 15, 2024
d313fe3
Merge branch 'app-router' of https://github.com/pmndrs/docs into app-…
abernier Aug 15, 2024
8252679
EMOJI
abernier Aug 15, 2024
e3dc57b
LOGO
abernier Aug 15, 2024
3a1920d
ICON
abernier Aug 15, 2024
9e734a4
fix icon
abernier Aug 15, 2024
3345fd8
doc
abernier Aug 15, 2024
7c1bf93
set-base-path
abernier Aug 15, 2024
cb552de
uikit, xr redirects
abernier Aug 15, 2024
c3a2a9f
home metadatas
abernier Aug 15, 2024
159f986
removing app-router branch references
abernier Aug 15, 2024
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
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
out
.next
66 changes: 66 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Reusable pmndrs/docs workflow

on:
workflow_call:
inputs:
mdx:
required: true
type: string
libname:
required: true
type: string
home_redirect:
required: true
type: string
default: '/getting-started/introduction'
icon:
type: string
default: 'πŸ–¨οΈ'
logo:
type: string
default: '/logo.png'
base_path:
type: string

jobs:
build-job:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- id: configurepages
uses: actions/configure-pages@v5
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#example-of-setting-an-output-parameter
- id: set-base-path
run: echo "BASE_PATH=${{ inputs.base_path || steps.configurepages.outputs.base_path }}" >> "$GITHUB_OUTPUT"
- run: |
set -ex

docker run --rm --init \
-v "$MDX":/app/docs \
-e BASE_PATH \
-e DIST_DIR="$MDX/out$BASE_PATH" \
-e MDX \
-e NEXT_PUBLIC_LIBNAME \
-e OUTPUT=export \
-e HOME_REDIRECT \
-e MDX_BASEURL \
-e EDIT_BASEURL \
-e NEXT_PUBLIC_URL \
-e ICON \
-e LOGO \
ghcr.io/pmndrs/docs:main npm run build
env:
BASE_PATH: ${{ steps.set-base-path.outputs.BASE_PATH }}
MDX: ${{ inputs.mdx }}
NEXT_PUBLIC_LIBNAME: ${{ inputs.libname }}
HOME_REDIRECT: ${{ inputs.home_redirect }}
MDX_BASEURL: 'https://github.com/${{ github.repository }}/raw/${{ github.ref_name }}/${{ inputs.mdx }}'
EDIT_BASEURL: 'https://github.com/${{ github.repository }}/edit/${{ github.ref_name }}/${{ inputs.mdx }}'
NEXT_PUBLIC_URL: ${{ steps.configurepages.outputs.base_url }}
ICON: '${{ inputs.icon }}'
LOGO: '${{ inputs.logo }}'

- uses: actions/upload-pages-artifact@v3
with:
path: ${{ inputs.mdx }}/out${{ steps.set-base-path.outputs.BASE_PATH }}
60 changes: 60 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# https://docs.github.com/en/actions/publishing-packages/publishing-docker-images#publishing-images-to-github-packages
name: Create and publish a Docker image
on:
push:
branches: ['main']

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest

permissions:
contents: write # 'write' required for semantic-release-action
packages: write
attestations: write
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# will generate a git tag => then, used by docker/metadata-action
- name: Semantic Release
id: semantic_release
uses: cycjimmy/semantic-release-action@v4
with:
semantic_version: 24
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
9 changes: 3 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
.pnp.js
node_modules/

# dependency lock files
package-lock.json
pnpm-lock.yaml
yarn.lock

# other
.next/
.DS_Store
Expand All @@ -20,4 +15,6 @@ dist/
logs/
out/
tmp/
temp/
temp/

tsconfig.tsbuildinfo
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node:18-alpine

RUN apk add --no-cache libc6-compat git && apk update
WORKDIR /app

COPY package.json package-lock.json ./
RUN npm ci

COPY . .
File renamed without changes.
205 changes: 205 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
# Configuration

| var | description | example |
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------- |
| `MDX`\* | Path to `*.mdx` folder<br>NB: can be relative or absolute | `docs` or `~/code/myproject/documentation` |
| `NEXT_PUBLIC_LIBNAME`\* | Library name | `React Three Fiber` |
| `BASE_PATH` | Base path for the final URL | `/react-three-fiber` |
| `DIST_DIR` | Path to the output folder ([within project](https://nextjs.org/docs/app/api-reference/next-config-js/distDir#:~:text=should%20not%20leave%20your%20project%20directory)) | `out` or `docs/out/react-three-fiber` |
| `OUTPUT` | Set to `export` for static output | `export` |
| `HOME_REDIRECT` | Where the home should redirect | `/getting-started/introduction` |
| `MDX_BASEURL` | Base URL for inlining relative images | `http://localhost:60141`or `https://github.com/pmndrs/react-three-fiber/raw/master/docs` |
| `EDIT_BASEURL` | Base URL for displaying "Edit this page" URLs | `https://github.com/pmndrs/react-three-fiber/edit/master/docs` |
| `NEXT_PUBLIC_URL` | Final URL of the published website | `https://pmndrs.github.io/react-three-fiber` |
| `ICON` | Emoji or image to use as (fav)icon (path local to `MDX`) | `πŸ‡¨πŸ‡­` or `/icon.png` or `/favicon.ico` |
| `LOGO` | Logo src/path (either FQURL or local to `MDX` path) | `/logo.png` or `https://worldvectorlogo.com/r3f.png` |

\* Required

<details>
<summary>`MDX_BASEURL`</summary>

Given a `advanced/introduction.mdx` file in the `MDX` folder:

```mdx
![](dog.png)
```

becomes (for a `MDX_BASEURL=http://localhost:60141` value):

```mdx
![](http://localhost:60141/advanced/dog.png)
```

`http://localhost:60141` being the `MDX` folder served.

> [!TIP]
> When deployed on GitHub Pages, `MDX_BASEURL` will typically value something like `https://github.com/pmndrs/uikit/raw/main/docs`, thanks to [`build.yml`](.github/workflows/build.yml) rule.

</details>

# dev

```sh
$ (
trap 'kill -9 0' SIGINT

export _PORT=60141

# [Config](https://github.com/pmndrs/docs#configuration)
export MDX=~/code/pmndrs/react-three-fiber/docs
export NEXT_PUBLIC_LIBNAME="React Three Fiber"
export BASE_PATH=
export DIST_DIR=
export OUTPUT=export
export HOME_REDIRECT=/getting-started/introduction
export MDX_BASEURL=http://localhost:$_PORT
export EDIT_BASEURL="vscode://file/$MDX"
export NEXT_PUBLIC_URL=
export ICON="/icon.ico"
export LOGO=/logo.png

kill $(lsof -ti:"$_PORT")
npx serve $MDX -p $_PORT --no-port-switching --no-clipboard &
npm run dev &

wait
)
```

Then go to: http://localhost:3000

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

# build

```sh
$ (
trap 'kill -9 0' SIGINT

rm -rf out

export _PORT=60141

# [Config](https://github.com/pmndrs/docs#configuration)
export MDX=~/code/pmndrs/react-three-fiber/docs
export NEXT_PUBLIC_LIBNAME="React Three Fiber"
export BASE_PATH=
export DIST_DIR=
export OUTPUT=export
export HOME_REDIRECT=/getting-started/introduction
export MDX_BASEURL=http://localhost:$_PORT
export EDIT_BASEURL=
export NEXT_PUBLIC_URL=
export ICON=πŸ‡¨πŸ‡­
export LOGO=/logo.png

npm run build

kill $(lsof -ti:"$_PORT")
npx serve $MDX -p $_PORT --no-port-switching --no-clipboard &
npx serve out &

wait
)
```

http://localhost:3000

# Docker

```sh
$ docker build -t pmndrs-docs .
```

```sh
$ cd ~/code/pmndrs/react-three-fiber
$ (
trap 'kill -9 0' SIGINT

export _PORT=60141

# [Config](https://github.com/pmndrs/docs#configuration)
export MDX=./docs
export NEXT_PUBLIC_LIBNAME="React Three Fiber"
export BASE_PATH=
export OUTPUT=export
export HOME_REDIRECT=/getting-started/introduction
export MDX_BASEURL=http://localhost:$_PORT
export EDIT_BASEURL=
export NEXT_PUBLIC_URL=
export ICON=πŸ‡¨πŸ‡­
export LOGO=/logo.png

rm -rf "$MDX/out"

docker run --rm --init -it \
-v "$MDX":/app/docs \
-e MDX \
-e NEXT_PUBLIC_LIBNAME \
-e BASE_PATH \
-e DIST_DIR="$MDX/out$BASE_PATH" \
-e OUTPUT \
-e HOME_REDIRECT \
-e MDX_BASEURL \
-e EDIT_BASEURL \
-e NEXT_PUBLIC_URL \
-e ICON \
-e LOGO \
pmndrs-docs npm run build

kill $(lsof -ti:"$_PORT")
npx serve $MDX -p $_PORT --no-port-switching --no-clipboard &
npx -y serve "$MDX/out" &

wait
)
```

Then go to: http://localhost:3000

# Reusable GitHub Actions workflow

`pmndrs/docs` provides a [`build.yml`](.github/workflows/build.yml) reusable workflow, any project can use:

```yml
uses: pmndrs/docs/.github/workflows/build.yml@main
with:
mdx: './docs'
libname: 'React Three Fiber'
home_redirect: '/getting-started/introduction'
icon: 'πŸ‡¨πŸ‡­'
logo: '/logo.png'
```

See [`pmndrs/react-three-fiber/.github/workflows/docs.yml`](https://github.com/pmndrs/react-three-fiber/blob/master/.github/workflows/docs.yml) for an example implementation.

# Authoring

In your `MDX` folder, create any `path/to/my-document.mdx`:

```mdx
---
title: My Document
description: Lorem ipsum...
image: dog.png
nav: 0
---

MARKDOWN
```

## Frontmatter

Any key is optional.

- `title`: if not provided, last part of the path is used: `my document`
- `image`:
- relative (to the md file) or absolute path, eg: `dog.png`, `./dog.png`, `../../dog.png`, `/dog.png` or `https://animals.com/dog.png`
- will be used as metadata image if provided
- `nav`: order in the navigation (on the same level)

## MARKDOWN

TODO
Loading