mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-13 06:09:21 +00:00
Compare commits
200 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bd5d7a979a | |||
| 6859f7d239 | |||
| dfa8a37be1 | |||
| 11a6511b7a | |||
| af98402655 | |||
| b7a0db3339 | |||
| 382a19885b | |||
| d99da6a3ae | |||
| 72cd0e59e6 | |||
| 42d88da73c | |||
| 2863fe0dc1 | |||
| 87218062be | |||
| 8a3910e208 | |||
| 6294bbb53c | |||
| a28a997851 | |||
| 28a9ee701e | |||
| 50e8b2ec52 | |||
| 315717fa2d | |||
| da67711c90 | |||
| fecdbe8dde | |||
| 9316ccd1f4 | |||
| c3b620e975 | |||
| 7a00880e5b | |||
| b6b597564d | |||
| d410381957 | |||
| 902c3c6c1a | |||
| 4fb2a4a6d7 | |||
| 2d64c78787 | |||
| fbfcca5dae | |||
| 664ae8bff6 | |||
| fa3d2aae08 | |||
| e7a591d9f6 | |||
| 2860beacdc | |||
| 231167d3e1 | |||
| c0ee60ec13 | |||
| f58b904ba6 | |||
| d5992f1a5c | |||
| fa12f9eeb6 | |||
| 33726c88a0 | |||
| 6aa3ff9c5e | |||
| 7d3fe23195 | |||
| 521052d84f | |||
| c730845e17 | |||
| 7b5a3616c4 | |||
| c9373efdb5 | |||
| 015615de8a | |||
| 0f867e533a | |||
| 7d5a6d2255 | |||
| a1da4f023d | |||
| 666e8426e1 | |||
| df2fa42bda | |||
| b3a7ad6d2c | |||
| 2932077bf9 | |||
| 957afd967f | |||
| 4c9a9d0416 | |||
| 40df91a363 | |||
| af66ff71ed | |||
| 6f8ecd6111 | |||
| fa3eb07617 | |||
| dc4268db64 | |||
| a0c06a72cc | |||
| 19c20c0be3 | |||
| fae34e56ac | |||
| ba0094a862 | |||
| b259009c9c | |||
| d88dd5ed8a | |||
| 57bb146075 | |||
| 4b67fe5317 | |||
| 938125e772 | |||
| 1c8d9febb3 | |||
| 223edae17d | |||
| 12a455dab5 | |||
| d00dc8ca72 | |||
| 2c85a302fc | |||
| 3460b78b45 | |||
| 95a1f652f9 | |||
| cc37e2ae15 | |||
| 08382ce62f | |||
| 80cb52a237 | |||
| c6637b09e2 | |||
| 778624af00 | |||
| e15757d01f | |||
| aed79fd6c3 | |||
| 0c973a3292 | |||
| 56c923c0ed | |||
| 7d7806df30 | |||
| cb5598dc19 | |||
| 47f01edcb8 | |||
| e6ddc0f07f | |||
| 373f18f451 | |||
| 3f292065cd | |||
| 5e975ab95b | |||
| a3ec264764 | |||
| 5d504ffa4c | |||
| 04999662db | |||
| f7a34706c7 | |||
| f328a41982 | |||
| 20ebecb114 | |||
| 5a69692f54 | |||
| 42ca7e1580 | |||
| c4ebb3fecd | |||
| 2a805cc082 | |||
| 89a5816ee4 | |||
| c3f6b8c003 | |||
| 0e201d5899 | |||
| ae5f1abc58 | |||
| 580101d04e | |||
| 81b4a4db53 | |||
| 8339e91e2b | |||
| 3119066728 | |||
| 326e28e9b0 | |||
| 90f0127ada | |||
| 0353a8186c | |||
| dd043df00f | |||
| 97b7c79bc6 | |||
| 634e0b4302 | |||
| 2a23f1f003 | |||
| 88ffdcc303 | |||
| b6b09d42af | |||
| ebc39e9db9 | |||
| 0df3849ea2 | |||
| 8ed1bda2f2 | |||
| d67699a1f1 | |||
| 3363a18856 | |||
| ad1dc0b914 | |||
| e4c7307c99 | |||
| f9c942c8ff | |||
| eeb977fc03 | |||
| 4b8a62122a | |||
| e44e947fc1 | |||
| 7588cfe1c5 | |||
| a9a643f222 | |||
| 77d6cb75be | |||
| 1942d221df | |||
| 041601ed65 | |||
| 5567281a85 | |||
| 4c3753046b | |||
| 89f8e16184 | |||
| a3e1125ced | |||
| 4dae8acfed | |||
| bc081c4344 | |||
| e4275b235d | |||
| 77397cac82 | |||
| b6a08bc679 | |||
| 116575c811 | |||
| 4ba7bd5ce1 | |||
| 223ab5377f | |||
| ae43ca146c | |||
| 42342893d6 | |||
| eedefdd5c9 | |||
| f5e152dd74 | |||
| 95ea22d9c5 | |||
| f23023ddfa | |||
| da74077954 | |||
| 29aaba5949 | |||
| daf41fc728 | |||
| b08eb1af59 | |||
| 8322cd3e35 | |||
| 444039c142 | |||
| 3b0eff7f71 | |||
| c765463e38 | |||
| e8ca25b67e | |||
| 528eee3fc6 | |||
| 168a4fa998 | |||
| 3ea75adba4 | |||
| cbd768a095 | |||
| 2d01653a78 | |||
| aa3357a57d | |||
| de53946896 | |||
| d51204148e | |||
| 319761a39e | |||
| 7fbf01a348 | |||
| c22490bd80 | |||
| 860fd6d02e | |||
| c43c524804 | |||
| 66bb938d85 | |||
| 0e6d928496 | |||
| f07982d9f8 | |||
| b92ecfad58 | |||
| 416bde70bc | |||
| 580f7ade15 | |||
| cdffd7c47b | |||
| 5a959cf041 | |||
| 31466546a2 | |||
| 90ead98eaa | |||
| 65e9cb9d5c | |||
| e59076a074 | |||
| 653920dec9 | |||
| 23cedd2d8b | |||
| 70c4182fd8 | |||
| b62b101065 | |||
| b9c929beeb | |||
| 2b6c593289 | |||
| c0b339e406 | |||
| da485f5144 | |||
| 139a8050a5 | |||
| da7b369ffd | |||
| 432da64919 | |||
| 7d0b422200 | |||
| fb90eb0acc |
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix UX issue about highlighting the search term in search result sections
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
---
|
||||||
|
"gitbook": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix three small visual issues
|
||||||
|
|
||||||
|
- Fix sidebar showing on `no-toc` pages in the gradient theme
|
||||||
|
- Fix variant selector truncating incorrectly in header when sections are present
|
||||||
|
- Fix page cover alignment on `lg` screens without TOC
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Respect fullWidth and defaultWidth for images
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook-v2": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Add docs.testgitbook.com to ADAPTIVE_CONTENT_HOSTS list
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix nested a tag causing hydration error
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix href being empty in TOC
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix navigation between sections/variants when previewing a site in v2
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Add support for inline icons.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Add circular corners and depth styling
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix crash when integration script fails to render block.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'@gitbook/react-openapi': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Add authorization header for OAuth2
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
'@gitbook/react-openapi': patch
|
||||||
|
'gitbook': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Improve support for OAuth2 security type
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"gitbook-v2": patch
|
||||||
|
"gitbook": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Adds Columns layout block to GBO
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Support dark-mode specific page cover image
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'gitbook': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Update Models page styling
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook-v2": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Optimize performances by using a smarter per-request cache arround data cached functions
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook-v2": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
add a force-revalidate api route to force bust the cache in case of errors
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix rendering of ogimage with SVG logos.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Best effort at preserving current variant when navigating between sections by matching the pathname against site spaces in the new section.
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"gitbook-v2": patch
|
||||||
|
"gitbook": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
encode customization header
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Rework full-width layout, add support for full-width page option
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook-v2": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix ISR on preview env
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"gitbook-v2": patch
|
||||||
|
"gitbook": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix concurrent execution in Vercel causing pages to not be attached to the proper tags.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@gitbook/react-contentkit": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Add basic error handling when transitioning between states.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook-v2": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Generate a llms-full.txt version of the docs site
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@gitbook/fonts": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Initial version of the package
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix rendering of ogimage when logo or icon are AVIF images.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Add margin to adjacent buttons
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook-v2": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Don't cache unexpected API errors for more than a few minutes.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook-v2": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
add a global error boundary
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'@gitbook/react-openapi': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Indent JSON python code sample
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix missing title on button to close the announcement banner.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Make icons for page groups more contrasting
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Ignore case while highlighting search results.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Make TOC height dynamic based on visible header and footer elements
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix bold header links hover color
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"gitbook": patch
|
||||||
|
"gitbook-v2": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
cache fonts and static image used in OGImage in memory
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix border being added to cards
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'@gitbook/react-openapi': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Handle nested deprecated properties in generateSchemaExample
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook-v2": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Add `urlObject.hash` to `linker.toLinkForContent` to pass through URL fragment identifiers, used in search
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook-v2": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
apply customization for dynamic context
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Reverse order of feedback smileys
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'@gitbook/react-openapi': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Deduplicate path parameters from OpenAPI spec
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix ogimage using incorrect Google Font depending on language.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"gitbook-v2": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
remove trailing slash from linker
|
||||||
+33
-5
@@ -53,19 +53,47 @@ After forking this repository, you'll want to [create a branch](https://docs.git
|
|||||||
|
|
||||||
#### 3. Install dependencies and run the project locally
|
#### 3. Install dependencies and run the project locally
|
||||||
|
|
||||||
GitBook uses [Bun](https://bun.sh/) to run the project. Make sure you're using the specified version of `node` before running any of the development commands to ensure a smooth development experience.
|
##### Prerequisites:
|
||||||
|
- Node.js (Version: >=20.6)
|
||||||
|
- Use `nvm` for easy Node management
|
||||||
|
- [Bun](https://bun.sh/) (Version: >=1.2.15)
|
||||||
|
- We use a text-based lockfile which isn't supported below 1.2.15
|
||||||
|
|
||||||
You can easily do this by running the command `nvm use`.
|
##### Setup steps:
|
||||||
|
|
||||||
To start your local version of GitBook, run the command `bun dev`.
|
1. Ensure you are using the project's version of Node:
|
||||||
|
```bash
|
||||||
|
nvm use
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Install dependencies using Bun:
|
||||||
|
```bash
|
||||||
|
bun install
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Build the project:
|
||||||
|
```bash
|
||||||
|
bun build:v2
|
||||||
|
```
|
||||||
|
|
||||||
|
4. Start the development server:
|
||||||
|
```bash
|
||||||
|
bun dev:v2
|
||||||
|
```
|
||||||
|
|
||||||
|
Additional development commands:
|
||||||
|
- `bun format`: Format the code using Biome
|
||||||
|
- `bun typecheck`: Run TypeScript type checking
|
||||||
|
- `bun unit`: Run unit tests
|
||||||
|
- `bun e2e`: Run end-to-end tests
|
||||||
|
|
||||||
#### 4. Preview your changes
|
#### 4. Preview your changes
|
||||||
|
|
||||||
When running the development server, published GitBook sites can be rendered through your local version at `http://localhost:3000/`.
|
When running the development server, published GitBook sites can be rendered through your local version at `http://localhost:3000/`.
|
||||||
|
|
||||||
For example, our published docs can be viewed using the local version by visiting `http://localhost:3000/docs.gitbook.com` after running the development server.
|
For example, our published docs can be viewed using the local version by visiting `http://localhost:3000/gitbook.com/docs` after running the development server.
|
||||||
|
|
||||||
You can visit any published GitBook site behind your development server. Please make sure your site is [published publicly](https://docs.gitbook.com/published-documentation/publish-your-content-as-a-docs-site) to ensure you can view the site correctly in your development version.
|
You can visit any published GitBook site behind your development server. Please make sure your site is [published publicly](https://gitbook.com/docs/published-documentation/publish-your-content-as-a-docs-site) to ensure you can view the site correctly in your development version.
|
||||||
|
|
||||||
### Commit your update
|
### Commit your update
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
name: Gradual Deploy to Cloudflare
|
||||||
|
description: Use gradual deployment to deploy to Cloudflare. This action will upload the middleware and server versions to Cloudflare and kept them bound together
|
||||||
|
inputs:
|
||||||
|
apiToken:
|
||||||
|
description: 'Cloudflare API token'
|
||||||
|
required: true
|
||||||
|
accountId:
|
||||||
|
description: 'Cloudflare account ID'
|
||||||
|
required: true
|
||||||
|
environment:
|
||||||
|
description: 'Cloudflare environment to deploy to (staging, production, preview)'
|
||||||
|
required: true
|
||||||
|
middlewareVersionId:
|
||||||
|
description: 'Middleware version ID to deploy'
|
||||||
|
required: true
|
||||||
|
serverVersionId:
|
||||||
|
description: 'Server version ID to deploy'
|
||||||
|
required: true
|
||||||
|
outputs:
|
||||||
|
deployment-url:
|
||||||
|
description: "Deployment URL"
|
||||||
|
value: ${{ steps.deploy_middleware.outputs.deployment-url }}
|
||||||
|
runs:
|
||||||
|
using: 'composite'
|
||||||
|
steps:
|
||||||
|
- id: wrangler_status
|
||||||
|
name: Check wrangler deployment status
|
||||||
|
uses: cloudflare/wrangler-action@v3.14.0
|
||||||
|
with:
|
||||||
|
apiToken: ${{ inputs.apiToken }}
|
||||||
|
accountId: ${{ inputs.accountId }}
|
||||||
|
workingDirectory: ./
|
||||||
|
wranglerVersion: '4.10.0'
|
||||||
|
environment: ${{ inputs.environment }}
|
||||||
|
command: deployments status --config ./packages/gitbook-v2/openNext/customWorkers/defaultWrangler.jsonc
|
||||||
|
|
||||||
|
# This step is used to get the version ID that is currently deployed to Cloudflare.
|
||||||
|
- id: extract_current_version
|
||||||
|
name: Extract current version
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
version_id=$(echo "${{ steps.wrangler_status.outputs.command-output }}" | grep -A 3 "(100%)" | grep -oP '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}')
|
||||||
|
echo "version_id=$version_id" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- id: deploy_server
|
||||||
|
name: Deploy server to Cloudflare at 0%
|
||||||
|
uses: cloudflare/wrangler-action@v3.14.0
|
||||||
|
with:
|
||||||
|
apiToken: ${{ inputs.apiToken }}
|
||||||
|
accountId: ${{ inputs.accountId }}
|
||||||
|
workingDirectory: ./
|
||||||
|
wranglerVersion: '4.10.0'
|
||||||
|
environment: ${{ inputs.environment }}
|
||||||
|
command: versions deploy ${{ steps.extract_current_version.outputs.version_id }}@100% ${{ inputs.serverVersionId }}@0% -y --config ./packages/gitbook-v2/openNext/customWorkers/defaultWrangler.jsonc
|
||||||
|
|
||||||
|
# Since we use version overrides headers, we can directly deploy the middleware to 100%.
|
||||||
|
- id: deploy_middleware
|
||||||
|
name: Deploy middleware to Cloudflare at 100%
|
||||||
|
uses: cloudflare/wrangler-action@v3.14.0
|
||||||
|
with:
|
||||||
|
apiToken: ${{ inputs.apiToken }}
|
||||||
|
accountId: ${{ inputs.accountId }}
|
||||||
|
workingDirectory: ./
|
||||||
|
wranglerVersion: '4.10.0'
|
||||||
|
environment: ${{ inputs.environment }}
|
||||||
|
command: versions deploy ${{ inputs.middlewareVersionId }}@100% -y --config ./packages/gitbook-v2/openNext/customWorkers/middlewareWrangler.jsonc
|
||||||
|
|
||||||
|
- name: Deploy server to Cloudflare at 100%
|
||||||
|
uses: cloudflare/wrangler-action@v3.14.0
|
||||||
|
with:
|
||||||
|
apiToken: ${{ inputs.apiToken }}
|
||||||
|
accountId: ${{ inputs.accountId }}
|
||||||
|
workingDirectory: ./
|
||||||
|
wranglerVersion: '4.10.0'
|
||||||
|
environment: ${{ inputs.environment }}
|
||||||
|
command: versions deploy ${{ inputs.serverVersionId }}@100% -y --config ./packages/gitbook-v2/openNext/customWorkers/defaultWrangler.jsonc
|
||||||
|
|
||||||
|
- name: Outputs
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
DEPLOYMENT_URL: ${{ steps.deploy_middleware.outputs.deployment-url }}
|
||||||
|
run: |
|
||||||
|
echo "URL: ${{ steps.deploy_middleware.outputs.deployment-url }}"
|
||||||
@@ -19,10 +19,16 @@ inputs:
|
|||||||
deploy:
|
deploy:
|
||||||
description: 'Deploy as main version for all traffic instead of uploading versions'
|
description: 'Deploy as main version for all traffic instead of uploading versions'
|
||||||
required: true
|
required: true
|
||||||
|
commitTag:
|
||||||
|
description: 'Commit branch to associate with the deployment'
|
||||||
|
required: true
|
||||||
|
commitMessage:
|
||||||
|
description: 'Commit message to associate with the deployment'
|
||||||
|
required: true
|
||||||
outputs:
|
outputs:
|
||||||
deployment-url:
|
deployment-url:
|
||||||
description: "Deployment URL"
|
description: "Deployment URL"
|
||||||
value: ${{ steps.deploy.outputs.deployment-url }}
|
value: ${{ steps.upload_middleware.outputs.deployment-url }}
|
||||||
runs:
|
runs:
|
||||||
using: 'composite'
|
using: 'composite'
|
||||||
steps:
|
steps:
|
||||||
@@ -49,24 +55,84 @@ runs:
|
|||||||
GITBOOK_INTEGRATIONS_HOST: ${{ inputs.opItem }}/GITBOOK_INTEGRATIONS_HOST
|
GITBOOK_INTEGRATIONS_HOST: ${{ inputs.opItem }}/GITBOOK_INTEGRATIONS_HOST
|
||||||
GITBOOK_IMAGE_RESIZE_SIGNING_KEY: ${{ inputs.opItem }}/GITBOOK_IMAGE_RESIZE_SIGNING_KEY
|
GITBOOK_IMAGE_RESIZE_SIGNING_KEY: ${{ inputs.opItem }}/GITBOOK_IMAGE_RESIZE_SIGNING_KEY
|
||||||
GITBOOK_IMAGE_RESIZE_URL: ${{ inputs.opItem }}/GITBOOK_IMAGE_RESIZE_URL
|
GITBOOK_IMAGE_RESIZE_URL: ${{ inputs.opItem }}/GITBOOK_IMAGE_RESIZE_URL
|
||||||
|
GITBOOK_IMAGE_RESIZE_MODE: ${{ inputs.opItem }}/GITBOOK_IMAGE_RESIZE_MODE
|
||||||
GITBOOK_ASSETS_PREFIX: ${{ inputs.opItem }}/GITBOOK_ASSETS_PREFIX
|
GITBOOK_ASSETS_PREFIX: ${{ inputs.opItem }}/GITBOOK_ASSETS_PREFIX
|
||||||
GITBOOK_FONTS_URL: ${{ inputs.opItem }}/GITBOOK_FONTS_URL
|
GITBOOK_FONTS_URL: ${{ inputs.opItem }}/GITBOOK_FONTS_URL
|
||||||
- name: Build worker
|
- name: Build worker
|
||||||
run: bun run turbo build:v2:cloudflare
|
run: bun run turbo build:v2:cloudflare
|
||||||
|
env:
|
||||||
|
GITBOOK_RUNTIME: cloudflare
|
||||||
shell: bash
|
shell: bash
|
||||||
- id: deploy
|
|
||||||
name: Deploy to Cloudflare
|
- name: Upload the DO worker
|
||||||
uses: cloudflare/wrangler-action@v3.14.0
|
uses: cloudflare/wrangler-action@v3.14.0
|
||||||
with:
|
with:
|
||||||
apiToken: ${{ inputs.apiToken }}
|
apiToken: ${{ inputs.apiToken }}
|
||||||
accountId: ${{ inputs.accountId }}
|
accountId: ${{ inputs.accountId }}
|
||||||
workingDirectory: ./
|
workingDirectory: ./
|
||||||
wranglerVersion: '3.112.0'
|
wranglerVersion: '4.10.0'
|
||||||
environment: ${{ inputs.environment }}
|
environment: ${{ inputs.environment }}
|
||||||
command: ${{ fromJSON(inputs.deploy) == true && 'deploy' || 'versions upload' }} --config ./packages/gitbook-v2/wrangler.toml
|
command: deploy --config ./packages/gitbook-v2/openNext/customWorkers/doWrangler.jsonc
|
||||||
|
|
||||||
|
- id: upload_server
|
||||||
|
name: Upload server to Cloudflare
|
||||||
|
uses: cloudflare/wrangler-action@v3.14.0
|
||||||
|
with:
|
||||||
|
apiToken: ${{ inputs.apiToken }}
|
||||||
|
accountId: ${{ inputs.accountId }}
|
||||||
|
workingDirectory: ./
|
||||||
|
wranglerVersion: '4.10.0'
|
||||||
|
environment: ${{ inputs.environment }}
|
||||||
|
command: ${{ format('versions upload --tag {0} --message "{1}"', inputs.commitTag, inputs.commitMessage) }} --config ./packages/gitbook-v2/openNext/customWorkers/defaultWrangler.jsonc
|
||||||
|
|
||||||
|
- name: Extract server version worker ID
|
||||||
|
shell: bash
|
||||||
|
id: extract_server_version_id
|
||||||
|
run: |
|
||||||
|
version_id=$(echo '${{ steps.upload_server.outputs.command-output }}' | grep "Worker Version ID" | awk '{print $4}')
|
||||||
|
echo "version_id=$version_id" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Run updateWrangler scripts
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
bun run ./packages/gitbook-v2/openNext/customWorkers/script/updateWrangler.ts ${{ steps.extract_server_version_id.outputs.version_id }}
|
||||||
|
|
||||||
|
- id: upload_middleware
|
||||||
|
name: Upload middleware to Cloudflare
|
||||||
|
uses: cloudflare/wrangler-action@v3.14.0
|
||||||
|
with:
|
||||||
|
apiToken: ${{ inputs.apiToken }}
|
||||||
|
accountId: ${{ inputs.accountId }}
|
||||||
|
workingDirectory: ./
|
||||||
|
wranglerVersion: '4.10.0'
|
||||||
|
environment: ${{ inputs.environment }}
|
||||||
|
command: ${{ format('versions upload --tag {0} --message "{1}"', inputs.commitTag, inputs.commitMessage) }} --config ./packages/gitbook-v2/openNext/customWorkers/middlewareWrangler.jsonc
|
||||||
|
|
||||||
|
- name: Extract middleware version worker ID
|
||||||
|
shell: bash
|
||||||
|
id: extract_middleware_version_id
|
||||||
|
run: |
|
||||||
|
version_id=$(echo '${{ steps.upload_middleware.outputs.command-output }}' | grep "Worker Version ID" | awk '{print $4}')
|
||||||
|
echo "version_id=$version_id" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Deploy server and middleware to Cloudflare
|
||||||
|
if: ${{ inputs.deploy == 'true' }}
|
||||||
|
uses: ./.github/actions/gradual-deploy-cloudflare
|
||||||
|
with:
|
||||||
|
apiToken: ${{ inputs.apiToken }}
|
||||||
|
accountId: ${{ inputs.accountId }}
|
||||||
|
opServiceAccount: ${{ inputs.opServiceAccount }}
|
||||||
|
opItem: ${{ inputs.opItem }}
|
||||||
|
environment: ${{ inputs.environment }}
|
||||||
|
serverVersionId: ${{ steps.extract_server_version_id.outputs.version_id }}
|
||||||
|
middlewareVersionId: ${{ steps.extract_middleware_version_id.outputs.version_id }}
|
||||||
|
deploy: ${{ inputs.deploy }}
|
||||||
|
|
||||||
|
|
||||||
- name: Outputs
|
- name: Outputs
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
env:
|
||||||
DEPLOYMENT_URL: ${{ steps.deploy.outputs.deployment-url }}
|
DEPLOYMENT_URL: ${{ steps.upload_middleware.outputs.deployment-url }}
|
||||||
run: |
|
run: |
|
||||||
echo "URL: ${{ steps.deploy.outputs.deployment-url }}"
|
echo "URL: ${{ steps.upload_middleware.outputs.deployment-url }}"
|
||||||
|
echo "Output server: ${{ steps.upload_server.outputs.command-output }}"
|
||||||
@@ -54,6 +54,7 @@ runs:
|
|||||||
GITBOOK_INTEGRATIONS_HOST: ${{ inputs.opItem }}/GITBOOK_INTEGRATIONS_HOST
|
GITBOOK_INTEGRATIONS_HOST: ${{ inputs.opItem }}/GITBOOK_INTEGRATIONS_HOST
|
||||||
GITBOOK_IMAGE_RESIZE_SIGNING_KEY: ${{ inputs.opItem }}/GITBOOK_IMAGE_RESIZE_SIGNING_KEY
|
GITBOOK_IMAGE_RESIZE_SIGNING_KEY: ${{ inputs.opItem }}/GITBOOK_IMAGE_RESIZE_SIGNING_KEY
|
||||||
GITBOOK_IMAGE_RESIZE_URL: ${{ inputs.opItem }}/GITBOOK_IMAGE_RESIZE_URL
|
GITBOOK_IMAGE_RESIZE_URL: ${{ inputs.opItem }}/GITBOOK_IMAGE_RESIZE_URL
|
||||||
|
GITBOOK_IMAGE_RESIZE_MODE: ${{ inputs.opItem }}/GITBOOK_IMAGE_RESIZE_MODE
|
||||||
GITBOOK_ASSETS_PREFIX: ${{ inputs.opItem }}/GITBOOK_ASSETS_PREFIX
|
GITBOOK_ASSETS_PREFIX: ${{ inputs.opItem }}/GITBOOK_ASSETS_PREFIX
|
||||||
GITBOOK_FONTS_URL: ${{ inputs.opItem }}/GITBOOK_FONTS_URL
|
GITBOOK_FONTS_URL: ${{ inputs.opItem }}/GITBOOK_FONTS_URL
|
||||||
- name: Build Project Artifacts
|
- name: Build Project Artifacts
|
||||||
@@ -62,6 +63,7 @@ runs:
|
|||||||
env:
|
env:
|
||||||
VERCEL_ORG_ID: ${{ inputs.vercelOrg }}
|
VERCEL_ORG_ID: ${{ inputs.vercelOrg }}
|
||||||
VERCEL_PROJECT_ID: ${{ inputs.vercelProject }}
|
VERCEL_PROJECT_ID: ${{ inputs.vercelProject }}
|
||||||
|
GITBOOK_RUNTIME: vercel
|
||||||
- name: Deploy Project Artifacts to Vercel
|
- name: Deploy Project Artifacts to Vercel
|
||||||
id: deploy
|
id: deploy
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ jobs:
|
|||||||
deploy-v1-cloudflare:
|
deploy-v1-cloudflare:
|
||||||
name: Deploy v1 to Cloudflare Pages
|
name: Deploy v1 to Cloudflare Pages
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
environment:
|
environment:
|
||||||
name: ${{ github.ref == 'refs/heads/main' && '1c-production' || '1c-preview' }}
|
name: ${{ github.ref == 'refs/heads/main' && '1c-production' || '1c-preview' }}
|
||||||
url: ${{ steps.deploy.outputs.deployment-url }}
|
url: ${{ steps.deploy.outputs.deployment-url }}
|
||||||
permissions:
|
permissions:
|
||||||
@@ -40,6 +40,7 @@ jobs:
|
|||||||
run: bun run turbo gitbook#build:cloudflare
|
run: bun run turbo gitbook#build:cloudflare
|
||||||
env:
|
env:
|
||||||
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: ${{ secrets.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY }}
|
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: ${{ secrets.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY }}
|
||||||
|
GITBOOK_RUNTIME: cloudflare
|
||||||
- id: deploy
|
- id: deploy
|
||||||
name: Deploy to Cloudflare
|
name: Deploy to Cloudflare
|
||||||
uses: cloudflare/wrangler-action@v3.14.0
|
uses: cloudflare/wrangler-action@v3.14.0
|
||||||
@@ -56,7 +57,7 @@ jobs:
|
|||||||
deploy-v2-vercel:
|
deploy-v2-vercel:
|
||||||
name: Deploy v2 to Vercel (preview)
|
name: Deploy v2 to Vercel (preview)
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
environment:
|
environment:
|
||||||
name: 2v-preview
|
name: 2v-preview
|
||||||
url: ${{ steps.deploy.outputs.deployment-url }}
|
url: ${{ steps.deploy.outputs.deployment-url }}
|
||||||
outputs:
|
outputs:
|
||||||
@@ -77,11 +78,11 @@ jobs:
|
|||||||
deploy-v2-cloudflare:
|
deploy-v2-cloudflare:
|
||||||
name: Deploy v2 to Cloudflare Worker (preview)
|
name: Deploy v2 to Cloudflare Worker (preview)
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
environment:
|
environment:
|
||||||
name: 2c-preview
|
name: 2c-preview
|
||||||
url: ${{ steps.deploy.outputs.deployment-url }}
|
url: ${{ steps.deploy.outputs.deployment-url }}
|
||||||
outputs:
|
outputs:
|
||||||
deployment-url: ${{ steps.deploy.outputs.deployment-url }}
|
deployment-url: ${{ steps.deploy.outputs.deployment-url || steps.extract-worker-id.outputs.worker-url }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -95,9 +96,19 @@ jobs:
|
|||||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
opItem: op://gitbook-open/2c-preview
|
opItem: op://gitbook-open/2c-preview
|
||||||
opServiceAccount: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
|
opServiceAccount: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
|
||||||
|
commitTag: ${{ github.ref == 'refs/heads/main' && 'main' || format('pr{0}', github.event.pull_request.number) }}
|
||||||
|
commitMessage: ${{ github.sha }}
|
||||||
|
- name: Extract Worker ID
|
||||||
|
id: extract-worker-id
|
||||||
|
if: ${{ !steps.deploy.outputs.deployment-url }}
|
||||||
|
run: |
|
||||||
|
if [[ "${{ steps.deploy.outputs.command-output }}" =~ Worker\ Version\ ID:\ ([0-9a-f]{8})-([0-9a-f-]+) ]]; then
|
||||||
|
WORKER_ID_FIRST_PART="${BASH_REMATCH[1]}"
|
||||||
|
echo "worker-url=https://${WORKER_ID_FIRST_PART}-gitbook-open-v2-preview.gitbook.workers.dev/" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
- name: Outputs
|
- name: Outputs
|
||||||
run: |
|
run: |
|
||||||
echo "URL: ${{ steps.deploy.outputs.deployment-url }}"
|
echo "URL: ${{ steps.deploy.outputs.deployment-url || steps.extract-worker-id.outputs.worker-url }}"
|
||||||
comment-deployments:
|
comment-deployments:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
name: Comment Deployments (preview)
|
name: Comment Deployments (preview)
|
||||||
@@ -123,14 +134,14 @@ jobs:
|
|||||||
body: |
|
body: |
|
||||||
Summary of the deployments:
|
Summary of the deployments:
|
||||||
|
|
||||||
### Version 1 (production)
|
### Version 1
|
||||||
|
|
||||||
| Version | URL | Status |
|
| Version | URL | Status |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| Latest commit | [${{ needs.deploy-v1-cloudflare.outputs.deployment-url }}](${{ needs.deploy-v1-cloudflare.outputs.deployment-url }}) | ${{ needs.deploy-v1-cloudflare.result == 'success' && '✅' || '❌' }} |
|
| Latest commit | [${{ needs.deploy-v1-cloudflare.outputs.deployment-url }}](${{ needs.deploy-v1-cloudflare.outputs.deployment-url }}) | ${{ needs.deploy-v1-cloudflare.result == 'success' && '✅' || '❌' }} |
|
||||||
| PR | [${{ needs.deploy-v1-cloudflare.outputs.deployment-alias-url }}](${{ needs.deploy-v1-cloudflare.outputs.deployment-alias-url }}) | ${{ needs.deploy-v1-cloudflare.result == 'success' && '✅' || '❌' }} |
|
| PR | [${{ needs.deploy-v1-cloudflare.outputs.deployment-alias-url }}](${{ needs.deploy-v1-cloudflare.outputs.deployment-alias-url }}) | ${{ needs.deploy-v1-cloudflare.result == 'success' && '✅' || '❌' }} |
|
||||||
|
|
||||||
### Version 2 (experimental)
|
### Version 2
|
||||||
|
|
||||||
| Version | URL | Status |
|
| Version | URL | Status |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
@@ -139,16 +150,16 @@ jobs:
|
|||||||
|
|
||||||
### Test content
|
### Test content
|
||||||
|
|
||||||
| Site | v1 | v2 |
|
| Site | `v1` | `2v` | `2c` |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
| GitBook | [${{ needs.deploy-v1-cloudflare.outputs.deployment-url }}/docs.gitbook.com](${{ needs.deploy-v1-cloudflare.outputs.deployment-url }}/docs.gitbook.com) | [${{ needs.deploy-v2-vercel.outputs.deployment-url }}/url/docs.gitbook.com](${{ needs.deploy-v2-vercel.outputs.deployment-url }}/url/docs.gitbook.com) |
|
| GitBook | [${{ needs.deploy-v1-cloudflare.outputs.deployment-url }}/gitbook.com/docs](${{ needs.deploy-v1-cloudflare.outputs.deployment-url }}/gitbook.com/docs) | [${{ needs.deploy-v2-vercel.outputs.deployment-url }}/url/gitbook.com/docs](${{ needs.deploy-v2-vercel.outputs.deployment-url }}/url/gitbook.com/docs) | [${{ needs.deploy-v2-cloudflare.outputs.deployment-url }}/url/gitbook.com/docs](${{ needs.deploy-v2-cloudflare.outputs.deployment-url }}/url/gitbook.com/docs) |
|
||||||
| E2E | [${{ needs.deploy-v1-cloudflare.outputs.deployment-url }}/gitbook.gitbook.io/test-gitbook-open](${{ needs.deploy-v1-cloudflare.outputs.deployment-url }}/gitbook.gitbook.io/test-gitbook-open) | [${{ needs.deploy-v2-vercel.outputs.deployment-url }}/url/gitbook.gitbook.io/test-gitbook-open](${{ needs.deploy-v2-vercel.outputs.deployment-url }}/url/gitbook.gitbook.io/test-gitbook-open) |
|
| E2E | [${{ needs.deploy-v1-cloudflare.outputs.deployment-url }}/gitbook.gitbook.io/test-gitbook-open](${{ needs.deploy-v1-cloudflare.outputs.deployment-url }}/gitbook.gitbook.io/test-gitbook-open) | [${{ needs.deploy-v2-vercel.outputs.deployment-url }}/url/gitbook.gitbook.io/test-gitbook-open](${{ needs.deploy-v2-vercel.outputs.deployment-url }}/url/gitbook.gitbook.io/test-gitbook-open) | [${{ needs.deploy-v2-cloudflare.outputs.deployment-url }}/url/gitbook.gitbook.io/test-gitbook-open](${{ needs.deploy-v2-cloudflare.outputs.deployment-url }}/url/gitbook.gitbook.io/test-gitbook-open) |
|
||||||
edit-mode: replace
|
edit-mode: replace
|
||||||
visual-testing-v1:
|
visual-testing-v1:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
name: Visual Testing v1
|
name: Visual Testing v1
|
||||||
needs: deploy-v1-cloudflare
|
needs: deploy-v1-cloudflare
|
||||||
timeout-minutes: 8
|
timeout-minutes: 10
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -184,11 +195,32 @@ jobs:
|
|||||||
SITE_BASE_URL: ${{ needs.deploy-v2-vercel.outputs.deployment-url }}/url/
|
SITE_BASE_URL: ${{ needs.deploy-v2-vercel.outputs.deployment-url }}/url/
|
||||||
ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }}
|
ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }}
|
||||||
ARGOS_BUILD_NAME: 'v2-vercel'
|
ARGOS_BUILD_NAME: 'v2-vercel'
|
||||||
|
visual-testing-v2-cloudflare:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
name: Visual Testing v2 (Cloudflare)
|
||||||
|
needs: deploy-v2-cloudflare
|
||||||
|
timeout-minutes: 10
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Setup Bun
|
||||||
|
uses: ./.github/composite/setup-bun
|
||||||
|
- name: Install dependencies
|
||||||
|
run: bun install --frozen-lockfile
|
||||||
|
- name: Setup Playwright
|
||||||
|
uses: ./.github/actions/setup-playwright
|
||||||
|
- name: Run Playwright tests
|
||||||
|
run: bun e2e
|
||||||
|
env:
|
||||||
|
BASE_URL: ${{ needs.deploy-v2-cloudflare.outputs.deployment-url }}
|
||||||
|
SITE_BASE_URL: ${{ needs.deploy-v2-cloudflare.outputs.deployment-url }}/url/
|
||||||
|
ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }}
|
||||||
|
ARGOS_BUILD_NAME: 'v2-cloudflare'
|
||||||
visual-testing-customers-v1:
|
visual-testing-customers-v1:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
name: Visual Testing Customers v1
|
name: Visual Testing Customers v1
|
||||||
needs: deploy-v1-cloudflare
|
needs: deploy-v1-cloudflare
|
||||||
timeout-minutes: 6
|
timeout-minutes: 10
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -208,7 +240,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
name: Visual Testing Customers v2
|
name: Visual Testing Customers v2
|
||||||
needs: deploy-v2-vercel
|
needs: deploy-v2-vercel
|
||||||
timeout-minutes: 6
|
timeout-minutes: 10
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -225,6 +257,27 @@ jobs:
|
|||||||
SITE_BASE_URL: ${{ needs.deploy-v2-vercel.outputs.deployment-url }}/url/
|
SITE_BASE_URL: ${{ needs.deploy-v2-vercel.outputs.deployment-url }}/url/
|
||||||
ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }}
|
ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }}
|
||||||
ARGOS_BUILD_NAME: 'customers-v2'
|
ARGOS_BUILD_NAME: 'customers-v2'
|
||||||
|
visual-testing-customers-v2-cloudflare:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
name: Visual Testing Customers v2 (Cloudflare)
|
||||||
|
needs: deploy-v2-cloudflare
|
||||||
|
timeout-minutes: 10
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Setup Bun
|
||||||
|
uses: ./.github/composite/setup-bun
|
||||||
|
- name: Install dependencies
|
||||||
|
run: bun install --frozen-lockfile
|
||||||
|
- name: Setup Playwright
|
||||||
|
uses: ./.github/actions/setup-playwright
|
||||||
|
- name: Run Playwright tests
|
||||||
|
run: bun e2e-customers
|
||||||
|
env:
|
||||||
|
BASE_URL: ${{ needs.deploy-v2-cloudflare.outputs.deployment-url }}
|
||||||
|
SITE_BASE_URL: ${{ needs.deploy-v2-cloudflare.outputs.deployment-url }}/url/
|
||||||
|
ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }}
|
||||||
|
ARGOS_BUILD_NAME: 'customers-v2'
|
||||||
pagespeed-testing-v1:
|
pagespeed-testing-v1:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
name: PageSpeed Testing v1
|
name: PageSpeed Testing v1
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: Deploy staging
|
- name: Deploy
|
||||||
id: deploy
|
id: deploy
|
||||||
uses: ./.github/composite/deploy-vercel
|
uses: ./.github/composite/deploy-vercel
|
||||||
with:
|
with:
|
||||||
@@ -48,6 +48,8 @@ jobs:
|
|||||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
opItem: op://gitbook-open/2c-production
|
opItem: op://gitbook-open/2c-production
|
||||||
opServiceAccount: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
|
opServiceAccount: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
|
||||||
|
commitTag: main
|
||||||
|
commitMessage: ${{ github.sha }}
|
||||||
- name: Outputs
|
- name: Outputs
|
||||||
run: |
|
run: |
|
||||||
echo "URL: ${{ steps.deploy.outputs.deployment-url }}"
|
echo "URL: ${{ steps.deploy.outputs.deployment-url }}"
|
||||||
@@ -17,7 +17,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: Deploy staging
|
- name: Deploy
|
||||||
id: deploy
|
id: deploy
|
||||||
uses: ./.github/composite/deploy-vercel
|
uses: ./.github/composite/deploy-vercel
|
||||||
with:
|
with:
|
||||||
@@ -48,6 +48,8 @@ jobs:
|
|||||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
opItem: op://gitbook-open/2c-staging
|
opItem: op://gitbook-open/2c-staging
|
||||||
opServiceAccount: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
|
opServiceAccount: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
|
||||||
|
commitTag: main
|
||||||
|
commitMessage: ${{ github.sha }}
|
||||||
- name: Outputs
|
- name: Outputs
|
||||||
run: |
|
run: |
|
||||||
echo "URL: ${{ steps.deploy.outputs.deployment-url }}"
|
echo "URL: ${{ steps.deploy.outputs.deployment-url }}"
|
||||||
Vendored
+1
@@ -9,6 +9,7 @@
|
|||||||
],
|
],
|
||||||
"tailwindCSS.classAttributes": ["class", "className", "style", ".*Style"],
|
"tailwindCSS.classAttributes": ["class", "className", "style", ".*Style"],
|
||||||
"prettier.enable": false,
|
"prettier.enable": false,
|
||||||
|
"editor.formatOnSave": true,
|
||||||
"editor.defaultFormatter": "biomejs.biome",
|
"editor.defaultFormatter": "biomejs.biome",
|
||||||
"editor.codeActionsOnSave": {
|
"editor.codeActionsOnSave": {
|
||||||
"source.organizeImports.biome": "explicit",
|
"source.organizeImports.biome": "explicit",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<h1 align="center">GitBook</h1>
|
<h1 align="center">GitBook</h1>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://docs.gitbook.com/">Docs</a> - <a href="https://github.com/GitbookIO/community">Community</a> - <a href="https://developer.gitbook.com/">Developer Docs</a> - <a href="https://changelog.gitbook.com/">Changelog</a> - <a href="https://github.com/GitbookIO/gitbook/issues/new?assignees=&labels=bug&template=bug_report.md">Bug reports</a>
|
<a href="https://gitbook.com/docs/">Docs</a> - <a href="https://github.com/GitbookIO/community">Community</a> - <a href="https://developer.gitbook.com/">Developer Docs</a> - <a href="https://changelog.gitbook.com/">Changelog</a> - <a href="https://github.com/GitbookIO/gitbook/issues/new?assignees=&labels=bug&template=bug_report.md">Bug reports</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
@@ -56,26 +56,27 @@ git clone https://github.com/gitbookIO/gitbook.git
|
|||||||
bun install
|
bun install
|
||||||
```
|
```
|
||||||
|
|
||||||
4. Start your local development server.
|
4. Run build.
|
||||||
|
|
||||||
```
|
```
|
||||||
bun dev
|
bun build:v2
|
||||||
```
|
```
|
||||||
|
|
||||||
5. Open a published GitBook space in your web browser, prefixing it with `http://localhost:3000/`.
|
5. Start your local development server.
|
||||||
|
|
||||||
|
```
|
||||||
|
bun dev:v2
|
||||||
|
```
|
||||||
|
|
||||||
|
6. Open a published GitBook space in your web browser, prefixing it with `http://localhost:3000/`.
|
||||||
|
|
||||||
examples:
|
examples:
|
||||||
|
|
||||||
- http://localhost:3000/docs.gitbook.com
|
- http://localhost:3000/url/gitbook.com/docs
|
||||||
- http://localhost:3000/open-source.gitbook.io/midjourney
|
- http://localhost:3000/url/open-source.gitbook.io/midjourney
|
||||||
|
|
||||||
Any published GitBook site can be accessed through your local development instance, and any updates you make to the codebase will be reflected in your browser.
|
Any published GitBook site can be accessed through your local development instance, and any updates you make to the codebase will be reflected in your browser.
|
||||||
|
|
||||||
### Other development commands
|
|
||||||
|
|
||||||
- `bun format`: format the code
|
|
||||||
- `bun lint`: lint the code
|
|
||||||
|
|
||||||
### CI and testing
|
### CI and testing
|
||||||
|
|
||||||
All pull-requests will be tested against both visual and performances testing to prevent regressions.
|
All pull-requests will be tested against both visual and performances testing to prevent regressions.
|
||||||
@@ -150,11 +151,11 @@ See `LICENSE` for more information.
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
```md
|
```md
|
||||||
[](https://gitbook.com/)
|
[](https://www.gitbook.com/preview?utm_source=gitbook_readme_badge&utm_medium=organic&utm_campaign=preview_documentation&utm_content=link)
|
||||||
```
|
```
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<a href="https://gitbook.com">
|
<a href="https://www.gitbook.com/preview?utm_source=gitbook_readme_badge&utm_medium=organic&utm_campaign=preview_documentation&utm_content=link">
|
||||||
<img
|
<img
|
||||||
src="https://img.shields.io/static/v1?message=Documented%20on%20GitBook&logo=gitbook&logoColor=ffffff&label=%20&labelColor=5c5c5c&color=3F89A1"
|
src="https://img.shields.io/static/v1?message=Documented%20on%20GitBook&logo=gitbook&logoColor=ffffff&label=%20&labelColor=5c5c5c&color=3F89A1"
|
||||||
/>
|
/>
|
||||||
|
|||||||
+2
-1
@@ -20,7 +20,8 @@
|
|||||||
"**/.wrangler/**/*",
|
"**/.wrangler/**/*",
|
||||||
"packages/openapi-parser/src/fixtures/**/*",
|
"packages/openapi-parser/src/fixtures/**/*",
|
||||||
"packages/emoji-codepoints/index.ts",
|
"packages/emoji-codepoints/index.ts",
|
||||||
"packages/icons/src/data/*.json"
|
"packages/icons/src/data/*.json",
|
||||||
|
"packages/cache-do/worker-configuration.d.ts"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"formatter": {
|
"formatter": {
|
||||||
|
|||||||
+10
-6
@@ -4,15 +4,14 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "^1.9.4",
|
"@biomejs/biome": "^1.9.4",
|
||||||
"@changesets/cli": "^2.27.12",
|
"@changesets/cli": "^2.27.12",
|
||||||
"turbo": "^2.4.4",
|
"turbo": "^2.5.0",
|
||||||
"vercel": "^39.3.0"
|
"vercel": "^39.3.0"
|
||||||
},
|
},
|
||||||
"packageManager": "bun@1.2.5",
|
"packageManager": "bun@1.2.15",
|
||||||
"overrides": {
|
"overrides": {
|
||||||
"@codemirror/state": "6.4.1",
|
"@codemirror/state": "6.4.1",
|
||||||
"react": "18.3.1",
|
"react": "^19.0.0",
|
||||||
"react-dom": "18.3.1",
|
"react-dom": "^19.0.0"
|
||||||
"@gitbook/api": "0.106.0"
|
|
||||||
},
|
},
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -34,7 +33,12 @@
|
|||||||
"download:env": "op read op://gitbook-x-dev/gitbook-open/.env.local >> .env.local",
|
"download:env": "op read op://gitbook-x-dev/gitbook-open/.env.local >> .env.local",
|
||||||
"clean": "turbo run clean"
|
"clean": "turbo run clean"
|
||||||
},
|
},
|
||||||
"workspaces": ["packages/*"],
|
"workspaces": {
|
||||||
|
"packages": ["packages/*"],
|
||||||
|
"catalog": {
|
||||||
|
"@gitbook/api": "^0.121.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"patchedDependencies": {
|
"patchedDependencies": {
|
||||||
"decode-named-character-reference@1.0.2": "patches/decode-named-character-reference@1.0.2.patch",
|
"decode-named-character-reference@1.0.2": "patches/decode-named-character-reference@1.0.2.patch",
|
||||||
"@vercel/next@4.4.2": "patches/@vercel%2Fnext@4.4.2.patch"
|
"@vercel/next@4.4.2": "patches/@vercel%2Fnext@4.4.2.patch"
|
||||||
|
|||||||
@@ -21,10 +21,10 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"typescript": "^5.5.3",
|
"typescript": "^5.5.3",
|
||||||
"wrangler": "^3.112.0"
|
"wrangler": "^4.10.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"generate": "wrangler types --experimental-include-runtime",
|
"generate": "wrangler types",
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"typecheck": "tsc --noEmit",
|
"typecheck": "tsc --noEmit",
|
||||||
"dev": "tsc -w",
|
"dev": "tsc -w",
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"isolatedModules": true,
|
"isolatedModules": true,
|
||||||
"incremental": true,
|
"incremental": true,
|
||||||
"types": ["./.wrangler/types/runtime.d.ts"]
|
"types": ["./worker-configuration.d.ts"]
|
||||||
},
|
},
|
||||||
"include": ["src/**/*.ts"],
|
"include": ["src/**/*.ts"],
|
||||||
"exclude": ["node_modules"]
|
"exclude": ["node_modules"]
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"extends": ["//"],
|
||||||
|
"tasks": {
|
||||||
|
"generate": {
|
||||||
|
"outputs": ["worker-configuration.d.ts"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,17 @@
|
|||||||
# @gitbook/cache-tags
|
# @gitbook/cache-tags
|
||||||
|
|
||||||
|
## 0.3.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 77397ca: Fix version of @gitbook/api referenced in package.json
|
||||||
|
|
||||||
|
## 0.3.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- 116575c: Improve typing of getComputedContentSourceCacheTags to match latest API specification
|
||||||
|
|
||||||
## 0.2.0
|
## 0.2.0
|
||||||
|
|
||||||
### Minor Changes
|
### Minor Changes
|
||||||
|
|||||||
@@ -8,9 +8,9 @@
|
|||||||
"default": "./dist/index.js"
|
"default": "./dist/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"version": "0.2.0",
|
"version": "0.3.1",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@gitbook/api": "*",
|
"@gitbook/api": "catalog:",
|
||||||
"assert-never": "^1.2.1"
|
"assert-never": "^1.2.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -1,5 +1,25 @@
|
|||||||
# @gitbook/colors
|
# @gitbook/colors
|
||||||
|
|
||||||
|
## 0.3.3
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- c3f6b8c: Update chroma ratio per step
|
||||||
|
- 5e975ab: Fix code highlighting for HTTP
|
||||||
|
- f7a3470: Change lightness check for color step 9 to allow input colors with a higher-than-needed contrast
|
||||||
|
|
||||||
|
## 0.3.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- cdffd7c: Desaturate text colors by decreasing chroma for the last steps of the color scale
|
||||||
|
|
||||||
|
## 0.3.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- fb90eb0: Reduce chroma of first color scale step
|
||||||
|
|
||||||
## 0.3.0
|
## 0.3.0
|
||||||
|
|
||||||
### Minor Changes
|
### Minor Changes
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
"default": "./dist/index.js"
|
"default": "./dist/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"version": "0.3.0",
|
"version": "0.3.3",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"typescript": "^5.5.3"
|
"typescript": "^5.5.3"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -214,13 +214,31 @@ export function colorScale(
|
|||||||
const targetL =
|
const targetL =
|
||||||
foregroundColor.L * mapping[index] + backgroundColor.L * (1 - mapping[index]);
|
foregroundColor.L * mapping[index] + backgroundColor.L * (1 - mapping[index]);
|
||||||
|
|
||||||
if (index === 8 && !mix && Math.abs(baseColor.L - targetL) < 0.2) {
|
if (
|
||||||
|
index === 8 &&
|
||||||
|
!mix &&
|
||||||
|
(darkMode ? targetL - baseColor.L < 0.2 : baseColor.L - targetL < 0.2)
|
||||||
|
) {
|
||||||
// Original colour is close enough to target, so let's use the original colour as step 9.
|
// Original colour is close enough to target, so let's use the original colour as step 9.
|
||||||
result.push(hex);
|
result.push(hex);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const chromaRatio = index < 8 ? (index + 1) * 0.05 : 1;
|
const chromaRatio = (() => {
|
||||||
|
switch (index) {
|
||||||
|
// Step 9 and 10 have max chroma, meaning they are fully saturated.
|
||||||
|
case 8:
|
||||||
|
case 9:
|
||||||
|
return 1;
|
||||||
|
// Step 11 and 12 have a reduced chroma
|
||||||
|
case 10:
|
||||||
|
return 0.4;
|
||||||
|
case 11:
|
||||||
|
return 0.1;
|
||||||
|
default:
|
||||||
|
return index * 0.05;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
const shade = {
|
const shade = {
|
||||||
L: targetL, // Blend lightness
|
L: targetL, // Blend lightness
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
dist/
|
||||||
|
src/data/*.json
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# `@gitbook/fonts`
|
||||||
|
|
||||||
|
Utilities to lookup default fonts supported by GitBook.
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
import fs from 'node:fs/promises';
|
||||||
|
import path from 'node:path';
|
||||||
|
|
||||||
|
import { APIv2 } from 'google-font-metadata';
|
||||||
|
|
||||||
|
import { CustomizationDefaultFont } from '@gitbook/api';
|
||||||
|
|
||||||
|
import type { FontDefinitions } from '../src/types';
|
||||||
|
|
||||||
|
const googleFontsMap: { [fontName in CustomizationDefaultFont]: string } = {
|
||||||
|
[CustomizationDefaultFont.Inter]: 'inter',
|
||||||
|
[CustomizationDefaultFont.FiraSans]: 'fira-sans-extra-condensed',
|
||||||
|
[CustomizationDefaultFont.IBMPlexSerif]: 'ibm-plex-serif',
|
||||||
|
[CustomizationDefaultFont.Lato]: 'lato',
|
||||||
|
[CustomizationDefaultFont.Merriweather]: 'merriweather',
|
||||||
|
[CustomizationDefaultFont.NotoSans]: 'noto-sans',
|
||||||
|
[CustomizationDefaultFont.OpenSans]: 'open-sans',
|
||||||
|
[CustomizationDefaultFont.Overpass]: 'overpass',
|
||||||
|
[CustomizationDefaultFont.Poppins]: 'poppins',
|
||||||
|
[CustomizationDefaultFont.Raleway]: 'raleway',
|
||||||
|
[CustomizationDefaultFont.Roboto]: 'roboto',
|
||||||
|
[CustomizationDefaultFont.RobotoSlab]: 'roboto-slab',
|
||||||
|
[CustomizationDefaultFont.SourceSansPro]: 'source-sans-3',
|
||||||
|
[CustomizationDefaultFont.Ubuntu]: 'ubuntu',
|
||||||
|
[CustomizationDefaultFont.ABCFavorit]: 'inter',
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scripts to generate the list of all icons.
|
||||||
|
*/
|
||||||
|
async function main() {
|
||||||
|
// @ts-expect-error - we build the object
|
||||||
|
const output: FontDefinitions = {};
|
||||||
|
|
||||||
|
for (const font of Object.values(CustomizationDefaultFont)) {
|
||||||
|
const googleFontName = googleFontsMap[font];
|
||||||
|
const fontMetadata = APIv2[googleFontName.toLowerCase()];
|
||||||
|
if (!fontMetadata) {
|
||||||
|
throw new Error(`Font ${googleFontName} not found`);
|
||||||
|
}
|
||||||
|
|
||||||
|
output[font] = {
|
||||||
|
font: googleFontName,
|
||||||
|
unicodeRange: fontMetadata.unicodeRange,
|
||||||
|
variants: {
|
||||||
|
'400': {},
|
||||||
|
'700': {},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.keys(output[font].variants).forEach((weight) => {
|
||||||
|
const variants = fontMetadata.variants[weight];
|
||||||
|
const normalVariant = variants.normal;
|
||||||
|
if (!normalVariant) {
|
||||||
|
throw new Error(`Font ${googleFontName} has no normal variant`);
|
||||||
|
}
|
||||||
|
|
||||||
|
output[font].variants[weight] = {};
|
||||||
|
Object.entries(normalVariant).forEach(([script, url]) => {
|
||||||
|
output[font].variants[weight][script] = url.url.woff;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await writeDataFile('fonts', JSON.stringify(output, null, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We write both in dist and src as the build process might have happen already
|
||||||
|
* and tsc doesn't copy the files.
|
||||||
|
*/
|
||||||
|
async function writeDataFile(name, content) {
|
||||||
|
const srcData = path.resolve(__dirname, '../src/data');
|
||||||
|
const distData = path.resolve(__dirname, '../dist/data');
|
||||||
|
|
||||||
|
// Ensure the directories exists
|
||||||
|
await Promise.all([
|
||||||
|
fs.mkdir(srcData, { recursive: true }),
|
||||||
|
fs.mkdir(distData, { recursive: true }),
|
||||||
|
]);
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
fs.writeFile(path.resolve(srcData, `${name}.json`), content),
|
||||||
|
fs.writeFile(path.resolve(distData, `${name}.json`), content),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
main().catch((error) => {
|
||||||
|
console.error(`Error generating icons list: ${error}`);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"name": "@gitbook/fonts",
|
||||||
|
"type": "module",
|
||||||
|
"exports": {
|
||||||
|
".": {
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"development": "./src/index.ts",
|
||||||
|
"default": "./dist/index.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"version": "0.0.0",
|
||||||
|
"dependencies": {
|
||||||
|
"@gitbook/api": "catalog:"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"google-font-metadata": "^6.0.3",
|
||||||
|
"typescript": "^5.5.3"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"generate": "bun ./bin/generate.js",
|
||||||
|
"build": "tsc --project tsconfig.build.json",
|
||||||
|
"typecheck": "tsc --noEmit",
|
||||||
|
"dev": "tsc -w",
|
||||||
|
"clean": "rm -rf ./dist && rm -rf ./src/data",
|
||||||
|
"unit": "bun test"
|
||||||
|
},
|
||||||
|
"files": ["dist", "src", "bin", "README.md", "CHANGELOG.md"],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=20.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
// Bun Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`getDefaultFont should return correct object for Latin text 1`] = `
|
||||||
|
{
|
||||||
|
"font": "Inter",
|
||||||
|
"url": "https://fonts.gstatic.com/s/inter/v18/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfAZ9hjp-Ek-_0ew.woff",
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`getDefaultFont should return correct object for Cyrillic text 1`] = `
|
||||||
|
{
|
||||||
|
"font": "Inter",
|
||||||
|
"url": "https://fonts.gstatic.com/s/inter/v18/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfAZthjp-Ek-_0ewmM.woff",
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`getDefaultFont should return correct object for Greek text 1`] = `
|
||||||
|
{
|
||||||
|
"font": "Inter",
|
||||||
|
"url": "https://fonts.gstatic.com/s/inter/v18/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfAZxhjp-Ek-_0ewmM.woff",
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`getDefaultFont should handle mixed script text 1`] = `
|
||||||
|
{
|
||||||
|
"font": "Inter",
|
||||||
|
"url": "https://fonts.gstatic.com/s/inter/v18/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfAZthjp-Ek-_0ewmM.woff",
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`getDefaultFont should handle different font weights: regular 1`] = `
|
||||||
|
{
|
||||||
|
"font": "Inter",
|
||||||
|
"url": "https://fonts.gstatic.com/s/inter/v18/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfAZ9hjp-Ek-_0ew.woff",
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`getDefaultFont should handle different font weights: bold 1`] = `
|
||||||
|
{
|
||||||
|
"font": "Inter",
|
||||||
|
"url": "https://fonts.gstatic.com/s/inter/v18/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuFuYAZ9hjp-Ek-_0ew.woff",
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`getDefaultFont should handle different fonts: inter 1`] = `
|
||||||
|
{
|
||||||
|
"font": "Inter",
|
||||||
|
"url": "https://fonts.gstatic.com/s/inter/v18/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfAZ9hjp-Ek-_0ew.woff",
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`getDefaultFont should handle different fonts: roboto 1`] = `
|
||||||
|
{
|
||||||
|
"font": "Roboto",
|
||||||
|
"url": "https://fonts.gstatic.com/s/roboto/v32/KFOmCnqEu92Fr1Mu4mxMKTU1Kg.woff",
|
||||||
|
}
|
||||||
|
`;
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import type { FontDefinitions } from './types';
|
||||||
|
|
||||||
|
import rawFonts from './data/fonts.json' with { type: 'json' };
|
||||||
|
|
||||||
|
export const fonts: FontDefinitions = rawFonts;
|
||||||
@@ -0,0 +1,119 @@
|
|||||||
|
import { describe, expect, it } from 'bun:test';
|
||||||
|
import { CustomizationDefaultFont } from '@gitbook/api';
|
||||||
|
import { getDefaultFont } from './getDefaultFont';
|
||||||
|
|
||||||
|
describe('getDefaultFont', () => {
|
||||||
|
it('should return null for invalid font', () => {
|
||||||
|
const result = getDefaultFont({
|
||||||
|
font: 'invalid-font' as CustomizationDefaultFont,
|
||||||
|
text: 'Hello',
|
||||||
|
weight: 400,
|
||||||
|
});
|
||||||
|
expect(result).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return null for invalid weight', () => {
|
||||||
|
const result = getDefaultFont({
|
||||||
|
font: CustomizationDefaultFont.Inter,
|
||||||
|
text: 'Hello',
|
||||||
|
weight: 999 as any,
|
||||||
|
});
|
||||||
|
expect(result).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return null for text not supported by any script', () => {
|
||||||
|
const result = getDefaultFont({
|
||||||
|
font: CustomizationDefaultFont.Inter,
|
||||||
|
text: '😀', // Emoji not supported by Inter
|
||||||
|
weight: 400,
|
||||||
|
});
|
||||||
|
expect(result).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return correct object for Latin text', () => {
|
||||||
|
const result = getDefaultFont({
|
||||||
|
font: CustomizationDefaultFont.Inter,
|
||||||
|
text: 'Hello World',
|
||||||
|
weight: 400,
|
||||||
|
});
|
||||||
|
expect(result).not.toBeNull();
|
||||||
|
expect(result?.font).toBe(CustomizationDefaultFont.Inter);
|
||||||
|
expect(result).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return correct object for Cyrillic text', () => {
|
||||||
|
const result = getDefaultFont({
|
||||||
|
font: CustomizationDefaultFont.Inter,
|
||||||
|
text: 'Привет мир',
|
||||||
|
weight: 400,
|
||||||
|
});
|
||||||
|
expect(result).not.toBeNull();
|
||||||
|
expect(result?.font).toBe(CustomizationDefaultFont.Inter);
|
||||||
|
expect(result).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return correct object for Greek text', () => {
|
||||||
|
const result = getDefaultFont({
|
||||||
|
font: CustomizationDefaultFont.Inter,
|
||||||
|
text: 'Γεια σας',
|
||||||
|
weight: 400,
|
||||||
|
});
|
||||||
|
expect(result).not.toBeNull();
|
||||||
|
expect(result?.font).toBe(CustomizationDefaultFont.Inter);
|
||||||
|
expect(result).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle mixed script text', () => {
|
||||||
|
const result = getDefaultFont({
|
||||||
|
font: CustomizationDefaultFont.Inter,
|
||||||
|
text: 'Hello Привет',
|
||||||
|
weight: 400,
|
||||||
|
});
|
||||||
|
expect(result).not.toBeNull();
|
||||||
|
expect(result?.font).toBe(CustomizationDefaultFont.Inter);
|
||||||
|
expect(result).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle different font weights', () => {
|
||||||
|
const regular = getDefaultFont({
|
||||||
|
font: CustomizationDefaultFont.Inter,
|
||||||
|
text: 'Hello',
|
||||||
|
weight: 400,
|
||||||
|
});
|
||||||
|
const bold = getDefaultFont({
|
||||||
|
font: CustomizationDefaultFont.Inter,
|
||||||
|
text: 'Hello',
|
||||||
|
weight: 700,
|
||||||
|
});
|
||||||
|
expect(regular).not.toBeNull();
|
||||||
|
expect(bold).not.toBeNull();
|
||||||
|
expect(regular).toMatchSnapshot('regular');
|
||||||
|
expect(bold).toMatchSnapshot('bold');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle empty string', () => {
|
||||||
|
const result = getDefaultFont({
|
||||||
|
font: CustomizationDefaultFont.Inter,
|
||||||
|
text: '',
|
||||||
|
weight: 400,
|
||||||
|
});
|
||||||
|
expect(result).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle different fonts', () => {
|
||||||
|
const inter = getDefaultFont({
|
||||||
|
font: CustomizationDefaultFont.Inter,
|
||||||
|
text: 'Hello',
|
||||||
|
weight: 400,
|
||||||
|
});
|
||||||
|
const roboto = getDefaultFont({
|
||||||
|
font: CustomizationDefaultFont.Roboto,
|
||||||
|
text: 'Hello',
|
||||||
|
weight: 400,
|
||||||
|
});
|
||||||
|
expect(inter).not.toBeNull();
|
||||||
|
expect(roboto).not.toBeNull();
|
||||||
|
expect(inter).toMatchSnapshot('inter');
|
||||||
|
expect(roboto).toMatchSnapshot('roboto');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
import type { CustomizationDefaultFont } from '@gitbook/api';
|
||||||
|
import { fonts } from './fonts';
|
||||||
|
import type { FontWeight } from './types';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the URL to load a font for a text.
|
||||||
|
*/
|
||||||
|
export function getDefaultFont(input: {
|
||||||
|
/**
|
||||||
|
* GitBook font to use.
|
||||||
|
*/
|
||||||
|
font: CustomizationDefaultFont;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Text to display with the font.
|
||||||
|
*/
|
||||||
|
text: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Font weight to use.
|
||||||
|
*/
|
||||||
|
weight: FontWeight;
|
||||||
|
}): { font: string; url: string } | null {
|
||||||
|
if (!input.text.trim()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fontDefinition = fonts[input.font];
|
||||||
|
if (!fontDefinition) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const variant = fontDefinition.variants[`${input.weight}`];
|
||||||
|
if (!variant) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const script = getBestUnicodeRange(input.text, fontDefinition.unicodeRange);
|
||||||
|
if (!script) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return variant[script]
|
||||||
|
? {
|
||||||
|
font: input.font,
|
||||||
|
url: variant[script],
|
||||||
|
}
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine which named @font-face unicode-range covers
|
||||||
|
* the greatest share of the characters in `text`.
|
||||||
|
*
|
||||||
|
* @param text The text you want to inspect.
|
||||||
|
* @param ranges An object whose keys are range names and whose
|
||||||
|
* values are CSS-style comma-separated unicode-range
|
||||||
|
* declarations (e.g. "U+0370-03FF,U+1F00-1FFF").
|
||||||
|
* @returns The key of the best-matching range, or `null`
|
||||||
|
* when nothing matches at all.
|
||||||
|
*/
|
||||||
|
function getBestUnicodeRange(text: string, ranges: Record<string, string>): string | null {
|
||||||
|
// ---------- helper: parse "U+XXXX" or "U+XXXX-YYYY" ----------
|
||||||
|
const parseOne = (token: string): [number, number] | null => {
|
||||||
|
token = token.trim().toUpperCase();
|
||||||
|
if (!token.startsWith('U+')) return null;
|
||||||
|
|
||||||
|
const body = token.slice(2); // drop "U+"
|
||||||
|
const [startHex, endHex] = body.split('-');
|
||||||
|
const start = Number.parseInt(startHex, 16);
|
||||||
|
const end = endHex ? Number.parseInt(endHex, 16) : start;
|
||||||
|
|
||||||
|
if (Number.isNaN(start) || Number.isNaN(end) || end < start) return null;
|
||||||
|
return [start, end];
|
||||||
|
};
|
||||||
|
|
||||||
|
// ---------- helper: build lookup table ----------
|
||||||
|
const parsed: Record<string, [number, number][]> = {};
|
||||||
|
for (const [label, list] of Object.entries(ranges)) {
|
||||||
|
parsed[label] = list
|
||||||
|
.split(',')
|
||||||
|
.map(parseOne)
|
||||||
|
.filter((x): x is [number, number] => x !== null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- tally code-point hits ----------
|
||||||
|
const hits: Record<string, number> = Object.fromEntries(Object.keys(parsed).map((k) => [k, 0]));
|
||||||
|
|
||||||
|
for (let i = 0; i < text.length; ) {
|
||||||
|
const cp = text.codePointAt(i)!;
|
||||||
|
i += cp > 0xffff ? 2 : 1; // advance by 1 UTF-16 code-unit (or 2 for surrogates)
|
||||||
|
|
||||||
|
for (const [label, rangesArr] of Object.entries(parsed)) {
|
||||||
|
if (rangesArr.some(([lo, hi]) => cp >= lo && cp <= hi)) {
|
||||||
|
hits[label]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- choose the "best" ----------
|
||||||
|
let winner: string | null = null;
|
||||||
|
let maxCount = 0;
|
||||||
|
|
||||||
|
for (const [label, count] of Object.entries(hits)) {
|
||||||
|
if (count > maxCount) {
|
||||||
|
maxCount = count;
|
||||||
|
winner = label;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return maxCount > 0 ? winner : null;
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export * from './getDefaultFont';
|
||||||
|
export * from './types';
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import type { CustomizationDefaultFont } from '@gitbook/api';
|
||||||
|
|
||||||
|
export type FontWeight = 400 | 700;
|
||||||
|
|
||||||
|
export type FontDefinition = {
|
||||||
|
font: string;
|
||||||
|
unicodeRange: {
|
||||||
|
[script: string]: string;
|
||||||
|
};
|
||||||
|
variants: {
|
||||||
|
[weight in string]: {
|
||||||
|
[script: string]: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export type FontDefinitions = { [fontName in CustomizationDefaultFont]: FontDefinition };
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"exclude": ["node_modules", "src/**/*.test.ts"]
|
||||||
|
}
|
||||||
@@ -1,18 +1,19 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "esnext",
|
"lib": ["es2023"],
|
||||||
"lib": ["dom", "dom.iterable", "esnext"],
|
"module": "ESNext",
|
||||||
"allowJs": true,
|
"target": "es2022",
|
||||||
"skipLibCheck": true,
|
|
||||||
"strict": true,
|
"strict": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"allowJs": true,
|
||||||
"noEmit": false,
|
"noEmit": false,
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"outDir": "dist",
|
"outDir": "dist",
|
||||||
"esModuleInterop": true,
|
|
||||||
"module": "esnext",
|
|
||||||
"moduleResolution": "bundler",
|
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"isolatedModules": true,
|
"isolatedModules": true,
|
||||||
|
"jsx": "react-jsx",
|
||||||
"incremental": true,
|
"incremental": true,
|
||||||
"types": [
|
"types": [
|
||||||
"bun-types" // add Bun global
|
"bun-types" // add Bun global
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"extends": ["//"],
|
||||||
|
"tasks": {
|
||||||
|
"generate": {
|
||||||
|
"inputs": ["bin/**/*", "package.json"],
|
||||||
|
"outputs": ["src/data/*.json", "dist/data/*.json"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
# cloudflare
|
# cloudflare
|
||||||
.open-next
|
.open-next
|
||||||
|
.wrangler
|
||||||
|
|
||||||
# Symbolic links
|
# Symbolic links
|
||||||
public
|
public
|
||||||
|
|||||||
@@ -1,5 +1,39 @@
|
|||||||
# gitbook-v2
|
# gitbook-v2
|
||||||
|
|
||||||
|
## 0.3.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- 3119066: Add support for reusable content across spaces.
|
||||||
|
- 7d7806d: Pass SVG images through image resizing without resizing them to serve them from optimal host.
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 1c8d9fe: keep data cache in OpenNext between deployment
|
||||||
|
- 778624a: Only resize images with supported extensions.
|
||||||
|
- e6ddc0f: Fix URL in sitemap
|
||||||
|
- 5e975ab: Fix code highlighting for HTTP
|
||||||
|
- e15757d: Fix crash on Cloudflare by using latest stable version of Next.js instead of canary
|
||||||
|
- 634e0b4: Improve error messages around undefined site sections.
|
||||||
|
- 97b7c79: Increase logging around caching behaviour causing page crashes.
|
||||||
|
- 3f29206: Update the regex for validating site redirect
|
||||||
|
- dd043df: Revert investigation work around URL caches.
|
||||||
|
|
||||||
|
## 0.2.5
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [77397ca]
|
||||||
|
- @gitbook/cache-tags@0.3.1
|
||||||
|
|
||||||
|
## 0.2.4
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 4234289: Fix incoming URL for requests that were proxied
|
||||||
|
- Updated dependencies [116575c]
|
||||||
|
- @gitbook/cache-tags@0.3.0
|
||||||
|
|
||||||
## 0.2.3
|
## 0.2.3
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
Vendored
+1
@@ -1,5 +1,6 @@
|
|||||||
/// <reference types="next" />
|
/// <reference types="next" />
|
||||||
/// <reference types="next/image-types/global" />
|
/// <reference types="next/image-types/global" />
|
||||||
|
/// <reference types="next/navigation-types/compat/navigation" />
|
||||||
|
|
||||||
// NOTE: This file should not be edited
|
// NOTE: This file should not be edited
|
||||||
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ const nextConfig = {
|
|||||||
experimental: {
|
experimental: {
|
||||||
// This is needed to throw "forbidden" when the api token expired during revalidation
|
// This is needed to throw "forbidden" when the api token expired during revalidation
|
||||||
authInterrupts: true,
|
authInterrupts: true,
|
||||||
|
|
||||||
// This is needed to use 'use cache'
|
|
||||||
useCache: true,
|
useCache: true,
|
||||||
|
|
||||||
// Content is fully static, we can cache it in the session memory cache for a long time
|
// Content is fully static, we can cache it in the session memory cache for a long time
|
||||||
@@ -33,7 +31,9 @@ const nextConfig = {
|
|||||||
GITBOOK_ASSETS_PREFIX: process.env.GITBOOK_ASSETS_PREFIX,
|
GITBOOK_ASSETS_PREFIX: process.env.GITBOOK_ASSETS_PREFIX,
|
||||||
GITBOOK_SECRET: process.env.GITBOOK_SECRET,
|
GITBOOK_SECRET: process.env.GITBOOK_SECRET,
|
||||||
GITBOOK_IMAGE_RESIZE_SIGNING_KEY: process.env.GITBOOK_IMAGE_RESIZE_SIGNING_KEY,
|
GITBOOK_IMAGE_RESIZE_SIGNING_KEY: process.env.GITBOOK_IMAGE_RESIZE_SIGNING_KEY,
|
||||||
|
GITBOOK_IMAGE_RESIZE_MODE: process.env.GITBOOK_IMAGE_RESIZE_MODE,
|
||||||
GITBOOK_FONTS_URL: process.env.GITBOOK_FONTS_URL,
|
GITBOOK_FONTS_URL: process.env.GITBOOK_FONTS_URL,
|
||||||
|
GITBOOK_RUNTIME: process.env.GITBOOK_RUNTIME,
|
||||||
|
|
||||||
// Next.js envs
|
// Next.js envs
|
||||||
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: process.env.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY,
|
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: process.env.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY,
|
||||||
@@ -53,6 +53,24 @@ const nextConfig = {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async headers() {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
source: '/~gitbook/static/:path*',
|
||||||
|
headers: [
|
||||||
|
{
|
||||||
|
key: 'Cache-Control',
|
||||||
|
value: 'public, max-age=31536000, immutable',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'Access-Control-Allow-Origin',
|
||||||
|
value: '*',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default nextConfig;
|
export default nextConfig;
|
||||||
|
|||||||
@@ -1,10 +1,29 @@
|
|||||||
import { defineCloudflareConfig } from '@opennextjs/cloudflare';
|
import type { OpenNextConfig } from '@opennextjs/cloudflare';
|
||||||
import d1TagCache from '@opennextjs/cloudflare/d1-tag-cache';
|
|
||||||
import kvIncrementalCache from '@opennextjs/cloudflare/kv-cache';
|
|
||||||
import memoryQueue from '@opennextjs/cloudflare/memory-queue';
|
|
||||||
|
|
||||||
export default defineCloudflareConfig({
|
export default {
|
||||||
incrementalCache: kvIncrementalCache,
|
default: {
|
||||||
queue: memoryQueue,
|
override: {
|
||||||
tagCache: d1TagCache,
|
wrapper: 'cloudflare-node',
|
||||||
});
|
converter: 'edge',
|
||||||
|
proxyExternalRequest: 'fetch',
|
||||||
|
queue: () => import('./openNext/queue/middleware').then((m) => m.default),
|
||||||
|
incrementalCache: () => import('./openNext/incrementalCache').then((m) => m.default),
|
||||||
|
tagCache: () => import('./openNext/tagCache/middleware').then((m) => m.default),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
middleware: {
|
||||||
|
external: true,
|
||||||
|
override: {
|
||||||
|
wrapper: 'cloudflare-edge',
|
||||||
|
converter: 'edge',
|
||||||
|
proxyExternalRequest: 'fetch',
|
||||||
|
queue: () => import('./openNext/queue/middleware').then((m) => m.default),
|
||||||
|
incrementalCache: () => import('./openNext/incrementalCache').then((m) => m.default),
|
||||||
|
tagCache: () => import('./openNext/tagCache/middleware').then((m) => m.default),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
dangerous: {
|
||||||
|
enableCacheInterception: true,
|
||||||
|
},
|
||||||
|
edgeExternals: ['node:crypto'],
|
||||||
|
} satisfies OpenNextConfig;
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import { runWithCloudflareRequestContext } from '../../.open-next/cloudflare/init.js';
|
||||||
|
|
||||||
|
import { DurableObject } from 'cloudflare:workers';
|
||||||
|
|
||||||
|
// Only needed to run locally, in prod we'll use the one from do.js
|
||||||
|
export class R2WriteBuffer extends DurableObject {
|
||||||
|
writePromise;
|
||||||
|
|
||||||
|
async write(cacheKey, value) {
|
||||||
|
// We are already writing to this key
|
||||||
|
if (this.writePromise) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.writePromise = this.env.NEXT_INC_CACHE_R2_BUCKET.put(cacheKey, value);
|
||||||
|
this.ctx.waitUntil(
|
||||||
|
this.writePromise.finally(() => {
|
||||||
|
this.writePromise = undefined;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
async fetch(request, env, ctx) {
|
||||||
|
return runWithCloudflareRequestContext(request, env, ctx, async () => {
|
||||||
|
// We can't move the handler import to the top level, otherwise the runtime will not be properly initialized
|
||||||
|
const { handler } = await import(
|
||||||
|
'../../.open-next/server-functions/default/handler.mjs'
|
||||||
|
);
|
||||||
|
|
||||||
|
// - `Request`s are handled by the Next server
|
||||||
|
return handler(request, env, ctx);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -0,0 +1,163 @@
|
|||||||
|
{
|
||||||
|
"main": "default.js",
|
||||||
|
"name": "gitbook-open-v2-server",
|
||||||
|
"compatibility_date": "2025-04-14",
|
||||||
|
"compatibility_flags": [
|
||||||
|
"nodejs_compat",
|
||||||
|
"allow_importable_env",
|
||||||
|
"global_fetch_strictly_public"
|
||||||
|
],
|
||||||
|
"observability": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"vars": {
|
||||||
|
"NEXT_CACHE_DO_QUEUE_DISABLE_SQLITE": "true"
|
||||||
|
},
|
||||||
|
"env": {
|
||||||
|
"dev": {
|
||||||
|
"vars": {
|
||||||
|
"STAGE": "dev"
|
||||||
|
},
|
||||||
|
"r2_buckets": [
|
||||||
|
{
|
||||||
|
"binding": "NEXT_INC_CACHE_R2_BUCKET",
|
||||||
|
"bucket_name": "gitbook-open-v2-cache-preview"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"services": [
|
||||||
|
{
|
||||||
|
"binding": "WORKER_SELF_REFERENCE",
|
||||||
|
"service": "gitbook-open-v2-server-dev"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"durable_objects": {
|
||||||
|
"bindings": [
|
||||||
|
{
|
||||||
|
"name": "WRITE_BUFFER",
|
||||||
|
"class_name": "R2WriteBuffer"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"migrations": [
|
||||||
|
{
|
||||||
|
"tag": "v1",
|
||||||
|
"new_sqlite_classes": ["R2WriteBuffer"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"preview": {
|
||||||
|
"vars": {
|
||||||
|
"STAGE": "preview",
|
||||||
|
// Just as a test for the preview environment to check that everything works
|
||||||
|
"NEXT_PRIVATE_DEBUG_CACHE": "true"
|
||||||
|
},
|
||||||
|
"r2_buckets": [
|
||||||
|
{
|
||||||
|
"binding": "NEXT_INC_CACHE_R2_BUCKET",
|
||||||
|
"bucket_name": "gitbook-open-v2-cache-preview"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"services": [
|
||||||
|
{
|
||||||
|
"binding": "WORKER_SELF_REFERENCE",
|
||||||
|
"service": "gitbook-open-v2-server-preview"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"durable_objects": {
|
||||||
|
"bindings": [
|
||||||
|
{
|
||||||
|
"name": "WRITE_BUFFER",
|
||||||
|
"class_name": "R2WriteBuffer",
|
||||||
|
"script_name": "gitbook-open-v2-do-preview"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "NEXT_TAG_CACHE_DO_SHARDED",
|
||||||
|
"class_name": "DOShardedTagCache",
|
||||||
|
"script_name": "gitbook-open-v2-do-preview"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "NEXT_CACHE_DO_QUEUE",
|
||||||
|
"class_name": "DOQueueHandler",
|
||||||
|
"script_name": "gitbook-open-v2-do-preview"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"staging": {
|
||||||
|
"r2_buckets": [
|
||||||
|
{
|
||||||
|
"binding": "NEXT_INC_CACHE_R2_BUCKET",
|
||||||
|
"bucket_name": "gitbook-open-v2-cache-staging"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"services": [
|
||||||
|
{
|
||||||
|
"binding": "WORKER_SELF_REFERENCE",
|
||||||
|
"service": "gitbook-open-v2-server-staging"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"durable_objects": {
|
||||||
|
"bindings": [
|
||||||
|
{
|
||||||
|
"name": "WRITE_BUFFER",
|
||||||
|
"class_name": "R2WriteBuffer",
|
||||||
|
"script_name": "gitbook-open-v2-do-staging"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "NEXT_TAG_CACHE_DO_SHARDED",
|
||||||
|
"class_name": "DOShardedTagCache",
|
||||||
|
"script_name": "gitbook-open-v2-do-staging"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "NEXT_CACHE_DO_QUEUE",
|
||||||
|
"class_name": "DOQueueHandler",
|
||||||
|
"script_name": "gitbook-open-v2-do-staging"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"tail_consumers": [
|
||||||
|
{
|
||||||
|
"service": "gitbook-x-staging-tail"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"production": {
|
||||||
|
"r2_buckets": [
|
||||||
|
{
|
||||||
|
"binding": "NEXT_INC_CACHE_R2_BUCKET",
|
||||||
|
"bucket_name": "gitbook-open-v2-cache-production"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"services": [
|
||||||
|
{
|
||||||
|
"binding": "WORKER_SELF_REFERENCE",
|
||||||
|
"service": "gitbook-open-v2-server-production"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"durable_objects": {
|
||||||
|
"bindings": [
|
||||||
|
{
|
||||||
|
"name": "WRITE_BUFFER",
|
||||||
|
"class_name": "R2WriteBuffer",
|
||||||
|
"script_name": "gitbook-open-v2-do-production"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "NEXT_TAG_CACHE_DO_SHARDED",
|
||||||
|
"class_name": "DOShardedTagCache",
|
||||||
|
"script_name": "gitbook-open-v2-do-production"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "NEXT_CACHE_DO_QUEUE",
|
||||||
|
"class_name": "DOQueueHandler",
|
||||||
|
"script_name": "gitbook-open-v2-do-production"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"tail_consumers": [
|
||||||
|
{
|
||||||
|
"service": "gitbook-x-prod-tail"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
// This worker only purposes it to host the different DO that we will need in the other workers.
|
||||||
|
import { DurableObject } from 'cloudflare:workers';
|
||||||
|
|
||||||
|
// `use cache` could cause multiple writes to the same key to happen concurrently, there is a limit of 1 write per key/second
|
||||||
|
// so we need to buffer writes to the R2 bucket to avoid hitting this limit.
|
||||||
|
export class R2WriteBuffer extends DurableObject {
|
||||||
|
writePromise;
|
||||||
|
|
||||||
|
async write(cacheKey, value) {
|
||||||
|
// We are already writing to this key
|
||||||
|
if (this.writePromise) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.writePromise = this.env.NEXT_INC_CACHE_R2_BUCKET.put(cacheKey, value);
|
||||||
|
this.ctx.waitUntil(
|
||||||
|
this.writePromise.finally(() => {
|
||||||
|
this.writePromise = undefined;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { DOQueueHandler } from '../../.open-next/.build/durable-objects/queue.js';
|
||||||
|
|
||||||
|
export { DOShardedTagCache } from '../../.open-next/.build/durable-objects/sharded-tag-cache.js';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
async fetch() {
|
||||||
|
// This worker does not handle any requests, it only provides Durable Objects
|
||||||
|
return new Response('This worker is not meant to handle requests directly', {
|
||||||
|
status: 400,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'text/plain',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -0,0 +1,145 @@
|
|||||||
|
{
|
||||||
|
"main": "do.js",
|
||||||
|
"name": "gitbook-open-v2-do",
|
||||||
|
"compatibility_date": "2025-04-14",
|
||||||
|
"compatibility_flags": [
|
||||||
|
"nodejs_compat",
|
||||||
|
"allow_importable_env",
|
||||||
|
"global_fetch_strictly_public"
|
||||||
|
],
|
||||||
|
"observability": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"env": {
|
||||||
|
"preview": {
|
||||||
|
"vars": {
|
||||||
|
"STAGE": "preview",
|
||||||
|
"NEXT_CACHE_DO_QUEUE_DISABLE_SQLITE": "true"
|
||||||
|
},
|
||||||
|
"r2_buckets": [
|
||||||
|
{
|
||||||
|
"binding": "NEXT_INC_CACHE_R2_BUCKET",
|
||||||
|
"bucket_name": "gitbook-open-v2-cache-preview"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"services": [
|
||||||
|
{
|
||||||
|
"binding": "WORKER_SELF_REFERENCE",
|
||||||
|
"service": "gitbook-open-v2-preview"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"durable_objects": {
|
||||||
|
"bindings": [
|
||||||
|
{
|
||||||
|
"name": "NEXT_CACHE_DO_QUEUE",
|
||||||
|
"class_name": "DOQueueHandler"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "NEXT_TAG_CACHE_DO_SHARDED",
|
||||||
|
"class_name": "DOShardedTagCache"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "WRITE_BUFFER",
|
||||||
|
"class_name": "R2WriteBuffer"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"migrations": [
|
||||||
|
{
|
||||||
|
"tag": "v1",
|
||||||
|
"new_sqlite_classes": ["DOQueueHandler", "DOShardedTagCache", "R2WriteBuffer"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"staging": {
|
||||||
|
"vars": {
|
||||||
|
"STAGE": "staging",
|
||||||
|
"NEXT_CACHE_DO_QUEUE_DISABLE_SQLITE": "true"
|
||||||
|
},
|
||||||
|
"r2_buckets": [
|
||||||
|
{
|
||||||
|
"binding": "NEXT_INC_CACHE_R2_BUCKET",
|
||||||
|
"bucket_name": "gitbook-open-v2-cache-staging"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"tail_consumers": [
|
||||||
|
{
|
||||||
|
"service": "gitbook-x-staging-tail"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"services": [
|
||||||
|
{
|
||||||
|
"binding": "WORKER_SELF_REFERENCE",
|
||||||
|
"service": "gitbook-open-v2-staging"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"durable_objects": {
|
||||||
|
"bindings": [
|
||||||
|
{
|
||||||
|
"name": "NEXT_CACHE_DO_QUEUE",
|
||||||
|
"class_name": "DOQueueHandler"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "NEXT_TAG_CACHE_DO_SHARDED",
|
||||||
|
"class_name": "DOShardedTagCache"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "WRITE_BUFFER",
|
||||||
|
"class_name": "R2WriteBuffer"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"migrations": [
|
||||||
|
{
|
||||||
|
"tag": "v1",
|
||||||
|
"new_sqlite_classes": ["DOQueueHandler", "DOShardedTagCache", "R2WriteBuffer"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"production": {
|
||||||
|
"vars": {
|
||||||
|
"NEXT_CACHE_DO_QUEUE_DISABLE_SQLITE": "true",
|
||||||
|
"STAGE": "production"
|
||||||
|
},
|
||||||
|
"r2_buckets": [
|
||||||
|
{
|
||||||
|
"binding": "NEXT_INC_CACHE_R2_BUCKET",
|
||||||
|
"bucket_name": "gitbook-open-v2-cache-production"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"tail_consumers": [
|
||||||
|
{
|
||||||
|
"service": "gitbook-x-prod-tail"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"services": [
|
||||||
|
{
|
||||||
|
"binding": "WORKER_SELF_REFERENCE",
|
||||||
|
"service": "gitbook-open-v2-production"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"durable_objects": {
|
||||||
|
"bindings": [
|
||||||
|
{
|
||||||
|
"name": "NEXT_CACHE_DO_QUEUE",
|
||||||
|
"class_name": "DOQueueHandler"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "NEXT_TAG_CACHE_DO_SHARDED",
|
||||||
|
"class_name": "DOShardedTagCache"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "WRITE_BUFFER",
|
||||||
|
"class_name": "R2WriteBuffer"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"migrations": [
|
||||||
|
{
|
||||||
|
"tag": "v1",
|
||||||
|
"new_sqlite_classes": ["DOQueueHandler", "DOShardedTagCache", "R2WriteBuffer"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import { WorkerEntrypoint } from 'cloudflare:workers';
|
||||||
|
import { runWithCloudflareRequestContext } from '../../.open-next/cloudflare/init.js';
|
||||||
|
|
||||||
|
import { handler as middlewareHandler } from '../../.open-next/middleware/handler.mjs';
|
||||||
|
|
||||||
|
export { DOQueueHandler } from '../../.open-next/.build/durable-objects/queue.js';
|
||||||
|
|
||||||
|
export { DOShardedTagCache } from '../../.open-next/.build/durable-objects/sharded-tag-cache.js';
|
||||||
|
|
||||||
|
export default class extends WorkerEntrypoint {
|
||||||
|
async fetch(request) {
|
||||||
|
return runWithCloudflareRequestContext(request, this.env, this.ctx, async () => {
|
||||||
|
// - `Request`s are handled by the Next server
|
||||||
|
const reqOrResp = await middlewareHandler(request, this.env, this.ctx);
|
||||||
|
if (reqOrResp instanceof Response) {
|
||||||
|
return reqOrResp;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.env.STAGE !== 'preview') {
|
||||||
|
// https://developers.cloudflare.com/workers/configuration/versions-and-deployments/gradual-deployments/#version-affinity
|
||||||
|
reqOrResp.headers.set(
|
||||||
|
'Cloudflare-Workers-Version-Overrides',
|
||||||
|
`gitbook-open-v2-${this.env.STAGE}="${this.env.WORKER_VERSION_ID}"`
|
||||||
|
);
|
||||||
|
return this.env.DEFAULT_WORKER?.fetch(reqOrResp, {
|
||||||
|
cf: {
|
||||||
|
cacheEverything: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// If we are in preview mode, we need to send the request to the preview URL
|
||||||
|
const modifiedUrl = new URL(reqOrResp.url);
|
||||||
|
modifiedUrl.hostname = this.env.PREVIEW_HOSTNAME;
|
||||||
|
const nextRequest = new Request(modifiedUrl, reqOrResp);
|
||||||
|
return fetch(nextRequest, {
|
||||||
|
cf: {
|
||||||
|
cacheEverything: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,216 @@
|
|||||||
|
{
|
||||||
|
"main": "middleware.js",
|
||||||
|
"name": "gitbook-open-v2",
|
||||||
|
"compatibility_date": "2025-04-14",
|
||||||
|
"compatibility_flags": [
|
||||||
|
"nodejs_compat",
|
||||||
|
"allow_importable_env",
|
||||||
|
"global_fetch_strictly_public"
|
||||||
|
],
|
||||||
|
"assets": {
|
||||||
|
"directory": "../../.open-next/assets",
|
||||||
|
"binding": "ASSETS"
|
||||||
|
},
|
||||||
|
"observability": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"vars": {
|
||||||
|
"NEXT_CACHE_DO_QUEUE_DISABLE_SQLITE": "true"
|
||||||
|
},
|
||||||
|
"env": {
|
||||||
|
"dev": {
|
||||||
|
"vars": {
|
||||||
|
"STAGE": "dev",
|
||||||
|
"NEXT_PRIVATE_DEBUG_CACHE": "true"
|
||||||
|
},
|
||||||
|
"r2_buckets": [
|
||||||
|
{
|
||||||
|
"binding": "NEXT_INC_CACHE_R2_BUCKET",
|
||||||
|
"bucket_name": "gitbook-open-v2-cache-preview"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"services": [
|
||||||
|
{
|
||||||
|
"binding": "WORKER_SELF_REFERENCE",
|
||||||
|
"service": "gitbook-open-v2-dev"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"binding": "DEFAULT_WORKER",
|
||||||
|
"service": "gitbook-open-v2-server-dev"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"preview": {
|
||||||
|
"vars": {
|
||||||
|
"STAGE": "preview",
|
||||||
|
"PREVIEW_HOSTNAME": "TO_REPLACE",
|
||||||
|
"WORKER_VERSION_ID": "TO_REPLACE"
|
||||||
|
},
|
||||||
|
"r2_buckets": [
|
||||||
|
{
|
||||||
|
"binding": "NEXT_INC_CACHE_R2_BUCKET",
|
||||||
|
"bucket_name": "gitbook-open-v2-cache-preview"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"services": [
|
||||||
|
{
|
||||||
|
"binding": "WORKER_SELF_REFERENCE",
|
||||||
|
"service": "gitbook-open-v2-preview"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"binding": "DEFAULT_WORKER",
|
||||||
|
"service": "gitbook-open-v2-server-preview"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"durable_objects": {
|
||||||
|
"bindings": [
|
||||||
|
{
|
||||||
|
"name": "WRITE_BUFFER",
|
||||||
|
"class_name": "R2WriteBuffer",
|
||||||
|
"script_name": "gitbook-open-v2-do-preview"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "NEXT_TAG_CACHE_DO_SHARDED",
|
||||||
|
"class_name": "DOShardedTagCache",
|
||||||
|
"script_name": "gitbook-open-v2-do-preview"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "NEXT_CACHE_DO_QUEUE",
|
||||||
|
"class_name": "DOQueueHandler",
|
||||||
|
"script_name": "gitbook-open-v2-do-preview"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"staging": {
|
||||||
|
"vars": {
|
||||||
|
"STAGE": "staging",
|
||||||
|
"WORKER_VERSION_ID": "TO_REPLACE"
|
||||||
|
},
|
||||||
|
"routes": [
|
||||||
|
{
|
||||||
|
"pattern": "open-2c.gitbook-staging.com/*",
|
||||||
|
"zone_name": "gitbook-staging.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pattern": "static-2c.gitbook-staging.com/*",
|
||||||
|
"zone_name": "gitbook-staging.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"r2_buckets": [
|
||||||
|
{
|
||||||
|
"binding": "NEXT_INC_CACHE_R2_BUCKET",
|
||||||
|
"bucket_name": "gitbook-open-v2-cache-staging"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"services": [
|
||||||
|
{
|
||||||
|
"binding": "WORKER_SELF_REFERENCE",
|
||||||
|
"service": "gitbook-open-v2-staging"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"binding": "DEFAULT_WORKER",
|
||||||
|
"service": "gitbook-open-v2-server-staging"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"tail_consumers": [
|
||||||
|
{
|
||||||
|
"service": "gitbook-x-staging-tail"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"durable_objects": {
|
||||||
|
"bindings": [
|
||||||
|
{
|
||||||
|
"name": "WRITE_BUFFER",
|
||||||
|
"class_name": "R2WriteBuffer",
|
||||||
|
"script_name": "gitbook-open-v2-do-staging"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "NEXT_TAG_CACHE_DO_SHARDED",
|
||||||
|
"class_name": "DOShardedTagCache",
|
||||||
|
"script_name": "gitbook-open-v2-do-staging"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "NEXT_CACHE_DO_QUEUE",
|
||||||
|
"class_name": "DOQueueHandler",
|
||||||
|
"script_name": "gitbook-open-v2-do-staging"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"migrations": [
|
||||||
|
{
|
||||||
|
"tag": "v1",
|
||||||
|
"new_sqlite_classes": ["DOQueueHandler", "DOShardedTagCache"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"production": {
|
||||||
|
"vars": {
|
||||||
|
// This is a bit misleading, but it means that we can have 500 concurrent revalidations
|
||||||
|
// This means that we'll have up to 100 durable objects instance running at the same time
|
||||||
|
"MAX_REVALIDATE_CONCURRENCY": "100",
|
||||||
|
// Temporary variable to find the issue once deployed
|
||||||
|
// TODO: remove this once the issue is fixed
|
||||||
|
"DEBUG_CLOUDFLARE": "true",
|
||||||
|
"WORKER_VERSION_ID": "TO_REPLACE",
|
||||||
|
"STAGE": "production"
|
||||||
|
},
|
||||||
|
"routes": [
|
||||||
|
{
|
||||||
|
"pattern": "open-2c.gitbook.com/*",
|
||||||
|
"zone_name": "gitbook.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pattern": "static-2c.gitbook.com/*",
|
||||||
|
"zone_name": "gitbook.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"r2_buckets": [
|
||||||
|
{
|
||||||
|
"binding": "NEXT_INC_CACHE_R2_BUCKET",
|
||||||
|
"bucket_name": "gitbook-open-v2-cache-production"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"services": [
|
||||||
|
{
|
||||||
|
"binding": "WORKER_SELF_REFERENCE",
|
||||||
|
"service": "gitbook-open-v2-production"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"binding": "DEFAULT_WORKER",
|
||||||
|
"service": "gitbook-open-v2-server-production"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"tail_consumers": [
|
||||||
|
{
|
||||||
|
"service": "gitbook-x-prod-tail"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"durable_objects": {
|
||||||
|
"bindings": [
|
||||||
|
{
|
||||||
|
"name": "WRITE_BUFFER",
|
||||||
|
"class_name": "R2WriteBuffer",
|
||||||
|
"script_name": "gitbook-open-v2-do-production"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "NEXT_TAG_CACHE_DO_SHARDED",
|
||||||
|
"class_name": "DOShardedTagCache",
|
||||||
|
"script_name": "gitbook-open-v2-do-production"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "NEXT_CACHE_DO_QUEUE",
|
||||||
|
"class_name": "DOQueueHandler",
|
||||||
|
"script_name": "gitbook-open-v2-do-production"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"migrations": [
|
||||||
|
{
|
||||||
|
"tag": "v1",
|
||||||
|
"new_sqlite_classes": ["DOQueueHandler", "DOShardedTagCache"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
// In this script, we use the args from the cli to update the PREVIEW_URL vars in the wrangler config file for the middleware
|
||||||
|
import fs from 'node:fs';
|
||||||
|
import path from 'node:path';
|
||||||
|
|
||||||
|
const wranglerConfigPath = path.join(__dirname, '../middlewareWrangler.jsonc');
|
||||||
|
|
||||||
|
const file = fs.readFileSync(wranglerConfigPath, 'utf-8');
|
||||||
|
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
// The versionId is in the format xxx-xxx-xxx-xxx, we need the first part to reconstruct the preview URL
|
||||||
|
const versionId = args[0];
|
||||||
|
|
||||||
|
// The preview URL is in the format https://<versionId>-gitbook-open-v2-server-preview.gitbook.workers.dev
|
||||||
|
const previewHostname = `${versionId.split('-')[0]}-gitbook-open-v2-server-preview.gitbook.workers.dev`;
|
||||||
|
|
||||||
|
let updatedFile = file.replace(
|
||||||
|
/"PREVIEW_HOSTNAME": "TO_REPLACE"/,
|
||||||
|
`"PREVIEW_HOSTNAME": "${previewHostname}"`
|
||||||
|
);
|
||||||
|
|
||||||
|
updatedFile = updatedFile.replaceAll(
|
||||||
|
/"WORKER_VERSION_ID": "TO_REPLACE"/g,
|
||||||
|
`"WORKER_VERSION_ID": "${versionId}"`
|
||||||
|
);
|
||||||
|
|
||||||
|
fs.writeFileSync(wranglerConfigPath, updatedFile);
|
||||||
@@ -0,0 +1,217 @@
|
|||||||
|
import { createHash } from 'node:crypto';
|
||||||
|
|
||||||
|
import { trace } from '@/lib/tracing';
|
||||||
|
import type {
|
||||||
|
CacheEntryType,
|
||||||
|
CacheValue,
|
||||||
|
IncrementalCache,
|
||||||
|
WithLastModified,
|
||||||
|
} from '@opennextjs/aws/types/overrides.js';
|
||||||
|
import { getCloudflareContext } from '@opennextjs/cloudflare';
|
||||||
|
|
||||||
|
import type { DurableObjectNamespace, Rpc } from '@cloudflare/workers-types';
|
||||||
|
|
||||||
|
export const BINDING_NAME = 'NEXT_INC_CACHE_R2_BUCKET';
|
||||||
|
export const DEFAULT_PREFIX = 'incremental-cache';
|
||||||
|
|
||||||
|
export type KeyOptions = {
|
||||||
|
cacheType?: CacheEntryType;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* It is very similar to the `R2IncrementalCache` in the `@opennextjs/cloudflare` package, but it allow us to trace
|
||||||
|
* the cache operations. It also integrates both R2 and Cache API in a single class.
|
||||||
|
* Having our own, will allow us to customize it in the future if needed.
|
||||||
|
*/
|
||||||
|
class GitbookIncrementalCache implements IncrementalCache {
|
||||||
|
name = 'GitbookIncrementalCache';
|
||||||
|
|
||||||
|
protected localCache: Cache | undefined;
|
||||||
|
|
||||||
|
async get<CacheType extends CacheEntryType = 'cache'>(
|
||||||
|
key: string,
|
||||||
|
cacheType?: CacheType
|
||||||
|
): Promise<WithLastModified<CacheValue<CacheType>> | null> {
|
||||||
|
const cacheKey = this.getR2Key(key, cacheType);
|
||||||
|
return trace(
|
||||||
|
{
|
||||||
|
operation: 'openNextIncrementalCacheGet',
|
||||||
|
name: cacheKey,
|
||||||
|
},
|
||||||
|
async (span) => {
|
||||||
|
span.setAttribute('cacheType', cacheType ?? 'cache');
|
||||||
|
const r2 = getCloudflareContext().env[BINDING_NAME];
|
||||||
|
const localCache = await this.getCacheInstance();
|
||||||
|
if (!r2) throw new Error('No R2 bucket');
|
||||||
|
try {
|
||||||
|
// Check local cache first if available
|
||||||
|
const localCacheEntry = await localCache.match(this.getCacheUrlKey(cacheKey));
|
||||||
|
if (localCacheEntry) {
|
||||||
|
span.setAttribute('cacheHit', 'local');
|
||||||
|
const result = (await localCacheEntry.json()) as WithLastModified<
|
||||||
|
CacheValue<CacheType>
|
||||||
|
>;
|
||||||
|
return this.returnNullOn404(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
const r2Object = await r2.get(cacheKey);
|
||||||
|
if (!r2Object) return null;
|
||||||
|
|
||||||
|
span.setAttribute('cacheHit', 'r2');
|
||||||
|
return this.returnNullOn404({
|
||||||
|
value: await r2Object.json(),
|
||||||
|
lastModified: r2Object.uploaded.getTime(),
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to get from cache', e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: This is a workaround to handle 404 responses in the cache.
|
||||||
|
// It should be handled by OpenNext cache interception directly. This should be removed once OpenNext cache interception is fixed.
|
||||||
|
returnNullOn404<CacheType extends CacheEntryType = 'cache'>(
|
||||||
|
cacheEntry: WithLastModified<CacheValue<CacheType>> | null
|
||||||
|
): WithLastModified<CacheValue<CacheType>> | null {
|
||||||
|
if (!cacheEntry?.value) return null;
|
||||||
|
if ('meta' in cacheEntry.value && cacheEntry.value.meta?.status === 404) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return cacheEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
async set<CacheType extends CacheEntryType = 'cache'>(
|
||||||
|
key: string,
|
||||||
|
value: CacheValue<CacheType>,
|
||||||
|
cacheType?: CacheType
|
||||||
|
): Promise<void> {
|
||||||
|
const cacheKey = this.getR2Key(key, cacheType);
|
||||||
|
return trace(
|
||||||
|
{
|
||||||
|
operation: 'openNextIncrementalCacheSet',
|
||||||
|
name: cacheKey,
|
||||||
|
},
|
||||||
|
async (span) => {
|
||||||
|
span.setAttribute('cacheType', cacheType ?? 'cache');
|
||||||
|
const localCache = await this.getCacheInstance();
|
||||||
|
|
||||||
|
try {
|
||||||
|
await this.writeToR2(cacheKey, JSON.stringify(value));
|
||||||
|
|
||||||
|
//TODO: Check if there is any places where we don't have tags
|
||||||
|
// Ideally we should always have tags, but in case we don't, we need to decide how to handle it
|
||||||
|
// For now we default to a build ID tag, which allow us to invalidate the cache in case something is wrong in this deployment
|
||||||
|
const tags = this.getTagsFromCacheEntry(value) ?? [
|
||||||
|
`build_id/${process.env.NEXT_BUILD_ID}`,
|
||||||
|
];
|
||||||
|
|
||||||
|
// We consider R2 as the source of truth, so we update the local cache
|
||||||
|
// only after a successful R2 write
|
||||||
|
await localCache.put(
|
||||||
|
this.getCacheUrlKey(cacheKey),
|
||||||
|
new Response(
|
||||||
|
JSON.stringify({
|
||||||
|
value,
|
||||||
|
// Note: `Date.now()` returns the time of the last IO rather than the actual time.
|
||||||
|
// See https://developers.cloudflare.com/workers/reference/security-model/
|
||||||
|
lastModified: Date.now(),
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
// Cache-Control default to 30 minutes, will be overridden by `revalidate`
|
||||||
|
// In theory we should always get the `revalidate` value
|
||||||
|
'cache-control': `max-age=${value.revalidate ?? 60 * 30}`,
|
||||||
|
'cache-tag': tags.join(','),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to set to cache', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async delete(key: string): Promise<void> {
|
||||||
|
const cacheKey = this.getR2Key(key);
|
||||||
|
return trace(
|
||||||
|
{
|
||||||
|
operation: 'openNextIncrementalCacheDelete',
|
||||||
|
name: cacheKey,
|
||||||
|
},
|
||||||
|
async () => {
|
||||||
|
const r2 = getCloudflareContext().env[BINDING_NAME];
|
||||||
|
const localCache = await this.getCacheInstance();
|
||||||
|
if (!r2) throw new Error('No R2 bucket');
|
||||||
|
|
||||||
|
try {
|
||||||
|
await r2.delete(cacheKey);
|
||||||
|
|
||||||
|
// Here again R2 is the source of truth, so we delete from local cache first
|
||||||
|
await localCache.delete(this.getCacheUrlKey(cacheKey));
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to delete from cache', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async writeToR2(key: string, value: string): Promise<void> {
|
||||||
|
const env = getCloudflareContext().env as {
|
||||||
|
WRITE_BUFFER: DurableObjectNamespace<
|
||||||
|
Rpc.DurableObjectBranded & {
|
||||||
|
write: (key: string, value: string) => Promise<void>;
|
||||||
|
}
|
||||||
|
>;
|
||||||
|
};
|
||||||
|
const id = env.WRITE_BUFFER.idFromName(key);
|
||||||
|
|
||||||
|
// A stub is a client used to invoke methods on the Durable Object
|
||||||
|
const stub = env.WRITE_BUFFER.get(id);
|
||||||
|
|
||||||
|
await stub.write(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getCacheInstance(): Promise<Cache> {
|
||||||
|
if (this.localCache) return this.localCache;
|
||||||
|
this.localCache = await caches.open('incremental-cache');
|
||||||
|
return this.localCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Utility function to generate keys for R2/Cache API
|
||||||
|
getR2Key(key: string, cacheType: CacheEntryType = 'cache'): string {
|
||||||
|
const hash = createHash('sha256').update(key).digest('hex');
|
||||||
|
return `${DEFAULT_PREFIX}/${cacheType === 'cache' ? process.env?.NEXT_BUILD_ID : 'dataCache'}/${hash}.${cacheType}`.replace(
|
||||||
|
/\/+/g,
|
||||||
|
'/'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
getCacheUrlKey(cacheKey: string): string {
|
||||||
|
return `http://cache.local/${cacheKey}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
getTagsFromCacheEntry<CacheType extends CacheEntryType>(
|
||||||
|
entry: CacheValue<CacheType>
|
||||||
|
): string[] | undefined {
|
||||||
|
if ('tags' in entry && entry.tags) {
|
||||||
|
return entry.tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('meta' in entry && entry.meta && 'headers' in entry.meta && entry.meta.headers) {
|
||||||
|
const rawTags = entry.meta.headers['x-next-cache-tags'];
|
||||||
|
if (typeof rawTags === 'string') {
|
||||||
|
return rawTags.split(',');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ('value' in entry) {
|
||||||
|
return entry.tags;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new GitbookIncrementalCache();
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { trace } from '@/lib/tracing';
|
||||||
|
import type { Queue } from '@opennextjs/aws/types/overrides.js';
|
||||||
|
import { getCloudflareContext } from '@opennextjs/cloudflare';
|
||||||
|
import doQueue from '@opennextjs/cloudflare/overrides/queue/do-queue';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'GitbookISRQueue',
|
||||||
|
send: async (msg) => {
|
||||||
|
return trace({ operation: 'gitbookISRQueueSend', name: msg.MessageBody.url }, async () => {
|
||||||
|
const { ctx } = getCloudflareContext();
|
||||||
|
ctx.waitUntil(doQueue.send(msg));
|
||||||
|
});
|
||||||
|
},
|
||||||
|
} satisfies Queue;
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import type { Queue } from '@opennextjs/aws/types/overrides.js';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'GitbookISRQueue',
|
||||||
|
send: async (msg) => {
|
||||||
|
// We should never reach this point in the server. If that's the case, we should log it.
|
||||||
|
console.warn('GitbookISRQueue: send called on server side, this should not happen.', msg);
|
||||||
|
},
|
||||||
|
} satisfies Queue;
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
import { trace } from '@/lib/tracing';
|
||||||
|
import type { NextModeTagCache } from '@opennextjs/aws/types/overrides.js';
|
||||||
|
import doShardedTagCache from '@opennextjs/cloudflare/overrides/tag-cache/do-sharded-tag-cache';
|
||||||
|
import { softTagFilter } from '@opennextjs/cloudflare/overrides/tag-cache/tag-cache-filter';
|
||||||
|
|
||||||
|
const originalTagCache = doShardedTagCache({
|
||||||
|
baseShardSize: 12,
|
||||||
|
regionalCache: true,
|
||||||
|
// We can probably increase this value even further
|
||||||
|
regionalCacheTtlSec: 60,
|
||||||
|
shardReplication: {
|
||||||
|
numberOfSoftReplicas: 2,
|
||||||
|
numberOfHardReplicas: 1,
|
||||||
|
regionalReplication: {
|
||||||
|
defaultRegion: 'enam',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'GitbookTagCache',
|
||||||
|
mode: 'nextMode',
|
||||||
|
getLastRevalidated: async (tags: string[]) => {
|
||||||
|
const tagsToCheck = tags.filter(softTagFilter);
|
||||||
|
if (tagsToCheck.length === 0) {
|
||||||
|
// If we reach here, it probably means that there is an issue that we'll need to address.
|
||||||
|
console.warn(
|
||||||
|
'getLastRevalidated - No valid tags to check for last revalidation, original tags:',
|
||||||
|
tags
|
||||||
|
);
|
||||||
|
return 0; // If no tags to check, return 0
|
||||||
|
}
|
||||||
|
return trace(
|
||||||
|
{
|
||||||
|
operation: 'gitbookTagCacheGetLastRevalidated',
|
||||||
|
name: tagsToCheck.join(', '),
|
||||||
|
},
|
||||||
|
async () => {
|
||||||
|
return await originalTagCache.getLastRevalidated(tagsToCheck);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
hasBeenRevalidated: async (tags: string[], lastModified?: number) => {
|
||||||
|
const tagsToCheck = tags.filter(softTagFilter);
|
||||||
|
if (tagsToCheck.length === 0) {
|
||||||
|
// If we reach here, it probably means that there is an issue that we'll need to address.
|
||||||
|
console.warn(
|
||||||
|
'hasBeenRevalidated - No valid tags to check for revalidation, original tags:',
|
||||||
|
tags
|
||||||
|
);
|
||||||
|
return false; // If no tags to check, return false
|
||||||
|
}
|
||||||
|
return trace(
|
||||||
|
{
|
||||||
|
operation: 'gitbookTagCacheHasBeenRevalidated',
|
||||||
|
name: tagsToCheck.join(', '),
|
||||||
|
},
|
||||||
|
async () => {
|
||||||
|
const result = await originalTagCache.hasBeenRevalidated(tagsToCheck, lastModified);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
writeTags: async (tags: string[]) => {
|
||||||
|
return trace(
|
||||||
|
{
|
||||||
|
operation: 'gitbookTagCacheWriteTags',
|
||||||
|
name: tags.join(', '),
|
||||||
|
},
|
||||||
|
async () => {
|
||||||
|
const tagsToWrite = tags.filter(softTagFilter);
|
||||||
|
if (tagsToWrite.length === 0) {
|
||||||
|
console.warn('writeTags - No valid tags to write');
|
||||||
|
return; // If no tags to write, exit early
|
||||||
|
}
|
||||||
|
// Write only the filtered tags
|
||||||
|
await originalTagCache.writeTags(tagsToWrite);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
} satisfies NextModeTagCache;
|
||||||
@@ -1,23 +1,24 @@
|
|||||||
{
|
{
|
||||||
"name": "gitbook-v2",
|
"name": "gitbook-v2",
|
||||||
"version": "0.2.3",
|
"version": "0.3.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"next": "^15.2.3",
|
"@gitbook/api": "catalog:",
|
||||||
|
"@gitbook/cache-tags": "workspace:*",
|
||||||
|
"@opennextjs/cloudflare": "1.2.1",
|
||||||
|
"@sindresorhus/fnv1a": "^3.1.0",
|
||||||
|
"assert-never": "^1.2.1",
|
||||||
|
"jwt-decode": "^4.0.0",
|
||||||
|
"next": "^15.3.2",
|
||||||
"react": "^19.0.0",
|
"react": "^19.0.0",
|
||||||
"react-dom": "^19.0.0",
|
"react-dom": "^19.0.0",
|
||||||
"@gitbook/api": "*",
|
"rison": "^0.1.1",
|
||||||
"@gitbook/cache-tags": "workspace:*",
|
|
||||||
"@sindresorhus/fnv1a": "^3.1.0",
|
|
||||||
"server-only": "^0.0.1",
|
"server-only": "^0.0.1",
|
||||||
"warn-once": "^0.1.1",
|
"warn-once": "^0.1.1",
|
||||||
"rison": "^0.1.1",
|
"object-identity": "^0.1.2"
|
||||||
"jwt-decode": "^4.0.0",
|
|
||||||
"p-memoize": "^7.1.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"gitbook": "*",
|
"gitbook": "*",
|
||||||
"@opennextjs/cloudflare": "^0.5.10",
|
|
||||||
"@types/rison": "^0.0.9",
|
"@types/rison": "^0.0.9",
|
||||||
"tailwindcss": "^3.4.0",
|
"tailwindcss": "^3.4.0",
|
||||||
"postcss": "^8"
|
"postcss": "^8"
|
||||||
@@ -28,8 +29,10 @@
|
|||||||
"build": "next build",
|
"build": "next build",
|
||||||
"build:v2": "next build",
|
"build:v2": "next build",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
"build:v2:cloudflare": "opennextjs-cloudflare",
|
"build:v2:cloudflare": "opennextjs-cloudflare build",
|
||||||
"dev:v2:cloudflare": "wrangler dev --port 8771",
|
"dev:v2:cloudflare": "wrangler dev --port 8771 --env preview",
|
||||||
|
"dev:v2:cf:middleware": "wrangler dev --port 8771 --inspector-port 9230 --env dev --config ./openNext/customWorkers/middlewareWrangler.jsonc",
|
||||||
|
"dev:v2:cf:server": "wrangler dev --port 8772 --env dev --config ./openNext/customWorkers/defaultWrangler.jsonc",
|
||||||
"unit": "bun test",
|
"unit": "bun test",
|
||||||
"typecheck": "tsc --noEmit"
|
"typecheck": "tsc --noEmit"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import NextError from 'next/error';
|
||||||
|
|
||||||
|
export default function GlobalError({
|
||||||
|
error,
|
||||||
|
}: {
|
||||||
|
error: Error & { digest?: string };
|
||||||
|
}) {
|
||||||
|
console.error('Global error:', error);
|
||||||
|
return (
|
||||||
|
<html lang="en">
|
||||||
|
<body>
|
||||||
|
<NextError statusCode={undefined as any} />
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
);
|
||||||
|
}
|
||||||
+1
-11
@@ -3,10 +3,9 @@ import {
|
|||||||
generateSitePageMetadata,
|
generateSitePageMetadata,
|
||||||
generateSitePageViewport,
|
generateSitePageViewport,
|
||||||
} from '@/components/SitePage';
|
} from '@/components/SitePage';
|
||||||
import { getCacheTag } from '@gitbook/cache-tags';
|
|
||||||
import { type RouteParams, getPagePathFromParams, getStaticSiteContext } from '@v2/app/utils';
|
import { type RouteParams, getPagePathFromParams, getStaticSiteContext } from '@v2/app/utils';
|
||||||
|
|
||||||
import type { Metadata, Viewport } from 'next';
|
import type { Metadata, Viewport } from 'next';
|
||||||
import { unstable_cacheTag as cacheTag } from 'next/cache';
|
|
||||||
|
|
||||||
export const dynamic = 'force-static';
|
export const dynamic = 'force-static';
|
||||||
|
|
||||||
@@ -15,19 +14,10 @@ type PageProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default async function Page(props: PageProps) {
|
export default async function Page(props: PageProps) {
|
||||||
'use cache';
|
|
||||||
|
|
||||||
const params = await props.params;
|
const params = await props.params;
|
||||||
const { context } = await getStaticSiteContext(params);
|
const { context } = await getStaticSiteContext(params);
|
||||||
const pathname = getPagePathFromParams(params);
|
const pathname = getPagePathFromParams(params);
|
||||||
|
|
||||||
cacheTag(
|
|
||||||
getCacheTag({
|
|
||||||
tag: 'site',
|
|
||||||
site: context.site.id,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
return <SitePage context={context} pageParams={{ pathname }} />;
|
return <SitePage context={context} pageParams={{ pathname }} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,8 @@ import {
|
|||||||
generateSiteLayoutMetadata,
|
generateSiteLayoutMetadata,
|
||||||
generateSiteLayoutViewport,
|
generateSiteLayoutViewport,
|
||||||
} from '@/components/SiteLayout';
|
} from '@/components/SiteLayout';
|
||||||
import { getCacheTag } from '@gitbook/cache-tags';
|
|
||||||
import { type RouteLayoutParams, getStaticSiteContext } from '@v2/app/utils';
|
import { type RouteLayoutParams, getStaticSiteContext } from '@v2/app/utils';
|
||||||
import { GITBOOK_DISABLE_TRACKING } from '@v2/lib/env';
|
import { GITBOOK_DISABLE_TRACKING } from '@v2/lib/env';
|
||||||
import { unstable_cacheTag as cacheTag } from 'next/cache';
|
|
||||||
|
|
||||||
interface SiteStaticLayoutProps {
|
interface SiteStaticLayoutProps {
|
||||||
params: Promise<RouteLayoutParams>;
|
params: Promise<RouteLayoutParams>;
|
||||||
@@ -17,17 +15,8 @@ export default async function SiteStaticLayout({
|
|||||||
params,
|
params,
|
||||||
children,
|
children,
|
||||||
}: React.PropsWithChildren<SiteStaticLayoutProps>) {
|
}: React.PropsWithChildren<SiteStaticLayoutProps>) {
|
||||||
'use cache';
|
|
||||||
|
|
||||||
const { context, visitorAuthClaims } = await getStaticSiteContext(await params);
|
const { context, visitorAuthClaims } = await getStaticSiteContext(await params);
|
||||||
|
|
||||||
cacheTag(
|
|
||||||
getCacheTag({
|
|
||||||
tag: 'site',
|
|
||||||
site: context.site.id,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CustomizationRootLayout customization={context.customization}>
|
<CustomizationRootLayout customization={context.customization}>
|
||||||
<SiteLayout
|
<SiteLayout
|
||||||
|
|||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
import type { NextRequest } from 'next/server';
|
||||||
|
|
||||||
|
import { serveLLMsFullTxt } from '@/routes/llms-full';
|
||||||
|
import { type RouteLayoutParams, getStaticSiteContext } from '@v2/app/utils';
|
||||||
|
|
||||||
|
export const dynamic = 'force-static';
|
||||||
|
|
||||||
|
export async function GET(
|
||||||
|
_request: NextRequest,
|
||||||
|
{ params }: { params: Promise<RouteLayoutParams> }
|
||||||
|
) {
|
||||||
|
const { context } = await getStaticSiteContext(await params);
|
||||||
|
return serveLLMsFullTxt(context);
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import { getVisitorAuthClaims, getVisitorAuthClaimsFromToken } from '@/lib/adaptive';
|
import { getVisitorAuthClaims, getVisitorAuthClaimsFromToken } from '@/lib/adaptive';
|
||||||
|
import { getDynamicCustomizationSettings } from '@/lib/customization';
|
||||||
import type { SiteAPIToken } from '@gitbook/api';
|
import type { SiteAPIToken } from '@gitbook/api';
|
||||||
import { type SiteURLData, fetchSiteContextByURLLookup, getBaseContext } from '@v2/lib/context';
|
import { type SiteURLData, fetchSiteContextByURLLookup, getBaseContext } from '@v2/lib/context';
|
||||||
import { jwtDecode } from 'jwt-decode';
|
import { jwtDecode } from 'jwt-decode';
|
||||||
@@ -67,6 +68,8 @@ export async function getDynamicSiteContext(params: RouteLayoutParams) {
|
|||||||
siteURLData
|
siteURLData
|
||||||
);
|
);
|
||||||
|
|
||||||
|
context.customization = await getDynamicCustomizationSettings(context.customization);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
context,
|
context,
|
||||||
visitorAuthClaims: getVisitorAuthClaims(siteURLData),
|
visitorAuthClaims: getVisitorAuthClaims(siteURLData),
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user