mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-12 22:09:04 +00:00
Compare commits
201 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f64d5073d4 | |||
| 53b9f10ac8 | |||
| 75606e4df7 | |||
| 0643b7f351 | |||
| 5b3b4e0614 | |||
| 8d039d1348 | |||
| 87eea73081 | |||
| 67a6fb4c87 | |||
| 23584c9862 | |||
| 2f767125c4 | |||
| c73e07d42d | |||
| 6b5d7e6057 | |||
| 076dc48e89 | |||
| bb208ab36a | |||
| 60e35001b6 | |||
| 29a0d7ea02 | |||
| 1f2b7f7acf | |||
| 39e5cb63ef | |||
| 5b5928fb8d | |||
| 08068743a5 | |||
| 35eae1adcf | |||
| e85d357abd | |||
| 31396d8109 | |||
| 664debc0bc | |||
| 56c31c76b3 | |||
| 2d1a71f3d1 | |||
| c67cd73058 | |||
| 2572cb4352 | |||
| c9f6c7ccac | |||
| b6520b0dbc | |||
| 9fe8142117 | |||
| 57cdd25b5f | |||
| 1005ee5d52 | |||
| d9bb9f9a07 | |||
| 75a6fabe61 | |||
| 75e29b69cc | |||
| ffd3937538 | |||
| 575587e4c5 | |||
| 2ce59d7c92 | |||
| 3b3d6e2a73 | |||
| f2a467fdbf | |||
| 867481c66d | |||
| fc8065b7a8 | |||
| 28f1ed9205 | |||
| 568266bc9a | |||
| 7739f341b8 | |||
| 2b501f191c | |||
| aa2ed0fda1 | |||
| 51cba074d7 | |||
| 2c945c663c | |||
| d9a18ecabb | |||
| eab7931afb | |||
| 99b6c92377 | |||
| 4d56f1163b | |||
| 07cf835551 | |||
| 061c0c1a90 | |||
| 1ed18c05ef | |||
| ca134c8a60 | |||
| 7ba67fd852 | |||
| 7675c2c411 | |||
| 7c71363af8 | |||
| d48926eb2a | |||
| d843e5e06f | |||
| a2e564738e | |||
| 54a797a0b1 | |||
| a78c1ecb4d | |||
| 4771c78001 | |||
| b7a5106f36 | |||
| 4bcbdc50ff | |||
| 5d72b35c7f | |||
| ff50ac215c | |||
| 3fe3809416 | |||
| 363d337a72 | |||
| f89b31c940 | |||
| 630c3e84dd | |||
| d43202f137 | |||
| 0964043489 | |||
| e9b31a545d | |||
| 7f28a88374 | |||
| 07ea45bf84 | |||
| a86d35f721 | |||
| d6c28a0ff6 | |||
| a7af3ca7bc | |||
| cda08a9843 | |||
| 7588774237 | |||
| 683373b263 | |||
| 673ec8fb5d | |||
| 63bacaa671 | |||
| e3a3d6a505 | |||
| 175171dda1 | |||
| a4b63b88c8 | |||
| c3675fdfe7 | |||
| 2fa08519b6 | |||
| 065627060b | |||
| 2982b6a808 | |||
| c3f56ecd40 | |||
| fe9e6c1afd | |||
| 73394ae929 | |||
| c754fc9ff4 | |||
| 1ca6208057 | |||
| cdfae4d4df | |||
| c3da5469ca | |||
| 79f2d8ba76 | |||
| 7b1bdb92a6 | |||
| f9a075eed1 | |||
| 32e4193557 | |||
| 133c3e7c0a | |||
| 6ce3cea682 | |||
| 250e77d18b | |||
| e3bfe006e9 | |||
| 76aeecdc68 | |||
| 15d2ee3e76 | |||
| b066db479f | |||
| a69ff2789a | |||
| 4df235d64a | |||
| 11524457e3 | |||
| 8f7364293e | |||
| 56f5fa1fbe | |||
| b075f0f7e9 | |||
| 0ca32afe8d | |||
| 32c2f257a9 | |||
| a7066ccbe1 | |||
| 09248e0efe | |||
| e2ef22fc5f | |||
| 75f825e4f8 | |||
| 9b8d5198e4 | |||
| e09f747727 | |||
| 16e6171750 | |||
| f885e887ea | |||
| 5096f7fbc5 | |||
| f16560c1ee | |||
| d0f4860759 | |||
| 34d36c6de1 | |||
| 042b850b5d | |||
| 73892f4fc2 | |||
| 636b868bf1 | |||
| b144368e3f | |||
| 683b4193d1 | |||
| f4c953665a | |||
| 0f990c772a | |||
| 0bf985af61 | |||
| 42473611d3 | |||
| 2c437f7d94 | |||
| aa8c49eb0c | |||
| b32e40c72a | |||
| 2ff7ed1b52 | |||
| bfbed1a69b | |||
| ef9d012be9 | |||
| f12a2155c0 | |||
| 43f696c4a8 | |||
| 4c19014dcd | |||
| 0e7f9d6778 | |||
| 00a0bf3c1b | |||
| e9149036f6 | |||
| b6a9967959 | |||
| 8bbc3caf3e | |||
| 237b703a6c | |||
| cf3045a718 | |||
| a679e7283f | |||
| 13c75341e2 | |||
| 4cbcc5bb20 | |||
| 51955dae3b | |||
| 51fa3ab2c8 | |||
| af9e66e87e | |||
| 8878dc7f80 | |||
| 4336bc20e0 | |||
| 4a7613a521 | |||
| 689f55340f | |||
| 160ae3d49d | |||
| c079c3c6d9 | |||
| cb782a7557 | |||
| 502d8fc087 | |||
| 6295881138 | |||
| 17f71ba680 | |||
| 5fe7adb87b | |||
| 41684d091b | |||
| 9f6c3347cb | |||
| aa321989c4 | |||
| 0f1565cb4b | |||
| 3996110ebd | |||
| 3422ad4c84 | |||
| 3c07e65b9a | |||
| 287df91661 | |||
| 776bc3135a | |||
| 4638958c9f | |||
| 1f24fe46c4 | |||
| ccbcab8822 | |||
| 094e9cdac2 | |||
| 5c35f36b3a | |||
| d7ec2b57a4 | |||
| 373a1e0312 | |||
| e9fe3975bb | |||
| 32a73b55d4 | |||
| 0426312d6c | |||
| ede2335fb3 | |||
| 709f1a1ccb | |||
| 24b785cbfb | |||
| acc3f2f418 | |||
| d4a653d6a9 | |||
| 7e74d25447 | |||
| 3445db41ce |
+21
-7
@@ -1,6 +1,8 @@
|
|||||||
# Welcome to GitBook's contributing guide!
|
# Welcome to GitBook's contributing guide!
|
||||||
|
|
||||||
Thank you for investing your time in contributing to GitBook. Any contribution you make will be reviewed by our team.In this guide, you'll learn the different ways you can contribute.
|
> _For help, support, feature requests, and product questions - head to our [GitHub Community](https://github.com/orgs/GitbookIO/discussions) 🤖_
|
||||||
|
|
||||||
|
Thank you for investing your time in contributing to GitBook. Any contribution you make will be reviewed by our team. In this guide, you'll learn the different ways you can contribute.
|
||||||
|
|
||||||
## Types of Contributions
|
## Types of Contributions
|
||||||
|
|
||||||
@@ -45,13 +47,25 @@ Any contribution you make can be made to the code located in this repository. In
|
|||||||
|
|
||||||
- [Fork the repo](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo#fork-an-example-repository) so that you can make your changes without affecting the original project until you're ready to merge them.
|
- [Fork the repo](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo#fork-an-example-repository) so that you can make your changes without affecting the original project until you're ready to merge them.
|
||||||
|
|
||||||
##### GitHub Codespaces:
|
|
||||||
|
|
||||||
- [Fork, edit, and preview](https://docs.github.com/en/free-pro-team@latest/github/developing-online-with-codespaces/creating-a-codespace) using [GitHub Codespaces](https://github.com/features/codespaces) without having to install and run the project locally.
|
|
||||||
|
|
||||||
#### 2. Create a working branch and start with your changes
|
#### 2. Create a working branch and start with your changes
|
||||||
|
|
||||||
After forking this repository, you'll want to [create a branch](https://docs.github.com/en/issues/tracking-your-work-with-issues/creating-a-branch-for-an-issue) to work off of. After creating the branch, you can start making changes!
|
After forking this repository, you'll want to [create a branch](https://docs.github.com/en/issues/tracking-your-work-with-issues/creating-a-branch-for-an-issue) to work off of.
|
||||||
|
|
||||||
|
#### 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.
|
||||||
|
|
||||||
|
You can easily do this by running the command `nvm use`.
|
||||||
|
|
||||||
|
To start your local version of GitBook, run the command `bun dev`.
|
||||||
|
|
||||||
|
#### 4. Preview your changes
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
### Commit your update
|
### Commit your update
|
||||||
|
|
||||||
@@ -71,4 +85,4 @@ When you're finished with the changes, [create a pull request](https://docs.gith
|
|||||||
|
|
||||||
### Your PR is merged
|
### Your PR is merged
|
||||||
|
|
||||||
Congratulations 🎉Thank you for your contribution! Once your PR is merged, your contributions will be publicly visible on the relevant repository.
|
Congratulations 🎉 Thank you for your contribution! Once your PR is merged, your contributions will be publicly visible on the relevant repository.
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ runs:
|
|||||||
- name: 🏗 Prepare Playwright env
|
- name: 🏗 Prepare Playwright env
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
PLAYWRIGHT_VERSION=$(npm ls --json @playwright/test | jq --raw-output '.dependencies["@playwright/test"].version')
|
PLAYWRIGHT_VERSION=$(npm ls --json @playwright/test | jq --raw-output '.dependencies["gitbook"].dependencies["@playwright/test"].version')
|
||||||
echo "PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION" >> $GITHUB_ENV
|
echo "PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION" >> $GITHUB_ENV
|
||||||
|
|
||||||
# Cache browser binaries, cache key is based on Playwright version and OS
|
# Cache browser binaries, cache key is based on Playwright version and OS
|
||||||
- name: 🧰 Cache Playwright browser binaries
|
- name: 🧰 Cache Playwright browser binaries
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v4
|
||||||
id: playwright-cache
|
id: playwright-cache
|
||||||
with:
|
with:
|
||||||
path: '~/.cache/ms-playwright'
|
path: '~/.cache/ms-playwright'
|
||||||
@@ -24,6 +24,7 @@ runs:
|
|||||||
- name: 🏗 Install Playwright browser binaries & OS dependencies
|
- name: 🏗 Install Playwright browser binaries & OS dependencies
|
||||||
if: steps.playwright-cache.outputs.cache-hit != 'true'
|
if: steps.playwright-cache.outputs.cache-hit != 'true'
|
||||||
shell: bash
|
shell: bash
|
||||||
|
working-directory: packages/gitbook
|
||||||
run: |
|
run: |
|
||||||
bun x playwright install --with-deps chromium
|
bun x playwright install --with-deps chromium
|
||||||
|
|
||||||
@@ -31,5 +32,6 @@ runs:
|
|||||||
- name: 🏗 Install Playwright OS dependencies
|
- name: 🏗 Install Playwright OS dependencies
|
||||||
if: steps.playwright-cache.outputs.cache-hit == 'true'
|
if: steps.playwright-cache.outputs.cache-hit == 'true'
|
||||||
shell: bash
|
shell: bash
|
||||||
|
working-directory: packages/gitbook
|
||||||
run: |
|
run: |
|
||||||
bun x playwright install-deps
|
bun x playwright install-deps
|
||||||
|
|||||||
+69
-22
@@ -4,7 +4,8 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
env:
|
||||||
|
NPMRC_FONT_AWESOME_TOKEN: ${{ secrets.NPMRC_FONT_AWESOME_TOKEN }}
|
||||||
jobs:
|
jobs:
|
||||||
deploy:
|
deploy:
|
||||||
name: Deploy to Cloudflare Pages
|
name: Deploy to Cloudflare Pages
|
||||||
@@ -12,8 +13,12 @@ jobs:
|
|||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
deployments: write
|
deployments: write
|
||||||
|
issues: write
|
||||||
|
pull-requests: write
|
||||||
|
checks: write
|
||||||
|
statuses: write
|
||||||
outputs:
|
outputs:
|
||||||
deployment_url: ${{ steps.cloudflare.outputs.url }}
|
deployment_url: ${{ steps.deploy.outputs.deployment-url }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -25,16 +30,6 @@ jobs:
|
|||||||
run: bun install --frozen-lockfile
|
run: bun install --frozen-lockfile
|
||||||
env:
|
env:
|
||||||
PUPPETEER_SKIP_DOWNLOAD: 1
|
PUPPETEER_SKIP_DOWNLOAD: 1
|
||||||
- name: Cache Next.js build
|
|
||||||
uses: actions/cache@v3
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
${{ github.workspace }}/.next/cache
|
|
||||||
# Generate a new cache whenever packages or source files change.
|
|
||||||
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/bun.lockb') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
|
|
||||||
# If source files changed but packages didn't, rebuild from a prior cache.
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-nextjs-${{ hashFiles('**/bun.lockb') }}-
|
|
||||||
- name: Sets env vars for production
|
- name: Sets env vars for production
|
||||||
run: |
|
run: |
|
||||||
echo "SENTRY_ENVIRONMENT=production" >> $GITHUB_ENV
|
echo "SENTRY_ENVIRONMENT=production" >> $GITHUB_ENV
|
||||||
@@ -51,27 +46,55 @@ jobs:
|
|||||||
SENTRY_ORG: ${{ vars.SENTRY_ORG }}
|
SENTRY_ORG: ${{ vars.SENTRY_ORG }}
|
||||||
SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }}
|
SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }}
|
||||||
SENTRY_DSN: ${{ vars.SENTRY_DSN }}
|
SENTRY_DSN: ${{ vars.SENTRY_DSN }}
|
||||||
- id: cloudflare
|
- id: deploy
|
||||||
name: Publish to Cloudflare Pages
|
name: Deploy to Cloudflare
|
||||||
uses: cloudflare/pages-action@v1
|
uses: cloudflare/wrangler-action@v3.11.0
|
||||||
with:
|
with:
|
||||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
projectName: ${{ vars.CLOUDFLARE_PROJECT_NAME }}
|
|
||||||
directory: ./packages/gitbook/.vercel/output/static
|
|
||||||
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
workingDirectory: ./
|
workingDirectory: ./
|
||||||
|
wranglerVersion: '3.82.0'
|
||||||
|
command: pages deploy ./packages/gitbook/.vercel/output/static --project-name=${{ vars.CLOUDFLARE_PROJECT_NAME }} --branch=${{ github.ref == 'refs/heads/main' && 'main' || format('pr{0}', github.event.pull_request.number) }}
|
||||||
- name: Outputs
|
- name: Outputs
|
||||||
run: |
|
run: |
|
||||||
echo "ID: ${{ steps.cloudflare.outputs.id }}"
|
echo "URL: ${{ steps.deploy.outputs.deployment-url }}"
|
||||||
echo "URL: ${{ steps.cloudflare.outputs.url }}"
|
echo "Alias URL: ${{ steps.deploy.outputs.deployment-alias-url }}"
|
||||||
echo "Environment: ${{ steps.cloudflare.outputs.environment }}"
|
|
||||||
echo "Alias: ${{ steps.cloudflare.outputs.alias }}"
|
|
||||||
- name: Archive build output
|
- name: Archive build output
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: build-output
|
name: build-output
|
||||||
path: .vercel/
|
path: .vercel/
|
||||||
|
# Until https://github.com/cloudflare/wrangler-action/issues/301 is done
|
||||||
|
- name: Update Deployment Status to Success
|
||||||
|
env:
|
||||||
|
DEPLOYMENT_URL: ${{ steps.deploy.outputs.deployment-url }}
|
||||||
|
run: |
|
||||||
|
curl -X POST \
|
||||||
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||||
|
-H "Accept: application/vnd.github.v3+json" \
|
||||||
|
-d '{"state": "success", "target_url": "${{ steps.deploy.outputs.deployment-url }}", "description": "Deployed Preview URL for commit", "context": "cloudflare/preview"}' \
|
||||||
|
https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }}
|
||||||
|
|
||||||
|
- name: Find GitHub Comment
|
||||||
|
uses: peter-evans/find-comment@v3
|
||||||
|
id: fc
|
||||||
|
if: 1 && !startsWith(github.ref, 'refs/heads/main')
|
||||||
|
with:
|
||||||
|
issue-number: ${{ github.event.pull_request.number }}
|
||||||
|
comment-author: 'github-actions[bot]'
|
||||||
|
body-includes: GitBook Preview
|
||||||
|
|
||||||
|
- name: Create or update GitHub comment
|
||||||
|
uses: peter-evans/create-or-update-comment@v4
|
||||||
|
if: 1 && !startsWith(github.ref, 'refs/heads/main')
|
||||||
|
with:
|
||||||
|
comment-id: ${{ steps.fc.outputs.comment-id }}
|
||||||
|
issue-number: ${{ github.event.pull_request.number }}
|
||||||
|
body: |
|
||||||
|
**GitBook Preview**
|
||||||
|
Latest commit: [${{ steps.deploy.outputs.deployment-url }}](${{ steps.deploy.outputs.deployment-url }})
|
||||||
|
PR: [${{ steps.deploy.outputs.deployment-alias-url }}](${{ steps.deploy.outputs.deployment-alias-url }})
|
||||||
|
edit-mode: replace
|
||||||
visual-testing:
|
visual-testing:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
name: Visual Testing
|
name: Visual Testing
|
||||||
@@ -92,6 +115,12 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
BASE_URL: ${{needs.deploy.outputs.deployment_url}}
|
BASE_URL: ${{needs.deploy.outputs.deployment_url}}
|
||||||
ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }}
|
ARGOS_TOKEN: ${{ secrets.ARGOS_TOKEN }}
|
||||||
|
- uses: actions/upload-artifact@v4
|
||||||
|
if: ${{ !cancelled() }}
|
||||||
|
with:
|
||||||
|
name: playwright-test-results
|
||||||
|
path: packages/gitbook/test-results/
|
||||||
|
retention-days: 3
|
||||||
pagespeed-testing:
|
pagespeed-testing:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
name: PageSpeed Testing
|
name: PageSpeed Testing
|
||||||
@@ -157,6 +186,24 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
PUPPETEER_SKIP_DOWNLOAD: 1
|
PUPPETEER_SKIP_DOWNLOAD: 1
|
||||||
- run: bun unit
|
- run: bun unit
|
||||||
|
build-oss:
|
||||||
|
# CI to check that the repository builds correctly on a machine without the credentials
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
name: Build (Open Source)
|
||||||
|
env:
|
||||||
|
NPMRC_FONT_AWESOME_TOKEN: ''
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Setup bun
|
||||||
|
uses: oven-sh/setup-bun@v1
|
||||||
|
with:
|
||||||
|
bun-version: 1.1.18
|
||||||
|
- name: Install dependencies
|
||||||
|
run: bun install --frozen-lockfile
|
||||||
|
env:
|
||||||
|
PUPPETEER_SKIP_DOWNLOAD: 1
|
||||||
|
- run: bun run build
|
||||||
typecheck:
|
typecheck:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
name: Typecheck
|
name: Typecheck
|
||||||
|
|||||||
@@ -35,3 +35,26 @@ jobs:
|
|||||||
# https://github.com/orgs/community/discussions/26875#discussioncomment-3253761
|
# https://github.com/orgs/community/discussions/26875#discussioncomment-3253761
|
||||||
GITHUB_TOKEN: ${{ secrets.GH_PERSONAL_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GH_PERSONAL_TOKEN }}
|
||||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
|
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
|
release-preview:
|
||||||
|
# For now it releases the cache-do to both preview and production
|
||||||
|
# Once we changed to deploy the app only on release, we should change `release:preview` in `cache-do`
|
||||||
|
name: Release Preview
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout Repo
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Setup bun
|
||||||
|
uses: oven-sh/setup-bun@v1
|
||||||
|
with:
|
||||||
|
bun-version: 1.1.18
|
||||||
|
- name: Install dependencies
|
||||||
|
run: bun install --frozen-lockfile
|
||||||
|
env:
|
||||||
|
PUPPETEER_SKIP_DOWNLOAD: 1
|
||||||
|
- name: Release preview packages
|
||||||
|
run: bun run release:preview
|
||||||
|
env:
|
||||||
|
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
|
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
|
|||||||
@@ -20,3 +20,5 @@ yarn-error.log*
|
|||||||
# Vercel
|
# Vercel
|
||||||
.vercel
|
.vercel
|
||||||
|
|
||||||
|
# Env files
|
||||||
|
.env.local
|
||||||
|
|||||||
@@ -4,3 +4,7 @@
|
|||||||
# Generated
|
# Generated
|
||||||
packages/emoji-codepoints/index.ts
|
packages/emoji-codepoints/index.ts
|
||||||
packages/gitbook/public/~gitbook/static/
|
packages/gitbook/public/~gitbook/static/
|
||||||
|
packages/icons/src/data/*.json
|
||||||
|
|
||||||
|
# Build files
|
||||||
|
dist/
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://gitbook.com"><img src="https://img.shields.io/static/v1?message=Documented%20on%20GitBook&logo=data:image/svg%2bxml;base64,PHN2ZyB3aWR0aD0iNjUiIGhlaWdodD0iNjUiIHZpZXdCb3g9IjAgMCA2NSA2NSIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTI3LjM5NjQgMzMuNjc2NEMzMC41MjU1IDM1LjQ4MjQgMzIuMDkgMzYuMzg1NCAzMy44MDgzIDM2LjM4NjlDMzUuNTI2NSAzNi4zODg0IDM3LjA5MjYgMzUuNDg4MiA0MC4yMjQ5IDMzLjY4NzdMNjAuMTkxNCAyMi4yMTA0QzYxLjA5MjcgMjEuNjkyMiA2MS42NDg0IDIwLjczMTggNjEuNjQ4NCAxOS42OTIxQzYxLjY0ODQgMTguNjUyNCA2MS4wOTI3IDE3LjY5MiA2MC4xOTE0IDE3LjE3MzlMNDAuMjE3NyA1LjY5MjQ1QzM3LjA4ODggMy44OTM4NiAzNS41MjQzIDIuOTk0NTcgMzMuODA3OCAyLjk5NTI0QzMyLjA5MTIgMi45OTU5MSAzMC41Mjc1IDMuODk2NDIgMjcuNCA1LjY5NzQ0TDEwLjIyOTMgMTUuNTg1NUMxMC4xMDIgMTUuNjU4OCAxMC4wMzg0IDE1LjY5NTQgOS45NzkwOCAxNS43MzAxQzQuMTEzNzEgMTkuMTYzNyAwLjQ4OTg5MiAyNS40MzIzIDAuNDQxNDM4IDMyLjIyODZDMC40NDA5NDggMzIuMjk3MyAwLjQ0MDk0OCAzMi4zNzA4IDAuNDQwOTQ4IDMyLjUxNzZDMC40NDA5NDggMzIuNjY0MyAwLjQ0MDk0OCAzMi43Mzc2IDAuNDQxNDM3IDMyLjgwNjNDMC40ODk3ODUgMzkuNTk0OSA0LjEwNTUyIDQ1Ljg1NzcgOS45NjA0NCA0OS4yOTRDMTAuMDE5NiA0OS4zMjg3IDEwLjA4MzIgNDkuMzY1NCAxMC4yMTAyIDQ5LjQzODdMMjAuOTY1OSA1NS42NDg3QzI3LjIzMzIgNTkuMjY3MyAzMC4zNjY4IDYxLjA3NjYgMzMuODA4MSA2MS4wNzc3QzM3LjI0OTMgNjEuMDc4OSA0MC4zODQyIDU5LjI3MTcgNDYuNjUzOSA1NS42NTc0TDU4LjAwOCA0OS4xMTIxQzYxLjE0NzQgNDcuMzAyMyA2Mi43MTcxIDQ2LjM5NzQgNjMuNTc5IDQ0LjkwNTZDNjQuNDQwOSA0My40MTM5IDY0LjQ0MDkgNDEuNjAyIDY0LjQ0MDkgMzcuOTc4NFYzMC45NzgxQzY0LjQ0MDkgMjkuOTcyOCA2My44OTY1IDI5LjA0NjQgNjMuMDE4MiAyOC41NTczQzYyLjE2ODQgMjguMDgzOSA2MS4xMzI1IDI4LjA5MSA2MC4yODkxIDI4LjU3NThMMzcuMDA3NCA0MS45NTg4QzM1LjQ0NTQgNDIuODU2NyAzNC42NjQzIDQzLjMwNTYgMzMuODA3MyA0My4zMDU5QzMyLjk1MDIgNDMuMzA2MiAzMi4xNjg5IDQyLjg1NzcgMzAuNjA2MyA0MS45NjA3TDE0Ljg0ODcgMzIuOTE1NUMxNC4wNTk0IDMyLjQ2MjQgMTMuNjY0NyAzMi4yMzU5IDEzLjM0NzcgMzIuMTk1QzEyLjYyNSAzMi4xMDE3IDExLjkzMDEgMzIuNTA2NiAxMS42NTQ4IDMzLjE4MTNDMTEuNTM0MSAzMy40NzcyIDExLjUzNjUgMzMuOTMyMiAxMS41NDE0IDM0Ljg0MjRDMTEuNTQ1IDM1LjUxMjQgMTEuNTQ2OCAzNS44NDc0IDExLjYwOTQgMzYuMTU1NkMxMS43NDk3IDM2Ljg0NTYgMTIuMTEyNyAzNy40NzA1IDEyLjY0MjggMzcuOTM0MUMxMi44Nzk1IDM4LjE0MTEgMTMuMTY5NiAzOC4zMDg1IDEzLjc1IDM4LjY0MzVMMzAuNTk3NCA0OC4zNjcyQzMyLjE2NDEgNDkuMjcxNCAzMi45NDc0IDQ5LjcyMzUgMzMuODA3NSA0OS43MjM3QzM0LjY2NzcgNDkuNzIzOSAzNS40NTEzIDQ5LjI3MjMgMzcuMDE4NCA0OC4zNjg5TDU3LjY2ODQgMzYuNDY1NEM1OC4yMDM3IDM2LjE1NjkgNTguNDcxNCAzNi4wMDI2IDU4LjY3MjEgMzYuMTE4NUM1OC44NzI3IDM2LjIzNDUgNTguODcyNyAzNi41NDM0IDU4Ljg3MjcgMzcuMTYxM1Y0MC4zMzY1QzU4Ljg3MjcgNDEuMjQyNCA1OC44NzI3IDQxLjY5NTQgNTguNjU3MiA0Mi4wNjgzQzU4LjQ0MTggNDIuNDQxMyA1OC4wNDkzIDQyLjY2NzUgNTcuMjY0NCA0My4xMTk5TDQwLjIzMjIgNTIuOTM4QzM3LjA5NjYgNTQuNzQ1NCAzNS41Mjg4IDU1LjY0OTIgMzMuODA3OSA1NS42NDg0QzMyLjA4NjkgNTUuNjQ3NiAzMC41MTk5IDU0Ljc0MjQgMjcuMzg2IDUyLjkzMjFMMTEuNDUwOSA0My43MjdDMTEuNDAwMyA0My42OTc4IDExLjM3NSA0My42ODMyIDExLjM1MTQgNDMuNjY5NEM4LjAxMDIzIDQxLjcxNyA1Ljk0ODU5IDM4LjE0NTEgNS45MjkyNSAzNC4yNzU0QzUuOTI5MTIgMzQuMjQ4IDUuOTI5MTIgMzQuMjE4OCA1LjkyOTEyIDM0LjE2MDRWMzEuMjQ1OEM1LjkyOTEyIDI5LjEwOTUgNy4wNjY4OSAyNy4xMzQ5IDguOTE1MTMgMjYuMDYzNkMxMC41NDgzIDI1LjExNjkgMTIuNTYyOCAyNS4xMTUxIDE0LjE5NzcgMjYuMDU4N0wyNy4zOTY0IDMzLjY3NjRaIiBmaWxsPSIjRjJGN0Y3Ii8+Cjwvc3ZnPgo=&labelColor=5c5c5c&color=3F89A1&label=%20" alt="Documented on GitBook"></a>
|
<a href="https://gitbook.com"><img src="https://img.shields.io/static/v1?message=Documented%20on%20GitBook&logo=gitbook&logoColor=ffffff&label=%20&labelColor=5c5c5c&color=3F89A1"></a>
|
||||||
<a href="#"><img src="https://img.shields.io/badge/Open_Source-❤️-FDA599?"/></a>
|
<a href="#"><img src="https://img.shields.io/badge/Open_Source-❤️-FDA599?"/></a>
|
||||||
<a href="/LICENSE"><img src="https://img.shields.io/badge/License-GNU_GPLv3-F4E28D"/></a>
|
<a href="/LICENSE"><img src="https://img.shields.io/badge/License-GNU_GPLv3-F4E28D"/></a>
|
||||||
<a href="/.github/CONTRIBUTING.md"><img src="https://img.shields.io/github/contributors/gitbookIO/gitbook"/></a>
|
<a href="/.github/CONTRIBUTING.md"><img src="https://img.shields.io/github/contributors/gitbookIO/gitbook"/></a>
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
<p align="center">Welcome to GitBook, the platform for managing technical knowledge for teams.</p>
|
<p align="center">Welcome to GitBook, the platform for managing technical knowledge for teams.</p>
|
||||||
|
|
||||||
<p align="center">This repository contains the open-source code used to render GitBook's published content.</p>
|
<p align="center">This repository contains the open source code used to render GitBook's published content.</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img alt="GitBook Open Published Site" src="./assets/published-site.png">
|
<img alt="GitBook Open Published Site" src="./assets/published-site.png">
|
||||||
@@ -46,19 +46,28 @@ To run a local version of this project, please follow these simple steps.
|
|||||||
git clone https://github.com/gitbookIO/gitbook.git
|
git clone https://github.com/gitbookIO/gitbook.git
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Install the project's dependencies through Bun.
|
2. Ensure you are using the project's version of `node`. Running `nvm use` will change your local version to the correct one.
|
||||||
|
|
||||||
|
3. Install the project's dependencies through Bun.
|
||||||
|
|
||||||
```
|
```
|
||||||
bun install
|
bun install
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Start your local development server.
|
4. Start your local development server.
|
||||||
|
|
||||||
```
|
```
|
||||||
bun dev
|
bun dev
|
||||||
```
|
```
|
||||||
|
|
||||||
Then open the space in your web browser, using http://localhost:3000/<host>/<path> (example: http://localhost:3000/docs.gitbook.com).
|
5. Open a published GitBook space in your web browser, prefixing it with `http://localhost:3000/`.
|
||||||
|
|
||||||
|
examples:
|
||||||
|
|
||||||
|
- http://localhost:3000/docs.gitbook.com
|
||||||
|
- http://localhost:3000/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.
|
||||||
|
|
||||||
### Other development commands
|
### Other development commands
|
||||||
|
|
||||||
@@ -71,7 +80,7 @@ All pull-requests will be tested against both visual and performances testing to
|
|||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
GitBook's rendering engine is fully open-source and built on top of [Next.js](https://nextjs.org/). Head to our [contributing guide](https://github.com/GitbookIO/gitbook/.github/CONTRIBUTING.md) to learn more about the workflow on adding your first Pull Request.
|
GitBook's rendering engine is fully open source and built on top of [Next.js](https://nextjs.org/). Head to our [contributing guide](https://github.com/GitbookIO/gitbook/blob/main/.github/CONTRIBUTING.md) to learn more about the workflow on adding your first Pull Request.
|
||||||
|
|
||||||
### Types of contributions
|
### Types of contributions
|
||||||
|
|
||||||
@@ -79,7 +88,7 @@ We encourage you to contribute to GitBook to help us build the best tool for doc
|
|||||||
|
|
||||||
#### Translations
|
#### Translations
|
||||||
|
|
||||||
The GitBook UI is rendered using a set of translation files found in [`src/intl/translations`](/src/intl/translations/). We welcome all additional translations for the UI.
|
The GitBook UI is rendered using a set of translation files found in [`packages/gitbook/src/intl/translations`](/packages/gitbook/src/intl/translations/). We welcome all additional translations for the UI.
|
||||||
|
|
||||||
#### Bugs
|
#### Bugs
|
||||||
|
|
||||||
@@ -90,7 +99,7 @@ Encounter a bug or find an issue you'd like to fix? Helping us fix issues relate
|
|||||||
> [!WARNING]
|
> [!WARNING]
|
||||||
> While it is possible to self-host this project, we do not recommend this unless you are certain this option fits your need.
|
> While it is possible to self-host this project, we do not recommend this unless you are certain this option fits your need.
|
||||||
>
|
>
|
||||||
> _Looking to add a specific feature in GitBook? Head to our [contributing guide](/.github/CONTRIBUTING.md) to get started._
|
> _Looking to add a specific feature in GitBook? Head to our [contributing guide](https://github.com/GitbookIO/gitbook/blob/main/.github/CONTRIBUTING.md) to get started._
|
||||||
>
|
>
|
||||||
> Self-hosting this project puts the responsibility of maintaining and merging future updates on **you**. We cannot guarantee support, maintenance, or updates to forked and self-hosted instances of this project.
|
> Self-hosting this project puts the responsibility of maintaining and merging future updates on **you**. We cannot guarantee support, maintenance, or updates to forked and self-hosted instances of this project.
|
||||||
>
|
>
|
||||||
@@ -106,10 +115,30 @@ On the con side, you become responsible for the reliability of your published si
|
|||||||
|
|
||||||
Distributed under the [GNU GPLv3 License](https://github.com/GitBookIO/gitbook/blob/main/LICENSE).
|
Distributed under the [GNU GPLv3 License](https://github.com/GitBookIO/gitbook/blob/main/LICENSE).
|
||||||
|
|
||||||
If you plan to distribute the code, you must the source code public to comply with GNU GPLv3. To clone in a private repository, acquire a [commercial license](https://www.gitbook.com/pricing).
|
If you plan to distribute the code, you must make the source code public to comply with the GNU GPLv3. To clone in a private repository, acquire a [commercial license](https://www.gitbook.com/pricing).
|
||||||
|
|
||||||
See `LICENSE` for more information.
|
See `LICENSE` for more information.
|
||||||
|
|
||||||
|
## Badges
|
||||||
|
|
||||||
|
<p align="left">
|
||||||
|
<a href="https://gitbook.com"><img src="https://img.shields.io/static/v1?message=Documented%20on%20GitBook&logo=gitbook&logoColor=ffffff&label=%20&labelColor=5c5c5c&color=3F89A1"></a>
|
||||||
|
<a href="https://gitbook.com"><img src="https://img.shields.io/static/v1?message=Documented%20on%20GitBook&logo=gitbook&logoColor=ffffff&label=%20&labelColor=5c5c5c&color=F4E28D"></a>
|
||||||
|
<a href="https://gitbook.com"><img src="https://img.shields.io/static/v1?message=Documented%20on%20GitBook&logo=gitbook&logoColor=ffffff&label=%20&labelColor=5c5c5c&color=FDA599"></a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
```md
|
||||||
|
[](https://gitbook.com/)
|
||||||
|
```
|
||||||
|
|
||||||
|
```html
|
||||||
|
<a href="https://gitbook.com">
|
||||||
|
<img
|
||||||
|
src="https://img.shields.io/static/v1?message=Documented%20on%20GitBook&logo=gitbook&logoColor=ffffff&label=%20&labelColor=5c5c5c&color=3F89A1"
|
||||||
|
/>
|
||||||
|
</a>
|
||||||
|
```
|
||||||
|
|
||||||
## Acknowledgements
|
## Acknowledgements
|
||||||
|
|
||||||
GitBook wouldn't be possible without these projects:
|
GitBook wouldn't be possible without these projects:
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
[install.scopes]
|
||||||
|
"awesome.me" = { token = "$NPMRC_FONT_AWESOME_TOKEN", url = "https://npm.fontawesome.com/" }
|
||||||
+16
-8
@@ -1,27 +1,35 @@
|
|||||||
{
|
{
|
||||||
"name": "gitbook",
|
"name": "gitbook",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"devDependencies": {
|
||||||
|
"@changesets/cli": "^2.27.7",
|
||||||
|
"prettier": "^3.0.3",
|
||||||
|
"turbo": "^2.1.2"
|
||||||
|
},
|
||||||
"packageManager": "bun@1.1.18",
|
"packageManager": "bun@1.1.18",
|
||||||
|
"patchedDependencies": {
|
||||||
|
"@vercel/next@4.3.15": "patches/@vercel%2Fnext@4.3.15.patch",
|
||||||
|
"@cloudflare/next-on-pages@1.13.5": "patches/@cloudflare%2Fnext-on-pages@1.13.5.patch"
|
||||||
|
},
|
||||||
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "turbo run dev",
|
"dev": "turbo run dev",
|
||||||
"build": "turbo run build",
|
"build": "turbo run build",
|
||||||
"build:cloudflare": "turbo run build:cloudflare",
|
"build:cloudflare": "turbo run build:cloudflare",
|
||||||
"lint": "turbo run lint",
|
"lint": "turbo run lint",
|
||||||
|
"lint:fix": "turbo run lint -- --fix",
|
||||||
"typecheck": "turbo run typecheck",
|
"typecheck": "turbo run typecheck",
|
||||||
"format": "prettier ./ --ignore-unknown --write",
|
"format": "prettier ./ --ignore-unknown --write",
|
||||||
"format:check": "prettier ./ --ignore-unknown --list-different",
|
"format:check": "prettier ./ --ignore-unknown --list-different",
|
||||||
"unit": "turbo run unit",
|
"unit": "turbo run unit",
|
||||||
"e2e": "turbo run e2e",
|
"e2e": "turbo run e2e",
|
||||||
"changeset": "changeset",
|
"changeset": "changeset",
|
||||||
"release": "turbo run build && changeset publish"
|
"release": "turbo run release && changeset publish",
|
||||||
|
"release:preview": "turbo run release:preview",
|
||||||
|
"download:env": "op read op://gitbook-x-dev/gitbook-open/.env.local >> .env.local",
|
||||||
|
"clean": "turbo run clean"
|
||||||
},
|
},
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"packages/*"
|
"packages/*"
|
||||||
],
|
]
|
||||||
"devDependencies": {
|
|
||||||
"@changesets/cli": "^2.27.7",
|
|
||||||
"prettier": "^3.0.3",
|
|
||||||
"turbo": "^2.0.9"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
.wrangler
|
||||||
|
worker-configuration.d.ts
|
||||||
|
dist/
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# @gitbook/cache-do
|
||||||
|
|
||||||
|
## 0.1.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- b7a5106: Disable cloudflare observability in production
|
||||||
|
|
||||||
|
## 0.1.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- 9b8d519: Experiment with optimizing billable duration in Cloudflare by using multiple RPC sessions instead of one
|
||||||
|
- 636b868: First version of a new cache backend powered by Cloudflare Durable Objects
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 56f5fa1: Enable Workers observability with a sampling of 0.1
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# `@gitbook/cache-do`
|
||||||
|
|
||||||
|
Cache backend, powered by Cloudflare Durable Objects. The cache is optimized for GitBook use-cases.
|
||||||
|
|
||||||
|
### Performances
|
||||||
|
|
||||||
|
The cache backend is optimized for performances by being distributed and accessible close to the worker locations that are reading it.
|
||||||
|
|
||||||
|
### Geo-distribution
|
||||||
|
|
||||||
|
To achieve a good balance between **performances** and **consistency**, cache objects are distributed over 7 locations, representing continents.
|
||||||
|
|
||||||
|
It makes it possible to purge all 7 locations in one go and achieve fast consistency.
|
||||||
|
|
||||||
|
### Concepts
|
||||||
|
|
||||||
|
**Cache tag**: unique tag in the cache environment. A cache tag groups multiple keys that should be purged together in one operation.
|
||||||
|
Cache tags should not contain a large set of unique keys. Exceeding thousands could lead to performances or reliability issues.
|
||||||
|
|
||||||
|
**Cache key**: unique key in the cache environment. Each key should be assigned to a `tag`.
|
||||||
|
|
||||||
|
**Location**: cache is distributed over 7 unique locations, one for each continent.
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
{
|
||||||
|
"name": "@gitbook/cache-do",
|
||||||
|
"type": "module",
|
||||||
|
"private": true,
|
||||||
|
"exports": {
|
||||||
|
".": {
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"development": "./src/index.ts",
|
||||||
|
"default": "./dist/index.js"
|
||||||
|
},
|
||||||
|
"./api": {
|
||||||
|
"types": "./dist/api.d.ts",
|
||||||
|
"development": "./src/api.ts",
|
||||||
|
"default": "./dist/api.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"version": "0.1.1",
|
||||||
|
"dependencies": {
|
||||||
|
"@msgpack/msgpack": "^3.0.0-beta2",
|
||||||
|
"lru_map": "^0.4.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"typescript": "^5.5.3",
|
||||||
|
"wrangler": "3.82.0"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"generate": "wrangler types --experimental-include-runtime",
|
||||||
|
"build": "tsc",
|
||||||
|
"typecheck": "tsc --noEmit",
|
||||||
|
"dev": "tsc -w",
|
||||||
|
"release": "wrangler deploy",
|
||||||
|
"release:preview": "wrangler deploy && wrangler deploy --env preview"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"dist",
|
||||||
|
"src",
|
||||||
|
"bin",
|
||||||
|
"data",
|
||||||
|
"README.md",
|
||||||
|
"CHANGELOG.md"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,299 @@
|
|||||||
|
import { encode, decode } from '@msgpack/msgpack';
|
||||||
|
import { DurableObject } from 'cloudflare:workers';
|
||||||
|
import { LRUMap } from 'lru_map';
|
||||||
|
|
||||||
|
export interface CacheObjectDescriptor {
|
||||||
|
get: <Value = unknown>(key: string) => Promise<Value | undefined>;
|
||||||
|
set: <Value = unknown>(key: string, value: Value, expiresAt: number) => Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Value stored in a chunked binary msgpack format.
|
||||||
|
* Stored under the key `prop.${key}.${index}`.
|
||||||
|
*/
|
||||||
|
interface CacheObjectProp<Value = unknown> {
|
||||||
|
value: Value;
|
||||||
|
expiresAt: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expiration clock stored under the key `exp.${expiresAt}.${key}`.
|
||||||
|
*/
|
||||||
|
interface CacheObjectExp {
|
||||||
|
/** Key of the property */
|
||||||
|
k: string;
|
||||||
|
/** Number of chunks */
|
||||||
|
c: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Durable Object class being deployed as a distributed cache.
|
||||||
|
*/
|
||||||
|
export class CacheObject extends DurableObject {
|
||||||
|
private lru = new LRUMap<string, { match: CacheObjectProp | undefined }>(500);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open a descriptor to access the cache object.
|
||||||
|
* The goal is to minimize the amount of RPC sessions between the client and the cache object.
|
||||||
|
* One session is opened per request on the client side and used to perform multiple operations.
|
||||||
|
* https://developers.cloudflare.com/workers/runtime-apis/rpc/#return-functions-from-rpc-methods
|
||||||
|
*/
|
||||||
|
public open(): CacheObjectDescriptor {
|
||||||
|
return {
|
||||||
|
get: async <Value = unknown>(key: string) => {
|
||||||
|
return this.get<Value>(key);
|
||||||
|
},
|
||||||
|
set: async <Value = unknown>(key: string, value: Value, expiresAt: number) => {
|
||||||
|
await this.set(key, value, expiresAt);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of a property.
|
||||||
|
*/
|
||||||
|
public async get<Value = unknown>(key: string) {
|
||||||
|
return this.logOperation({ operation: 'get', key }, async (setLog) => {
|
||||||
|
// Try the memory state first.
|
||||||
|
const memoryEntry = this.lru.get(key);
|
||||||
|
if (memoryEntry) {
|
||||||
|
setLog({ memory: true });
|
||||||
|
setLog({ memoryMatch: !!memoryEntry.match });
|
||||||
|
if (!memoryEntry.match) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isExpired = memoryEntry.match.expiresAt < Date.now();
|
||||||
|
setLog({ memoryExpired: isExpired });
|
||||||
|
|
||||||
|
if (!isExpired) {
|
||||||
|
return memoryEntry.match.value as Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return await this.getFromStorage<Value>(key);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of a property from the DO storage.
|
||||||
|
*/
|
||||||
|
public async getFromStorage<Value = unknown>(key: string) {
|
||||||
|
return this.logOperation({ operation: 'getFromStorage', key }, async (setLog) => {
|
||||||
|
const entries = await this.ctx.storage.list<Uint8Array>({
|
||||||
|
prefix: getStoragePropKey(key),
|
||||||
|
noCache: true,
|
||||||
|
});
|
||||||
|
if (entries.size) {
|
||||||
|
const entry = decodeChunks<CacheObjectProp<Value>>(entries);
|
||||||
|
setLog({ chunks: entries.size, chunksSize: entry?.size ?? 0 });
|
||||||
|
if (entry && entry.value.expiresAt > Date.now()) {
|
||||||
|
// Found
|
||||||
|
this.lru.set(key, { match: entry.value });
|
||||||
|
return entry.value.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not found
|
||||||
|
this.lru.set(key, { match: undefined });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a value in the cache object.
|
||||||
|
*/
|
||||||
|
public async set<Value = unknown>(key: string, value: Value, expiresAt: number) {
|
||||||
|
return this.logOperation({ operation: 'set', key }, async (setLog) => {
|
||||||
|
const prop: CacheObjectProp<Value> = {
|
||||||
|
value,
|
||||||
|
expiresAt,
|
||||||
|
};
|
||||||
|
|
||||||
|
this.lru.set(key, { match: prop });
|
||||||
|
await this.ctx.storage.transaction(async (tx) => {
|
||||||
|
const entries = encodeChunks(key, prop);
|
||||||
|
const chunks = Object.keys(entries).length;
|
||||||
|
setLog({ chunks });
|
||||||
|
|
||||||
|
const clockValue: CacheObjectExp = {
|
||||||
|
k: key,
|
||||||
|
c: chunks,
|
||||||
|
};
|
||||||
|
|
||||||
|
await tx.put(getGCClockKey(key, expiresAt), clockValue);
|
||||||
|
await tx.put(entries);
|
||||||
|
|
||||||
|
const currentAlarm = await tx.getAlarm();
|
||||||
|
if (!currentAlarm) {
|
||||||
|
// Set an alarm to garbage collect all entries that have expired in 12h.
|
||||||
|
await tx.setAlarm(Date.now() + 12 * 60 * 60 * 1000);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Purge all keys in the cache object.
|
||||||
|
*/
|
||||||
|
public async purge() {
|
||||||
|
return this.logOperation({ operation: 'purge' }, async (setLog) => {
|
||||||
|
let result = new Set<string>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// List all the keys in the cache object.
|
||||||
|
const entries = await this.ctx.storage.list<CacheObjectExp>({
|
||||||
|
prefix: 'exp.',
|
||||||
|
noCache: true,
|
||||||
|
});
|
||||||
|
setLog({ entries: entries.size });
|
||||||
|
entries.forEach((exp) => {
|
||||||
|
result.add(exp.k);
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
// If an error occurs, reset the cache object.
|
||||||
|
// This is a safety mechanism to prevent the cache object from being stuck in a bad state.
|
||||||
|
console.error('Error during purge, resetting the cache object', error);
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.reset();
|
||||||
|
return Array.from(result);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alarm to garbage collect all entries that have expired.
|
||||||
|
*/
|
||||||
|
async alarm() {
|
||||||
|
return this.logOperation({ operation: 'alarm' }, async (setLog) => {
|
||||||
|
try {
|
||||||
|
const entries = await this.ctx.storage.list<CacheObjectExp>({
|
||||||
|
prefix: 'exp.',
|
||||||
|
noCache: true,
|
||||||
|
});
|
||||||
|
setLog({ entries: entries.size });
|
||||||
|
const toDeleteSet = new Set<string>();
|
||||||
|
|
||||||
|
for (const [key, exp] of entries) {
|
||||||
|
const timestamp = parseInt(key.split('.')[1]);
|
||||||
|
if (timestamp < Date.now()) {
|
||||||
|
toDeleteSet.add(key);
|
||||||
|
for (let i = 0; i < exp.c; i++) {
|
||||||
|
toDeleteSet.add(getStoragePropChunkKey(exp.k, i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the keys by batch of 128.
|
||||||
|
const toDelete = Array.from(toDeleteSet);
|
||||||
|
setLog({ toDelete: toDelete.length });
|
||||||
|
for (let i = 0; i < toDelete.length; i += 128) {
|
||||||
|
await this.ctx.storage.delete(toDelete.slice(i, i + 128));
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there are still keys to delete, set an alarm to continue the deletion in 12h.
|
||||||
|
if (toDelete.length) {
|
||||||
|
await this.ctx.storage.setAlarm(Date.now() + 12 * 60 * 60 * 1000);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// If an error occurs, reset the cache object.
|
||||||
|
// This is a safety mechanism to prevent the cache object from being stuck in a bad state.
|
||||||
|
console.error('Error during alarm, reset the cache object', error);
|
||||||
|
await this.reset();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset the cache object.
|
||||||
|
*/
|
||||||
|
async reset() {
|
||||||
|
return this.logOperation({ operation: 'reset' }, async () => {
|
||||||
|
this.lru.clear();
|
||||||
|
await this.ctx.storage.deleteAll();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Time and log an operation.
|
||||||
|
*/
|
||||||
|
async logOperation<T>(
|
||||||
|
log: Record<string, unknown>,
|
||||||
|
fn: (update: (log: Record<string, unknown>) => void) => Promise<T>,
|
||||||
|
): Promise<T> {
|
||||||
|
const objectId = this.ctx.id.name ?? this.ctx.id.toString();
|
||||||
|
let update: Record<string, unknown> = {};
|
||||||
|
const start = performance.now();
|
||||||
|
try {
|
||||||
|
return await fn((arg) => {
|
||||||
|
Object.assign(update, arg);
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
const duration = performance.now() - start;
|
||||||
|
console.log({ ...log, ...update, objectId, duration });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getStoragePropKey(key: string): string {
|
||||||
|
return `prop.${key}.`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getStoragePropChunkKey(key: string, index: number): string {
|
||||||
|
return `${getStoragePropKey(key)}${index}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getGCClockRootKey(timestamp: number): string {
|
||||||
|
return `exp.${timestamp}.`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getGCClockKey(key: string, expiresAt: number): string {
|
||||||
|
return `${getGCClockRootKey(expiresAt)}${key}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function encodeChunks<T>(key: string, value: T): Record<string, Uint8Array> {
|
||||||
|
const buf = encode(value);
|
||||||
|
const entries: Record<string, Uint8Array> = {};
|
||||||
|
const chunks = chunkUint8Array(buf, 128 * 1024);
|
||||||
|
|
||||||
|
for (let index = 0; index < chunks.length; index++) {
|
||||||
|
entries[getStoragePropChunkKey(key, index)] = chunks[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
function decodeChunks<T>(entries: Map<string, Uint8Array>): { value: T; size: number } | undefined {
|
||||||
|
const chunks = Array.from(entries.entries())
|
||||||
|
.map(([key, value]) => {
|
||||||
|
const index = parseInt(key.split('.').pop()!);
|
||||||
|
return [index, value] as const;
|
||||||
|
})
|
||||||
|
.sort(([a], [b]) => a - b)
|
||||||
|
.map(([, value]) => value);
|
||||||
|
|
||||||
|
if (chunks.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const buf = mergeUint8Array(chunks);
|
||||||
|
return { value: decode(buf) as T, size: buf.length };
|
||||||
|
}
|
||||||
|
|
||||||
|
function chunkUint8Array(input: Uint8Array, chunkSize: number): Uint8Array[] {
|
||||||
|
const chunks: Uint8Array[] = [];
|
||||||
|
for (let i = 0; i < input.length; i += chunkSize) {
|
||||||
|
chunks.push(input.slice(i, i + chunkSize));
|
||||||
|
}
|
||||||
|
return chunks;
|
||||||
|
}
|
||||||
|
|
||||||
|
function mergeUint8Array(chunks: Uint8Array[]): Uint8Array {
|
||||||
|
const totalLength = chunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
||||||
|
const result = new Uint8Array(totalLength);
|
||||||
|
let offset = 0;
|
||||||
|
for (const chunk of chunks) {
|
||||||
|
result.set(chunk, offset);
|
||||||
|
offset += chunk.length;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
import type { CacheObject, CacheObjectDescriptor } from './CacheObject';
|
||||||
|
|
||||||
|
export type CacheLocationId = ContinentCode;
|
||||||
|
const allLocations: CacheLocationId[] = ['AF', 'AS', 'NA', 'SA', 'AN', 'EU', 'OC'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Location hint for the CacheObject durable object.
|
||||||
|
*/
|
||||||
|
const doLocationHints: {
|
||||||
|
[key in CacheLocationId]: DurableObjectLocationHint;
|
||||||
|
} = {
|
||||||
|
AF: 'afr',
|
||||||
|
AS: 'apac',
|
||||||
|
NA: 'wnam',
|
||||||
|
SA: 'sam',
|
||||||
|
AN: 'oc',
|
||||||
|
EU: 'weur',
|
||||||
|
OC: 'oc',
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Client to access a cache tag.
|
||||||
|
*/
|
||||||
|
export class CacheObjectStub {
|
||||||
|
private stub: DurableObjectStub<CacheObject>;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
/** Binding to the CacheObject durable object */
|
||||||
|
private doNamespace: DurableObjectNamespace<CacheObject>,
|
||||||
|
/** ID of the location to target */
|
||||||
|
private locationId: CacheLocationId,
|
||||||
|
/** Name of the tag */
|
||||||
|
private tag: string,
|
||||||
|
) {
|
||||||
|
const groupId = getCacheObjectIdName(this.locationId, this.tag);
|
||||||
|
this.stub = this.doNamespace.get(this.doNamespace.idFromName(groupId), {
|
||||||
|
// Initialize the object with a locaiton hint,
|
||||||
|
// as we might want to purge all locations before the object is created.
|
||||||
|
// https://developers.cloudflare.com/durable-objects/reference/data-location/
|
||||||
|
locationHint: doLocationHints[this.locationId],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open a descriptor to the cache object.
|
||||||
|
* It can be used to perform multiple operations in a single RPC session.
|
||||||
|
* Ex:
|
||||||
|
* ```ts
|
||||||
|
* using desc = cache.open();
|
||||||
|
* await desc.set('key', 'value', Date.now() + 1000);
|
||||||
|
* await desc.get('key');
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
async open() {
|
||||||
|
return await this.stub.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a value from the cache.
|
||||||
|
*/
|
||||||
|
async get<Value = unknown>(key: string) {
|
||||||
|
return (await this.stub.get(key)) as Value | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a value in the cache.
|
||||||
|
*/
|
||||||
|
async set<Value = unknown>(key: string, value: Value, expiresAt: number) {
|
||||||
|
return await this.stub.set(key, value, expiresAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Purge all keys in the cache tag.
|
||||||
|
*/
|
||||||
|
async purge() {
|
||||||
|
const keys = new Set<string>();
|
||||||
|
await Promise.all(
|
||||||
|
allLocations.map(async (locationId) => {
|
||||||
|
const groupId = getCacheObjectIdName(locationId, this.tag);
|
||||||
|
const cacheGroup = this.doNamespace.get(this.doNamespace.idFromName(groupId), {
|
||||||
|
// Initialize the object with a locaiton hint,
|
||||||
|
// as we might want to purge all locations before the object is created.
|
||||||
|
// https://developers.cloudflare.com/durable-objects/reference/data-location/
|
||||||
|
locationHint: doLocationHints[this.locationId],
|
||||||
|
});
|
||||||
|
const locationkeys = await cacheGroup.purge();
|
||||||
|
locationkeys.forEach((key) => keys.add(key));
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCacheObjectIdName(locationId: CacheLocationId, tag: string): string {
|
||||||
|
return `${locationId}:${tag}`;
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export * from './CacheObjectStub';
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import { WorkerEntrypoint } from 'cloudflare:workers';
|
||||||
|
|
||||||
|
export * from './CacheObject';
|
||||||
|
|
||||||
|
export default class Worker extends WorkerEntrypoint {
|
||||||
|
fetch() {
|
||||||
|
return new Response('Hello, world!');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "esnext",
|
||||||
|
"lib": ["dom", "dom.iterable", "esnext"],
|
||||||
|
"allowJs": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"strict": true,
|
||||||
|
"noEmit": false,
|
||||||
|
"declaration": true,
|
||||||
|
"outDir": "dist",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"module": "esnext",
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"isolatedModules": true,
|
||||||
|
"incremental": true,
|
||||||
|
"types": ["./.wrangler/types/runtime.d.ts"]
|
||||||
|
},
|
||||||
|
"include": ["src/**/*.ts"],
|
||||||
|
"exclude": ["node_modules"]
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
main = "./src/index.ts"
|
||||||
|
name = "gitbook-open-cache"
|
||||||
|
compatibility_date = "2024-09-02"
|
||||||
|
|
||||||
|
durable_objects.bindings = [
|
||||||
|
{name = "CACHE", class_name = "CacheObject"}
|
||||||
|
]
|
||||||
|
|
||||||
|
migrations = [
|
||||||
|
{tag = "v1", new_classes = ["CacheObject"]}
|
||||||
|
]
|
||||||
|
|
||||||
|
[observability]
|
||||||
|
enabled = false
|
||||||
|
|
||||||
|
[env.preview]
|
||||||
|
name = "gitbook-open-cache-preview"
|
||||||
|
durable_objects.bindings = [
|
||||||
|
{name = "CACHE", class_name = "CacheObject"}
|
||||||
|
]
|
||||||
|
migrations = [
|
||||||
|
{tag = "v1", new_classes = ["CacheObject"]}
|
||||||
|
]
|
||||||
|
|
||||||
|
[env.preview.observability]
|
||||||
|
enabled = true
|
||||||
|
head_sampling_rate = 0.1
|
||||||
@@ -1 +1 @@
|
|||||||
index.ts
|
dist/
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import fs from 'fs';
|
import fs from 'node:fs';
|
||||||
|
import path from 'node:path';
|
||||||
import emojisRaws from 'emoji-assets/emoji.json';
|
import emojisRaws from 'emoji-assets/emoji.json';
|
||||||
|
|
||||||
interface EmojiData {
|
interface EmojiData {
|
||||||
@@ -20,7 +21,8 @@ Object.entries(emojis).forEach(([key, value]) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
fs.mkdirSync(path.resolve(__dirname, 'dist'), { recursive: true });
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
'index.ts',
|
path.resolve(__dirname, 'dist/index.ts'),
|
||||||
`export const emojiCodepoints: Record<string, string> = ${JSON.stringify(output, null, 4)};`,
|
`export const emojiCodepoints: Record<string, string> = ${JSON.stringify(output, null, 4)};`,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,12 +3,13 @@
|
|||||||
"description": "Optimized mapping of codepoints to the fully qualified emoji codepoints",
|
"description": "Optimized mapping of codepoints to the fully qualified emoji codepoints",
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"exports": "./index.ts",
|
"exports": "./dist/index.ts",
|
||||||
"dependencies": {},
|
"dependencies": {},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"emoji-assets": "^8.0.0"
|
"emoji-assets": "^8.0.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"postinstall": "bun ./build.ts"
|
"generate": "bun ./build.ts",
|
||||||
|
"clean": "rm -rf ./dist"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,3 +25,6 @@
|
|||||||
|
|
||||||
### Sentry ###
|
### Sentry ###
|
||||||
# SENTRY_DSN=xxx
|
# SENTRY_DSN=xxx
|
||||||
|
|
||||||
|
### Silent logs
|
||||||
|
# SILENT=true
|
||||||
@@ -32,4 +32,5 @@ screenshots/
|
|||||||
/playwright/.cache/
|
/playwright/.cache/
|
||||||
|
|
||||||
# Generated public files
|
# Generated public files
|
||||||
/public/~gitbook/static/
|
/public/~gitbook/static/*
|
||||||
|
!/public/~gitbook/static/images
|
||||||
|
|||||||
@@ -1,5 +1,163 @@
|
|||||||
# gitbook
|
# gitbook
|
||||||
|
|
||||||
|
## 0.5.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- 57cdd25: GitBook Open now supports Ask AI in sites. When asking a question to Ask AI, GitBook will use context from across your site sections and variants to provide the best answer.
|
||||||
|
- ca134c8: Fix an issue where the active site section indicator appeared above any dropdowns.
|
||||||
|
- d48926e: Fix an issue where the space dropdown was shown under the site sections in Safari.
|
||||||
|
- 9fe8142: Fix an issue where Ask AI was erroring due to an object being passed as a param.
|
||||||
|
- d843e5e: Fix an issue where the space dropdown could appear behind the header.
|
||||||
|
- a2e5647: Fix the styling of site section tabs on smaller screens.
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 076dc48: Fix expandable block anchore resolution
|
||||||
|
- d9bb9f9: Fix an issue with the cookie banner buttons being non responsive
|
||||||
|
- 23584c9: Update the site header with new styling, a new search button, and refactored layout
|
||||||
|
- 664debc: Add support for tint color
|
||||||
|
- 4d56f11: Update styling of search+ask modal
|
||||||
|
- 061c0c1: Fix a regression in variant drop-down caused by missing z-index.
|
||||||
|
- 2f76712: Add breadcrumbs above page title
|
||||||
|
- 07cf835: Add scroll margin to the top when there are sections
|
||||||
|
- 5d72b35: Smoother tab transition for sections
|
||||||
|
- 7c71363: Don't adjust fallback font for mono font.
|
||||||
|
- 7675c2c: Optimize performances by using new API endpoint for fetching site data.
|
||||||
|
- 87eea73: Fix margin and image resolution of header logo
|
||||||
|
- aa2ed0f: Restyle hint blocks
|
||||||
|
- ffd3937: Fix security issue with image resizing that could be used for phishing
|
||||||
|
- 2ce59d7: Fix - whitespace added to site section tabs with icons.
|
||||||
|
- c73e07d: Increase token max length to fix code not highlighted
|
||||||
|
- 3b3d6e2: Add icons to sections
|
||||||
|
- 1ed18c0: style: adds missing scalar css variables
|
||||||
|
- Updated dependencies [b7a5106]
|
||||||
|
- Updated dependencies [4771c78]
|
||||||
|
- Updated dependencies [ff50ac2]
|
||||||
|
- Updated dependencies [867481c]
|
||||||
|
- Updated dependencies [7ba67fd]
|
||||||
|
- Updated dependencies [a78c1ec]
|
||||||
|
- @gitbook/cache-do@0.1.1
|
||||||
|
- @gitbook/react-openapi@0.7.1
|
||||||
|
|
||||||
|
## 0.4.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- e09f747: Revalidate change request cached content when pressing refresh button
|
||||||
|
- 2fa0851: Add navigation tabs for sections
|
||||||
|
- a4b63b8: Support resolution of new site URLs with sections
|
||||||
|
- 5c35f36: Replace all icons, previously imported from Geist, by new package `@gitbook/icons`
|
||||||
|
- e9b31a5: Unify section tab styles with page item styles
|
||||||
|
- f12a215: Add support for Norwegian language
|
||||||
|
- f4c9536: Optimize layout shift while transitioning between pages with full width blocks (ex: OpenAPI blocks)
|
||||||
|
- 1f24fe4: Add support for page icons
|
||||||
|
- cda08a9: Add support for searching results in a sections site
|
||||||
|
- b32e40c: Persist state of tabs and dynamically sync them based on title
|
||||||
|
- 15d2ee3: Show the caption for file blocks
|
||||||
|
- f885e88: Improve the toolbar for change-requests and revisions to show more actions
|
||||||
|
- 07ea45b: Remove deprecated synced block from GitBook Open
|
||||||
|
- c3675fd: Added support for new Reusable Content block.
|
||||||
|
- 1f24fe4: Add support for icons style customization for sites
|
||||||
|
- 4c19014: Prevent search indexation for pages where it's configured as disabled
|
||||||
|
- 3422ad4: Update rendering of community ads to match new API response, and make it possible to preview ads.
|
||||||
|
- 1152445: Changed the alternative URL resolution criteria in order to support site URLs without /v/ prefix
|
||||||
|
- 2c437f7: Fix linking to a tab itself
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- aa32198: Avoid multiple <h1> in the page by using a <div> for the title in the header
|
||||||
|
- 51fa3ab: Adds content-visibility css property to OpenAPI Operation for better render performance
|
||||||
|
- a7066cc: Fix scroll position when navigating pages on mobile
|
||||||
|
- c754fc9: Add automatic color contrast in site header, restyle search button
|
||||||
|
- 5fe7adb: RND-3532: drop down menu for hidden links at small screen size
|
||||||
|
- 6295881: Change dark mode shadow for multi-space search toolbar
|
||||||
|
- f89b31c: Upgrade the scalar api client package
|
||||||
|
- 13c7534: Use ellipsis and fix icon color for more links in the header on small screen
|
||||||
|
- f885e88: Improve consistency of change request preview by removing cache-control on response
|
||||||
|
- 16e6171: Improve performances of loading pages with embeds by caching them
|
||||||
|
- 34d36c6: Fix GitBook specific static assets not being served correctly when deployed on Cloudflare
|
||||||
|
- af9e66e: Only display spaces dropdown in compact header when site is multi-variants
|
||||||
|
- e3a3d6a: Improve perception of fast loading by not rendering skeletons for individual blocks in the top part of the viewport
|
||||||
|
- 042b850: Automatically scroll to active item in TOC
|
||||||
|
- d43202f: Optimize bundle size of the server output by reducing bundle size of shiki (skipping themes)
|
||||||
|
- bfbed1a: Ensure "Sponsored via GitBook" can be translated in all languages
|
||||||
|
- fe9e6c1: Update ogimage with new design
|
||||||
|
- 17f71ba: Use url hash to open Expandable and scroll to anchor
|
||||||
|
- 3c07e65: Fix margin for paragraphs in quote blocks
|
||||||
|
- 636b868: Use new cache backend, powered by Durable Objects, alongside the existing ones (KV, etc).
|
||||||
|
- f16560c: Include offset in calculations of whether scrollable element is in view
|
||||||
|
- 689f553: Fix inconsistent click area in table because of scroll indicator
|
||||||
|
- 6ce3cea: Stop using KV cache backend for now, but also improves it for higher performances
|
||||||
|
- e914903: Synchronize response and response example tabs
|
||||||
|
- 0f990c7: Show definition title when visible in cards
|
||||||
|
- e3a3d6a: Fix flickering when displaying an "Ask" answer with code blocks
|
||||||
|
- 4cbcc5b: Rollback of scalar modal while fixing perf issue
|
||||||
|
- 3996110: Optimize images rendered in community ads
|
||||||
|
- 133c3e7: Update design of Checkbox to be more consistent and readable
|
||||||
|
- 5096f7f: Disable KV cache for docs.gitbook.com as a test, also disable it for change-request to improve consistency
|
||||||
|
- 0f1565c: Add optional env `GITBOOK_INTEGRATIONS_HOST` to configure the host serving the integrations
|
||||||
|
- 2ff7ed1: Fix table of contents being visible on mobile when disabled at the page level
|
||||||
|
- b075f0f: Fix accessibility of the table of contents by using `aria-current` instead of `aria-selected`
|
||||||
|
- cb782a7: Fix "ip" being passed to BSA for community ads
|
||||||
|
- a7af3ca: Improving the look and feel of new section tabs
|
||||||
|
- 0bf985a: Don't show hidden pages in the empty state of a page
|
||||||
|
- d6c28a0: Update header styling of sections, variant selector, and button links
|
||||||
|
|
||||||
|
- Change position of variant selector depending on context (next to logo or in table of contents)
|
||||||
|
- Update section tab styling and animation
|
||||||
|
- Make header buttons smaller with a new `medium` button size
|
||||||
|
|
||||||
|
- Updated dependencies [51fa3ab]
|
||||||
|
- Updated dependencies [9b8d519]
|
||||||
|
- Updated dependencies [cf3045a]
|
||||||
|
- Updated dependencies [f89b31c]
|
||||||
|
- Updated dependencies [d0f4860]
|
||||||
|
- Updated dependencies [ef9d012]
|
||||||
|
- Updated dependencies [094e9cd]
|
||||||
|
- Updated dependencies [636b868]
|
||||||
|
- Updated dependencies [56f5fa1]
|
||||||
|
- Updated dependencies [5c35f36]
|
||||||
|
- Updated dependencies [4247361]
|
||||||
|
- Updated dependencies [aa8c49e]
|
||||||
|
- Updated dependencies [e914903]
|
||||||
|
- Updated dependencies [4cbcc5b]
|
||||||
|
- Updated dependencies [0f1565c]
|
||||||
|
- Updated dependencies [237b703]
|
||||||
|
- Updated dependencies [51955da]
|
||||||
|
- Updated dependencies [a679e72]
|
||||||
|
- Updated dependencies [c079c3c]
|
||||||
|
- Updated dependencies [5c35f36]
|
||||||
|
- Updated dependencies [776bc31]
|
||||||
|
- @gitbook/react-openapi@0.7.0
|
||||||
|
- @gitbook/cache-do@0.1.0
|
||||||
|
- @gitbook/icons@0.1.0
|
||||||
|
- @gitbook/react-contentkit@0.5.1
|
||||||
|
- @gitbook/react-math@0.6.0
|
||||||
|
|
||||||
|
## 0.3.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- 24b785c: Update shiki for code block syntax highlighting, with support for more languages and fixes for diffs. It also patches the deployment on Cloudflare to support edge functions larger than 4MB.
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- acc3f2f: Fix error with the "Try it" of OpenAPI block because of the Scalar proxy failing on Cloudflare with the `cache` option
|
||||||
|
- Updated dependencies [709f1a1]
|
||||||
|
- Updated dependencies [ede2335]
|
||||||
|
- Updated dependencies [0426312]
|
||||||
|
- @gitbook/react-openapi@0.6.0
|
||||||
|
|
||||||
|
## 0.2.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [3445db4]
|
||||||
|
- @gitbook/react-contentkit@0.5.0
|
||||||
|
- @gitbook/react-openapi@0.5.0
|
||||||
|
- @gitbook/react-math@0.5.0
|
||||||
|
|
||||||
## 0.2.1
|
## 0.2.1
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"version": 1,
|
||||||
|
"exclude": ["/~gitbook/static/*"]
|
||||||
|
}
|
||||||
Vendored
+7
@@ -0,0 +1,7 @@
|
|||||||
|
import type { CacheObject } from '@gitbook/cache-do';
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface CloudflareEnv {
|
||||||
|
CACHE?: DurableObjectNamespace<CacheObject>;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,21 +1,29 @@
|
|||||||
import { argosScreenshot } from '@argos-ci/playwright';
|
import { argosScreenshot } from '@argos-ci/playwright';
|
||||||
import {
|
import {
|
||||||
|
CustomizationBackground,
|
||||||
|
CustomizationCorners,
|
||||||
|
CustomizationFont,
|
||||||
CustomizationHeaderPreset,
|
CustomizationHeaderPreset,
|
||||||
|
CustomizationIconsStyle,
|
||||||
CustomizationLocale,
|
CustomizationLocale,
|
||||||
CustomizationSettings,
|
CustomizationThemeMode,
|
||||||
|
SiteCustomizationSettings,
|
||||||
} from '@gitbook/api';
|
} from '@gitbook/api';
|
||||||
import { test, expect, Page } from '@playwright/test';
|
import { test, expect, Page } from '@playwright/test';
|
||||||
|
import deepMerge from 'deepmerge';
|
||||||
import jwt from 'jsonwebtoken';
|
import jwt from 'jsonwebtoken';
|
||||||
import rison from 'rison';
|
import rison from 'rison';
|
||||||
|
import { DeepPartial } from 'ts-essentials';
|
||||||
|
|
||||||
import { getContentTestURL } from '../tests/utils';
|
import { getContentTestURL } from '../tests/utils';
|
||||||
|
|
||||||
interface Test {
|
interface Test {
|
||||||
name: string;
|
name: string;
|
||||||
url: string;
|
url: string; // URL to visit for testing
|
||||||
run?: (page: Page) => Promise<unknown>;
|
run?: (page: Page) => Promise<unknown>; // The test to run
|
||||||
fullPage?: boolean;
|
fullPage?: boolean; // Whether the test should be fullscreened during testing
|
||||||
screenshot?: false;
|
screenshot?: false; // Should a screenshot be stored
|
||||||
|
only?: boolean; // Only run this test
|
||||||
}
|
}
|
||||||
|
|
||||||
interface TestsCase {
|
interface TestsCase {
|
||||||
@@ -31,6 +39,18 @@ const allLocales: CustomizationLocale[] = [
|
|||||||
CustomizationLocale.Zh,
|
CustomizationLocale.Zh,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const allThemeModes: CustomizationThemeMode[] = [
|
||||||
|
CustomizationThemeMode.Light,
|
||||||
|
CustomizationThemeMode.Dark,
|
||||||
|
];
|
||||||
|
|
||||||
|
const allThemePresets: CustomizationHeaderPreset[] = [
|
||||||
|
CustomizationHeaderPreset.Default,
|
||||||
|
CustomizationHeaderPreset.Bold,
|
||||||
|
CustomizationHeaderPreset.Contrast,
|
||||||
|
CustomizationHeaderPreset.Custom,
|
||||||
|
];
|
||||||
|
|
||||||
async function waitForCookiesDialog(page: Page) {
|
async function waitForCookiesDialog(page: Page) {
|
||||||
const dialog = page.getByRole('dialog', { name: 'Cookies' });
|
const dialog = page.getByRole('dialog', { name: 'Cookies' });
|
||||||
const accept = dialog.getByRole('button', { name: 'Accept' });
|
const accept = dialog.getByRole('button', { name: 'Accept' });
|
||||||
@@ -92,7 +112,9 @@ const testCases: TestsCase[] = [
|
|||||||
name: 'Variants dropdown',
|
name: 'Variants dropdown',
|
||||||
url: '',
|
url: '',
|
||||||
run: async (page) => {
|
run: async (page) => {
|
||||||
const spaceDrowpdown = page.locator('[data-testid="space-dropdown-button"]');
|
const spaceDrowpdown = page
|
||||||
|
.locator('[data-testid="space-dropdown-button"]')
|
||||||
|
.locator('visible=true');
|
||||||
await spaceDrowpdown.waitFor();
|
await spaceDrowpdown.waitFor();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -102,7 +124,34 @@ const testCases: TestsCase[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'RFC variant',
|
name: 'RFC variant',
|
||||||
url: 'v/rfcs',
|
url: 'rfcs',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Customized variant titles are displayed',
|
||||||
|
url: '',
|
||||||
|
run: async (page) => {
|
||||||
|
const spaceDrowpdown = page
|
||||||
|
.locator('[data-testid="space-dropdown-button"]')
|
||||||
|
.locator('visible=true');
|
||||||
|
await spaceDrowpdown.click();
|
||||||
|
|
||||||
|
const variantSelectionDropdown = page.locator(
|
||||||
|
'css=[data-testid="space-dropdown-button"] + div',
|
||||||
|
);
|
||||||
|
// the customized space title
|
||||||
|
await expect(
|
||||||
|
variantSelectionDropdown.getByRole('link', {
|
||||||
|
name: 'Multi-Variants',
|
||||||
|
}),
|
||||||
|
).toBeVisible();
|
||||||
|
|
||||||
|
// the NON-customized space title
|
||||||
|
await expect(
|
||||||
|
variantSelectionDropdown.getByRole('link', {
|
||||||
|
name: 'RFCs',
|
||||||
|
}),
|
||||||
|
).toBeVisible();
|
||||||
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@@ -115,9 +164,9 @@ const testCases: TestsCase[] = [
|
|||||||
url: 'api-multi-versions/reference/api-reference/pets',
|
url: 'api-multi-versions/reference/api-reference/pets',
|
||||||
screenshot: false,
|
screenshot: false,
|
||||||
run: async (page) => {
|
run: async (page) => {
|
||||||
const spaceDrowpdown = await page.waitForSelector(
|
const spaceDrowpdown = await page
|
||||||
'[data-testid="space-dropdown-button"]',
|
.locator('[data-testid="space-dropdown-button"]')
|
||||||
);
|
.locator('visible=true');
|
||||||
await spaceDrowpdown.click();
|
await spaceDrowpdown.click();
|
||||||
|
|
||||||
// Click the second variant in the dropdown
|
// Click the second variant in the dropdown
|
||||||
@@ -129,18 +178,18 @@ const testCases: TestsCase[] = [
|
|||||||
|
|
||||||
// It should keep the current page path, i.e "reference/api-reference/pets" when navigating to the new variant
|
// It should keep the current page path, i.e "reference/api-reference/pets" when navigating to the new variant
|
||||||
await page.waitForURL(
|
await page.waitForURL(
|
||||||
'https://gitbook-open-e2e-sites.gitbook.io/api-multi-versions/v/2.0/reference/api-reference/pets?fallback=true',
|
'https://gitbook-open-e2e-sites.gitbook.io/api-multi-versions/2.0/reference/api-reference/pets?fallback=true',
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Keep navigation path/route when switching variant (Share link)',
|
name: 'Keep navigation path/route when switching variant (Share link)',
|
||||||
url: 'api-multi-versions-share-links/bRfQbzwsK8rbN1GRxx7K/reference/api-reference/pets',
|
url: 'api-multi-versions-share-links/8tNo6MeXg7CkFMzSSz81/reference/api-reference/pets',
|
||||||
screenshot: false,
|
screenshot: false,
|
||||||
run: async (page) => {
|
run: async (page) => {
|
||||||
const spaceDrowpdown = await page.waitForSelector(
|
const spaceDrowpdown = await page
|
||||||
'[data-testid="space-dropdown-button"]',
|
.locator('[data-testid="space-dropdown-button"]')
|
||||||
);
|
.locator('visible=true');
|
||||||
await spaceDrowpdown.click();
|
await spaceDrowpdown.click();
|
||||||
|
|
||||||
// Click the second variant in the dropdown
|
// Click the second variant in the dropdown
|
||||||
@@ -152,7 +201,7 @@ const testCases: TestsCase[] = [
|
|||||||
|
|
||||||
// It should keep the current page path, i.e "reference/api-reference/pets" when navigating to the new variant
|
// It should keep the current page path, i.e "reference/api-reference/pets" when navigating to the new variant
|
||||||
await page.waitForURL(
|
await page.waitForURL(
|
||||||
'https://gitbook-open-e2e-sites.gitbook.io/api-multi-versions-share-links/bRfQbzwsK8rbN1GRxx7K/v/2.0/reference/api-reference/pets?fallback=true',
|
'https://gitbook-open-e2e-sites.gitbook.io/api-multi-versions-share-links/8tNo6MeXg7CkFMzSSz81/2.0/reference/api-reference/pets?fallback=true',
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -173,9 +222,9 @@ const testCases: TestsCase[] = [
|
|||||||
return `api-multi-versions-va/reference/api-reference/pets?jwt_token=${token}`;
|
return `api-multi-versions-va/reference/api-reference/pets?jwt_token=${token}`;
|
||||||
})(),
|
})(),
|
||||||
run: async (page) => {
|
run: async (page) => {
|
||||||
const spaceDrowpdown = await page.waitForSelector(
|
const spaceDrowpdown = await page
|
||||||
'[data-testid="space-dropdown-button"]',
|
.locator('[data-testid="space-dropdown-button"]')
|
||||||
);
|
.locator('visible=true');
|
||||||
await spaceDrowpdown.click();
|
await spaceDrowpdown.click();
|
||||||
|
|
||||||
// Click the second variant in the dropdown
|
// Click the second variant in the dropdown
|
||||||
@@ -187,7 +236,7 @@ const testCases: TestsCase[] = [
|
|||||||
|
|
||||||
// It should keep the current page path, i.e "reference/api-reference/pets" when navigating to the new variant
|
// It should keep the current page path, i.e "reference/api-reference/pets" when navigating to the new variant
|
||||||
await page.waitForURL(
|
await page.waitForURL(
|
||||||
'https://gitbook-open-e2e-sites.gitbook.io/api-multi-versions-va/v/2.0/reference/api-reference/pets?fallback=true',
|
'https://gitbook-open-e2e-sites.gitbook.io/api-multi-versions-va/2.0/reference/api-reference/pets?fallback=true',
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -230,7 +279,7 @@ const testCases: TestsCase[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Versioning',
|
name: 'Versioning',
|
||||||
baseUrl: 'https://gitbook.gitbook.io/test-1-1/',
|
baseUrl: 'https://gitbook.gitbook.io/test-gitbook-open/',
|
||||||
tests: [
|
tests: [
|
||||||
{
|
{
|
||||||
name: 'Revision',
|
name: 'Revision',
|
||||||
@@ -241,7 +290,7 @@ const testCases: TestsCase[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'PDF',
|
name: 'PDF',
|
||||||
baseUrl: 'https://gitbook.gitbook.io/test-1-1/',
|
baseUrl: 'https://gitbook.gitbook.io/test-gitbook-open/',
|
||||||
tests: [
|
tests: [
|
||||||
{
|
{
|
||||||
name: 'PDF',
|
name: 'PDF',
|
||||||
@@ -251,7 +300,7 @@ const testCases: TestsCase[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Content tests',
|
name: 'Content tests',
|
||||||
baseUrl: 'https://gitbook.gitbook.io/test-1-1/',
|
baseUrl: 'https://gitbook.gitbook.io/test-gitbook-open/',
|
||||||
tests: [
|
tests: [
|
||||||
{
|
{
|
||||||
name: 'Text',
|
name: 'Text',
|
||||||
@@ -344,11 +393,21 @@ const testCases: TestsCase[] = [
|
|||||||
name: 'Math',
|
name: 'Math',
|
||||||
url: 'blocks/math',
|
url: 'blocks/math',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'Files',
|
||||||
|
url: 'blocks/files',
|
||||||
|
fullPage: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'Embeds',
|
name: 'Embeds',
|
||||||
url: 'blocks/embeds',
|
url: 'blocks/embeds',
|
||||||
fullPage: true,
|
fullPage: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'Page links',
|
||||||
|
url: 'blocks/page-links',
|
||||||
|
fullPage: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'Annotations',
|
name: 'Annotations',
|
||||||
url: 'blocks/annotations',
|
url: 'blocks/annotations',
|
||||||
@@ -357,11 +416,15 @@ const testCases: TestsCase[] = [
|
|||||||
await page.click('[data-testid="annotation-button"]');
|
await page.click('[data-testid="annotation-button"]');
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'Stepper',
|
||||||
|
url: 'blocks/stepper',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Page options',
|
name: 'Page options',
|
||||||
baseUrl: 'https://gitbook.gitbook.io/test-1-1/',
|
baseUrl: 'https://gitbook.gitbook.io/test-gitbook-open/',
|
||||||
tests: [
|
tests: [
|
||||||
{
|
{
|
||||||
name: 'Hidden',
|
name: 'Hidden',
|
||||||
@@ -383,32 +446,227 @@ const testCases: TestsCase[] = [
|
|||||||
url: 'page-options/page-with-cover-and-no-toc',
|
url: 'page-options/page-with-cover-and-no-toc',
|
||||||
run: waitForCookiesDialog,
|
run: waitForCookiesDialog,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'With icon',
|
||||||
|
url: 'page-options/page-with-icon',
|
||||||
|
run: waitForCookiesDialog,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Customization',
|
name: 'Customization',
|
||||||
baseUrl: 'https://gitbook.gitbook.io/test-1-1/',
|
baseUrl: 'https://gitbook.gitbook.io/test-gitbook-open/',
|
||||||
tests: [
|
tests: allThemeModes.flatMap((theme) => [
|
||||||
{
|
{
|
||||||
name: 'Without header',
|
name: `Without header - Theme ${theme}`,
|
||||||
url: getCustomizationURL({
|
url: getCustomizationURL({
|
||||||
header: {
|
header: {
|
||||||
preset: CustomizationHeaderPreset.None,
|
preset: CustomizationHeaderPreset.None,
|
||||||
links: [],
|
links: [],
|
||||||
},
|
},
|
||||||
|
themes: {
|
||||||
|
default: theme,
|
||||||
|
toggeable: false,
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
run: waitForCookiesDialog,
|
run: waitForCookiesDialog,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: `With duotone icons - Theme ${theme}`,
|
||||||
|
url:
|
||||||
|
'page-options/page-with-icon' +
|
||||||
|
getCustomizationURL({
|
||||||
|
styling: {
|
||||||
|
icons: CustomizationIconsStyle.Duotone,
|
||||||
|
},
|
||||||
|
themes: {
|
||||||
|
default: theme,
|
||||||
|
toggeable: false,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
run: waitForCookiesDialog,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: `With header buttons - Theme ${theme}`,
|
||||||
|
url: getCustomizationURL({
|
||||||
|
header: {
|
||||||
|
preset: CustomizationHeaderPreset.Default,
|
||||||
|
links: [
|
||||||
|
{
|
||||||
|
title: 'Secondary button',
|
||||||
|
to: { kind: 'url', url: 'https://www.gitbook.com' },
|
||||||
|
style: 'button-secondary',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Primary button',
|
||||||
|
to: { kind: 'url', url: 'https://www.gitbook.com' },
|
||||||
|
style: 'button-primary',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
themes: {
|
||||||
|
default: theme,
|
||||||
|
toggeable: false,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
run: waitForCookiesDialog,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: `Without tint - Default preset - Theme ${theme}`,
|
||||||
|
url: getCustomizationURL({
|
||||||
|
header: {
|
||||||
|
preset: CustomizationHeaderPreset.Default,
|
||||||
|
links: [
|
||||||
|
{
|
||||||
|
title: 'Secondary button',
|
||||||
|
to: { kind: 'url', url: 'https://www.gitbook.com' },
|
||||||
|
style: 'button-secondary',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Primary button',
|
||||||
|
to: { kind: 'url', url: 'https://www.gitbook.com' },
|
||||||
|
style: 'button-primary',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
themes: {
|
||||||
|
default: theme,
|
||||||
|
toggeable: false,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
run: waitForCookiesDialog,
|
||||||
|
},
|
||||||
|
...allThemePresets.flatMap((preset) => ({
|
||||||
|
name: `With tint - Preset ${preset} - Theme ${theme}`,
|
||||||
|
url: getCustomizationURL({
|
||||||
|
styling: {
|
||||||
|
tint: { color: { light: '#346DDB', dark: '#346DDB' } },
|
||||||
|
},
|
||||||
|
header: {
|
||||||
|
preset,
|
||||||
|
...(preset === CustomizationHeaderPreset.Custom
|
||||||
|
? {
|
||||||
|
backgroundColor: { light: '#C62C68', dark: '#EF96B8' },
|
||||||
|
linkColor: { light: '#4DDE98', dark: '#0C693D' },
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
|
links: [
|
||||||
|
{
|
||||||
|
title: 'Secondary button',
|
||||||
|
to: { kind: 'url', url: 'https://www.gitbook.com' },
|
||||||
|
style: 'button-secondary',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Primary button',
|
||||||
|
to: { kind: 'url', url: 'https://www.gitbook.com' },
|
||||||
|
style: 'button-primary',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
themes: {
|
||||||
|
default: theme,
|
||||||
|
toggeable: false,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
run: waitForCookiesDialog,
|
||||||
|
})),
|
||||||
|
{
|
||||||
|
name: `With tint - Legacy background match - Theme ${theme}`,
|
||||||
|
url: getCustomizationURL({
|
||||||
|
styling: {
|
||||||
|
background: CustomizationBackground.Match,
|
||||||
|
},
|
||||||
|
header: {
|
||||||
|
preset: CustomizationHeaderPreset.Default,
|
||||||
|
links: [
|
||||||
|
{
|
||||||
|
title: 'Secondary button',
|
||||||
|
to: { kind: 'url', url: 'https://www.gitbook.com' },
|
||||||
|
style: 'button-secondary',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Primary button',
|
||||||
|
to: { kind: 'url', url: 'https://www.gitbook.com' },
|
||||||
|
style: 'button-primary',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
themes: {
|
||||||
|
default: theme,
|
||||||
|
toggeable: false,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
run: waitForCookiesDialog,
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Ads',
|
||||||
|
baseUrl: 'https://gitbook.gitbook.io/test-gitbook-open/',
|
||||||
|
tests: [
|
||||||
|
{
|
||||||
|
name: 'Without previewed ads',
|
||||||
|
url: 'text-page?ads_preview=1',
|
||||||
|
run: waitForCookiesDialog,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Shared space navigation (first site)',
|
||||||
|
baseUrl: 'https://gitbook-open-e2e-sites.gitbook.io/shared-space-uno/',
|
||||||
|
tests: [
|
||||||
|
{
|
||||||
|
name: 'Navigation to shared space',
|
||||||
|
url: '',
|
||||||
|
run: async (page) => {
|
||||||
|
const sharedSpaceLink = page.locator('a.underline');
|
||||||
|
await sharedSpaceLink.click();
|
||||||
|
expect(page.locator('h1')).toHaveText('shared');
|
||||||
|
const url = page.url();
|
||||||
|
expect(url.includes('shared-space-uno')).toBeTruthy(); // same uno site
|
||||||
|
expect(url.endsWith('/shared')).toBeTruthy(); // correct page
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Shared space navigation (second site)',
|
||||||
|
baseUrl: 'https://gitbook-open-e2e-sites.gitbook.io/shared-space-dos/',
|
||||||
|
tests: [
|
||||||
|
{
|
||||||
|
name: 'Navigation to shared space',
|
||||||
|
url: '',
|
||||||
|
run: async (page) => {
|
||||||
|
const sharedSpaceLink = page.locator('a.underline');
|
||||||
|
await sharedSpaceLink.click();
|
||||||
|
expect(page.locator('h1')).toHaveText('shared');
|
||||||
|
const url = page.url();
|
||||||
|
expect(url.includes('shared-space-dos')).toBeTruthy(); // same dos site
|
||||||
|
expect(url.endsWith('/shared')).toBeTruthy(); // correct page
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Site Redirects',
|
||||||
|
baseUrl: 'https://gitbook-open-e2e-sites.gitbook.io/gitbook-doc/',
|
||||||
|
tests: [
|
||||||
|
{
|
||||||
|
name: 'Redirect to SSO page',
|
||||||
|
url: 'a/redirect/to/sso',
|
||||||
|
run: async (page) => {
|
||||||
|
await expect(page.locator('h1')).toHaveText('SSO');
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Share links',
|
name: 'Share links',
|
||||||
baseUrl: 'https://gitbook.gitbook.io/test-share-links/',
|
baseUrl: 'https://gitbook.gitbook.io/gbo-tests-share-links/',
|
||||||
tests: [
|
tests: [
|
||||||
{
|
{
|
||||||
name: 'Valid link',
|
name: 'Valid link',
|
||||||
url: 'Fc6mMII9FKgnwm7qqynx/',
|
url: 'thDznyWXCeEoT55WB7HC/',
|
||||||
run: waitForCookiesDialog,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Invalid link',
|
name: 'Invalid link',
|
||||||
@@ -495,7 +753,7 @@ const testCases: TestsCase[] = [
|
|||||||
expiresIn: '24h',
|
expiresIn: '24h',
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
return `v/spacea?jwt_token=${token}`;
|
return `spacea?jwt_token=${token}`;
|
||||||
})(),
|
})(),
|
||||||
run: waitForCookiesDialog,
|
run: waitForCookiesDialog,
|
||||||
},
|
},
|
||||||
@@ -512,7 +770,7 @@ const testCases: TestsCase[] = [
|
|||||||
expiresIn: '24h',
|
expiresIn: '24h',
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
return `v/spaceb?jwt_token=${token}`;
|
return `spaceb?jwt_token=${token}`;
|
||||||
})(),
|
})(),
|
||||||
run: waitForCookiesDialog,
|
run: waitForCookiesDialog,
|
||||||
},
|
},
|
||||||
@@ -529,7 +787,7 @@ const testCases: TestsCase[] = [
|
|||||||
expiresIn: '24h',
|
expiresIn: '24h',
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
return `v/spacec?jwt_token=${token}`;
|
return `spacec?jwt_token=${token}`;
|
||||||
})(),
|
})(),
|
||||||
run: waitForCookiesDialog,
|
run: waitForCookiesDialog,
|
||||||
},
|
},
|
||||||
@@ -611,13 +869,12 @@ const testCases: TestsCase[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Languages',
|
name: 'Languages',
|
||||||
baseUrl: 'https://gitbook.gitbook.io/test-1-1/',
|
baseUrl: 'https://gitbook.gitbook.io/test-gitbook-open/',
|
||||||
tests: allLocales.map((locale) => ({
|
tests: allLocales.map((locale) => ({
|
||||||
name: locale,
|
name: locale,
|
||||||
url: getCustomizationURL({
|
url: getCustomizationURL({
|
||||||
internationalization: {
|
internationalization: {
|
||||||
locale,
|
locale,
|
||||||
inherit: false,
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
run: async (page) => {
|
run: async (page) => {
|
||||||
@@ -626,12 +883,236 @@ const testCases: TestsCase[] = [
|
|||||||
},
|
},
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'SEO',
|
||||||
|
baseUrl: 'https://gitbook.gitbook.io/test-gitbook-open/',
|
||||||
|
tests: [
|
||||||
|
{
|
||||||
|
name: `Index by default`,
|
||||||
|
url: '?x-gitbook-search-indexation=true',
|
||||||
|
screenshot: false,
|
||||||
|
run: async (page) => {
|
||||||
|
const metaRobots = page.locator('meta[name="robots"]');
|
||||||
|
await expect(metaRobots).toHaveAttribute('content', 'index, follow');
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: `Don't index noIndex`,
|
||||||
|
url: 'page-options/page-no-index?x-gitbook-search-indexation=true',
|
||||||
|
screenshot: false,
|
||||||
|
run: async (page) => {
|
||||||
|
const metaRobots = page.locator('meta[name="robots"]');
|
||||||
|
await expect(metaRobots).toHaveAttribute('content', 'noindex, nofollow');
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: `Don't index descendant of noIndex`,
|
||||||
|
url: 'page-options/page-no-index/descendant-of-page-no-index?x-gitbook-search-indexation=true',
|
||||||
|
screenshot: false,
|
||||||
|
run: async (page) => {
|
||||||
|
const metaRobots = page.locator('meta[name="robots"]');
|
||||||
|
await expect(metaRobots).toHaveAttribute('content', 'noindex, nofollow');
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: `Don't index noRobotsIndex`,
|
||||||
|
url: 'page-options/page-no-robots-index?x-gitbook-search-indexation=true',
|
||||||
|
screenshot: false,
|
||||||
|
run: async (page) => {
|
||||||
|
const metaRobots = page.locator('meta[name="robots"]');
|
||||||
|
await expect(metaRobots).toHaveAttribute('content', 'noindex, nofollow');
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: `Don't index descendant of noRobotsIndex`,
|
||||||
|
url: 'page-options/page-no-robots-index/descendant-of-page-no-robots-index?x-gitbook-search-indexation=true',
|
||||||
|
screenshot: false,
|
||||||
|
run: async (page) => {
|
||||||
|
const metaRobots = page.locator('meta[name="robots"]');
|
||||||
|
await expect(metaRobots).toHaveAttribute('content', 'noindex, nofollow');
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Adaptive Content - VA',
|
||||||
|
baseUrl: `https://gitbook-open-e2e-sites.gitbook.io/adaptive-content-va/`,
|
||||||
|
tests: [
|
||||||
|
{
|
||||||
|
name: 'isAlphaUser',
|
||||||
|
url: (() => {
|
||||||
|
const privateKey = 'afe09cdf-0f43-480a-b54c-8b1f62f174f9';
|
||||||
|
const token = jwt.sign(
|
||||||
|
{
|
||||||
|
name: 'gitbook-open-tests',
|
||||||
|
isAlphaUser: true,
|
||||||
|
},
|
||||||
|
privateKey,
|
||||||
|
{
|
||||||
|
expiresIn: '24h',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return `?jwt_token=${token}`;
|
||||||
|
})(),
|
||||||
|
run: async (page) => {
|
||||||
|
const alphaUserPage = page
|
||||||
|
.locator('a[class*="group\\/toclink"]')
|
||||||
|
.filter({ hasText: 'Alpha users' });
|
||||||
|
const betaUserPage = page
|
||||||
|
.locator('a[class*="group\\/toclink"]')
|
||||||
|
.filter({ hasText: 'Beta users' });
|
||||||
|
await expect(alphaUserPage).toBeVisible();
|
||||||
|
await expect(betaUserPage).toHaveCount(0);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'isBetaUser',
|
||||||
|
url: (() => {
|
||||||
|
const privateKey = 'afe09cdf-0f43-480a-b54c-8b1f62f174f9';
|
||||||
|
const token = jwt.sign(
|
||||||
|
{
|
||||||
|
name: 'gitbook-open-tests',
|
||||||
|
isBetaUser: true,
|
||||||
|
},
|
||||||
|
privateKey,
|
||||||
|
{
|
||||||
|
expiresIn: '24h',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return `?jwt_token=${token}`;
|
||||||
|
})(),
|
||||||
|
run: async (page) => {
|
||||||
|
const alphaUserPage = page
|
||||||
|
.locator('a[class*="group\\/toclink"]')
|
||||||
|
.filter({ hasText: 'Alpha users' });
|
||||||
|
const betaUserPage = page
|
||||||
|
.locator('a[class*="group\\/toclink"]')
|
||||||
|
.filter({ hasText: 'Beta users' });
|
||||||
|
await expect(betaUserPage).toBeVisible();
|
||||||
|
await expect(alphaUserPage).toHaveCount(0);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'isAlphaUser & isBetaUser',
|
||||||
|
url: (() => {
|
||||||
|
const privateKey = 'afe09cdf-0f43-480a-b54c-8b1f62f174f9';
|
||||||
|
const token = jwt.sign(
|
||||||
|
{
|
||||||
|
name: 'gitbook-open-tests',
|
||||||
|
isAlphaUser: true,
|
||||||
|
isBetaUser: true,
|
||||||
|
},
|
||||||
|
privateKey,
|
||||||
|
{
|
||||||
|
expiresIn: '24h',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return `?jwt_token=${token}`;
|
||||||
|
})(),
|
||||||
|
run: async (page) => {
|
||||||
|
const alphaUserPage = page
|
||||||
|
.locator('a[class*="group\\/toclink"]')
|
||||||
|
.filter({ hasText: 'Alpha users' });
|
||||||
|
const betaUserPage = page
|
||||||
|
.locator('a[class*="group\\/toclink"]')
|
||||||
|
.filter({ hasText: 'Beta users' });
|
||||||
|
await expect(alphaUserPage).toBeVisible();
|
||||||
|
await expect(betaUserPage).toBeVisible();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Tables',
|
||||||
|
baseUrl: 'https://gitbook.gitbook.io/test-gitbook-open/',
|
||||||
|
tests: [
|
||||||
|
{
|
||||||
|
name: 'Default table',
|
||||||
|
url: 'blocks/tables',
|
||||||
|
run: waitForCookiesDialog,
|
||||||
|
fullPage: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Table with straight corners',
|
||||||
|
url:
|
||||||
|
'blocks/tables' +
|
||||||
|
getCustomizationURL({
|
||||||
|
styling: {
|
||||||
|
corners: CustomizationCorners.Straight,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
run: waitForCookiesDialog,
|
||||||
|
fullPage: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Table with primary color',
|
||||||
|
url:
|
||||||
|
'blocks/tables' +
|
||||||
|
getCustomizationURL({
|
||||||
|
styling: {
|
||||||
|
tint: { color: { light: '#346DDB', dark: '#346DDB' } },
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
run: waitForCookiesDialog,
|
||||||
|
fullPage: true,
|
||||||
|
},
|
||||||
|
// Test dark mode for each variant
|
||||||
|
...allThemeModes.flatMap((theme) => [
|
||||||
|
{
|
||||||
|
name: `Table in ${theme} mode`,
|
||||||
|
url:
|
||||||
|
'blocks/tables' +
|
||||||
|
getCustomizationURL({
|
||||||
|
themes: {
|
||||||
|
default: theme,
|
||||||
|
toggeable: false,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
run: waitForCookiesDialog,
|
||||||
|
fullPage: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: `Table with straight corners in ${theme} mode`,
|
||||||
|
url:
|
||||||
|
'blocks/tables' +
|
||||||
|
getCustomizationURL({
|
||||||
|
styling: {
|
||||||
|
corners: CustomizationCorners.Straight,
|
||||||
|
},
|
||||||
|
themes: {
|
||||||
|
default: theme,
|
||||||
|
toggeable: false,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
run: waitForCookiesDialog,
|
||||||
|
fullPage: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: `Table with primary color in ${theme} mode`,
|
||||||
|
url:
|
||||||
|
'blocks/tables' +
|
||||||
|
getCustomizationURL({
|
||||||
|
styling: {
|
||||||
|
tint: { color: { light: '#346DDB', dark: '#346DDB' } },
|
||||||
|
},
|
||||||
|
themes: {
|
||||||
|
default: theme,
|
||||||
|
toggeable: false,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
run: waitForCookiesDialog,
|
||||||
|
fullPage: true,
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const testCase of testCases) {
|
for (const testCase of testCases) {
|
||||||
test.describe(testCase.name, () => {
|
test.describe(testCase.name, () => {
|
||||||
for (const testEntry of testCase.tests) {
|
for (const testEntry of testCase.tests) {
|
||||||
test(testEntry.name, async ({ page, baseURL }) => {
|
const testFn = testEntry.only ? test.only : test;
|
||||||
|
testFn(testEntry.name, async ({ page, baseURL }) => {
|
||||||
const contentUrl = new URL(testEntry.url, testCase.baseUrl);
|
const contentUrl = new URL(testEntry.url, testCase.baseUrl);
|
||||||
const url = getContentTestURL(contentUrl.toString(), baseURL);
|
const url = getContentTestURL(contentUrl.toString(), baseURL);
|
||||||
await page.goto(url);
|
await page.goto(url);
|
||||||
@@ -658,8 +1139,63 @@ for (const testCase of testCases) {
|
|||||||
/**
|
/**
|
||||||
* Create a URL with customization settings.
|
* Create a URL with customization settings.
|
||||||
*/
|
*/
|
||||||
function getCustomizationURL(partial: Partial<CustomizationSettings>): string {
|
function getCustomizationURL(partial: DeepPartial<SiteCustomizationSettings>): string {
|
||||||
const encoded = rison.encode_object(partial);
|
/**
|
||||||
|
* Default customization settings.
|
||||||
|
*
|
||||||
|
* The customization object passed to the URL should be a valid API settings object. Hence we extend the test with necessary defaults.
|
||||||
|
*/
|
||||||
|
const DEFAULT_CUSTOMIZATION: SiteCustomizationSettings = {
|
||||||
|
styling: {
|
||||||
|
primaryColor: { light: '#346DDB', dark: '#346DDB' },
|
||||||
|
corners: CustomizationCorners.Rounded,
|
||||||
|
font: CustomizationFont.Inter,
|
||||||
|
background: CustomizationBackground.Plain,
|
||||||
|
icons: CustomizationIconsStyle.Regular,
|
||||||
|
},
|
||||||
|
internationalization: {
|
||||||
|
locale: CustomizationLocale.En,
|
||||||
|
},
|
||||||
|
favicon: {},
|
||||||
|
header: {
|
||||||
|
preset: CustomizationHeaderPreset.Default,
|
||||||
|
links: [],
|
||||||
|
},
|
||||||
|
footer: {
|
||||||
|
groups: [],
|
||||||
|
},
|
||||||
|
themes: {
|
||||||
|
default: CustomizationThemeMode.Light,
|
||||||
|
toggeable: true,
|
||||||
|
},
|
||||||
|
pdf: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
feedback: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
aiSearch: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
advancedCustomization: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
git: {
|
||||||
|
showEditLink: false,
|
||||||
|
},
|
||||||
|
pagination: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
trademark: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
privacyPolicy: {
|
||||||
|
url: 'https://www.gitbook.com/privacy',
|
||||||
|
},
|
||||||
|
socialPreview: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
const encoded = rison.encode_object(deepMerge(DEFAULT_CUSTOMIZATION, partial));
|
||||||
|
|
||||||
const searchParams = new URLSearchParams();
|
const searchParams = new URLSearchParams();
|
||||||
searchParams.set('customization', encoded);
|
searchParams.set('customization', encoded);
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ module.exports = withSentryConfig(
|
|||||||
SENTRY_DSN: process.env.SENTRY_DSN ?? '',
|
SENTRY_DSN: process.env.SENTRY_DSN ?? '',
|
||||||
SENTRY_ENVIRONMENT: process.env.SENTRY_ENVIRONMENT ?? 'development',
|
SENTRY_ENVIRONMENT: process.env.SENTRY_ENVIRONMENT ?? 'development',
|
||||||
GITBOOK_ASSETS_PREFIX: process.env.GITBOOK_ASSETS_PREFIX,
|
GITBOOK_ASSETS_PREFIX: process.env.GITBOOK_ASSETS_PREFIX,
|
||||||
|
GITBOOK_ICONS_URL: process.env.GITBOOK_ICONS_URL,
|
||||||
|
GITBOOK_ICONS_TOKEN: process.env.GITBOOK_ICONS_TOKEN,
|
||||||
},
|
},
|
||||||
|
|
||||||
webpack(config, { dev, webpack }) {
|
webpack(config, { dev, webpack }) {
|
||||||
|
|||||||
@@ -1,24 +1,28 @@
|
|||||||
{
|
{
|
||||||
"name": "gitbook",
|
"name": "gitbook",
|
||||||
"version": "0.2.1",
|
"version": "0.5.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "env-cmd --silent -f ../../.env.local next dev",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"build:cloudflare": "next-on-pages",
|
"build:cloudflare": "next-on-pages --custom-entrypoint=./src/cloudflare-entrypoint.ts",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
"lint": "next lint",
|
"lint": "next lint",
|
||||||
"typecheck": "tsc --noEmit",
|
"typecheck": "tsc --noEmit",
|
||||||
"e2e": "playwright test",
|
"e2e": "playwright test",
|
||||||
"unit": "bun test {src,packages}",
|
"unit": "bun test {src,packages}",
|
||||||
"postinstall": "rm -rf ./public/~gitbook/static/mathjax@3.2.2 && mkdir -p ./public/~gitbook/static/ && cp -R ../../node_modules/mathjax/es5 ./public/~gitbook/static/mathjax@3.2.2"
|
"generate": "gitbook-icons ./public/~gitbook/static/icons custom-icons && gitbook-math ./public/~gitbook/static/math",
|
||||||
|
"copy:icons": "gitbook-icons ./public/~gitbook/static/icons",
|
||||||
|
"clean": "rm -rf ./.next && rm -rf ./public/~gitbook/static"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@geist-ui/icons": "^1.0.2",
|
"@gitbook/api": "^0.81.0",
|
||||||
"@gitbook/api": "^0.56.0",
|
"@gitbook/cache-do": "workspace:*",
|
||||||
|
"@gitbook/emoji-codepoints": "workspace:*",
|
||||||
|
"@gitbook/icons": "workspace:*",
|
||||||
|
"@gitbook/react-contentkit": "workspace:*",
|
||||||
"@gitbook/react-math": "workspace:*",
|
"@gitbook/react-math": "workspace:*",
|
||||||
"@gitbook/react-openapi": "workspace:*",
|
"@gitbook/react-openapi": "workspace:*",
|
||||||
"@gitbook/react-contentkit": "workspace:*",
|
|
||||||
"@radix-ui/react-checkbox": "^1.0.4",
|
"@radix-ui/react-checkbox": "^1.0.4",
|
||||||
"@radix-ui/react-popover": "^1.0.7",
|
"@radix-ui/react-popover": "^1.0.7",
|
||||||
"@sentry/nextjs": "^7.94.1",
|
"@sentry/nextjs": "^7.94.1",
|
||||||
@@ -37,15 +41,16 @@
|
|||||||
"katex": "^0.16.9",
|
"katex": "^0.16.9",
|
||||||
"mathjax": "^3.2.2",
|
"mathjax": "^3.2.2",
|
||||||
"memoizee": "^0.4.15",
|
"memoizee": "^0.4.15",
|
||||||
"next": "^14.1.3",
|
"next": "14.2.15",
|
||||||
"next-themes": "^0.2.1",
|
"next-themes": "^0.2.1",
|
||||||
"nuqs": "^1.17.4",
|
"nuqs": "^1.17.4",
|
||||||
"object-hash": "^3.0.0",
|
"object-hash": "^3.0.0",
|
||||||
"openapi-types": "^12.1.3",
|
"openapi-types": "^12.1.3",
|
||||||
"p-map": "^7.0.0",
|
"p-map": "^7.0.0",
|
||||||
"parse-cache-control": "^1.0.1",
|
"parse-cache-control": "^1.0.1",
|
||||||
"react": "^18",
|
"postcss-color-contrast": "^1.1.0",
|
||||||
"react-dom": "^18",
|
"react": "18.3.1",
|
||||||
|
"react-dom": "18.3.1",
|
||||||
"react-hotkeys-hook": "^4.4.1",
|
"react-hotkeys-hook": "^4.4.1",
|
||||||
"recoil": "^0.7.7",
|
"recoil": "^0.7.7",
|
||||||
"rehype-sanitize": "^6.0.0",
|
"rehype-sanitize": "^6.0.0",
|
||||||
@@ -55,7 +60,7 @@
|
|||||||
"remark-rehype": "^11.1.0",
|
"remark-rehype": "^11.1.0",
|
||||||
"rison": "^0.1.1",
|
"rison": "^0.1.1",
|
||||||
"server-only": "^0.0.1",
|
"server-only": "^0.0.1",
|
||||||
"shiki": "^1.2.0",
|
"shiki": "^1.23.1",
|
||||||
"tailwind-merge": "^2.2.0",
|
"tailwind-merge": "^2.2.0",
|
||||||
"tailwind-shades": "^1.1.2",
|
"tailwind-shades": "^1.1.2",
|
||||||
"unified": "^11.0.4",
|
"unified": "^11.0.4",
|
||||||
@@ -63,9 +68,9 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@argos-ci/playwright": "^2.0.0",
|
"@argos-ci/playwright": "^2.0.0",
|
||||||
|
"@cloudflare/next-on-pages": "^1.13.5",
|
||||||
|
"@cloudflare/workers-types": "^4.20240725.0",
|
||||||
"@playwright/test": "^1.42.1",
|
"@playwright/test": "^1.42.1",
|
||||||
"@cloudflare/next-on-pages": "^1.11.3",
|
|
||||||
"@cloudflare/workers-types": "^4.20231218.0",
|
|
||||||
"@types/js-cookie": "^3.0.6",
|
"@types/js-cookie": "^3.0.6",
|
||||||
"@types/jsontoxml": "^1.0.5",
|
"@types/jsontoxml": "^1.0.5",
|
||||||
"@types/jsonwebtoken": "^9.0.6",
|
"@types/jsonwebtoken": "^9.0.6",
|
||||||
@@ -73,10 +78,12 @@
|
|||||||
"@types/object-hash": "^3.0.6",
|
"@types/object-hash": "^3.0.6",
|
||||||
"@types/parse-cache-control": "^1.0.4",
|
"@types/parse-cache-control": "^1.0.4",
|
||||||
"@types/psi": "^4.1.6",
|
"@types/psi": "^4.1.6",
|
||||||
"@types/react": "^18.3.3",
|
"@types/react": "18.3.13",
|
||||||
"@types/react-dom": "^18.3.0",
|
"@types/react-dom": "18.3.1",
|
||||||
"@types/rison": "^0.0.9",
|
"@types/rison": "^0.0.9",
|
||||||
"autoprefixer": "^10",
|
"autoprefixer": "^10",
|
||||||
|
"deepmerge": "^4.3.1",
|
||||||
|
"env-cmd": "^10.1.0",
|
||||||
"eslint": "^8",
|
"eslint": "^8",
|
||||||
"eslint-config-next": "^14.2.5",
|
"eslint-config-next": "^14.2.5",
|
||||||
"eslint-plugin-import": "^2.29.1",
|
"eslint-plugin-import": "^2.29.1",
|
||||||
@@ -84,6 +91,7 @@
|
|||||||
"postcss": "^8",
|
"postcss": "^8",
|
||||||
"psi": "^4.1.0",
|
"psi": "^4.1.0",
|
||||||
"tailwindcss": "^3.4.0",
|
"tailwindcss": "^3.4.0",
|
||||||
|
"ts-essentials": "^10.0.1",
|
||||||
"typescript": "^5.5.3"
|
"typescript": "^5.5.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# GitBook immutable static assets
|
||||||
|
/~gitbook/static/*
|
||||||
|
cache-control: public,max-age=31536000,immutable
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
@@ -4,6 +4,7 @@ import {
|
|||||||
verifyImageSignature,
|
verifyImageSignature,
|
||||||
resizeImage,
|
resizeImage,
|
||||||
CloudflareImageOptions,
|
CloudflareImageOptions,
|
||||||
|
imagesResizingSignVersion,
|
||||||
checkIsSizableImageURL,
|
checkIsSizableImageURL,
|
||||||
} from '@/lib/images';
|
} from '@/lib/images';
|
||||||
import { parseImageAPIURL } from '@/lib/urls';
|
import { parseImageAPIURL } from '@/lib/urls';
|
||||||
@@ -18,28 +19,29 @@ export const runtime = 'edge';
|
|||||||
export async function GET(request: NextRequest) {
|
export async function GET(request: NextRequest) {
|
||||||
let urlParam = request.nextUrl.searchParams.get('url');
|
let urlParam = request.nextUrl.searchParams.get('url');
|
||||||
const signature = request.nextUrl.searchParams.get('sign');
|
const signature = request.nextUrl.searchParams.get('sign');
|
||||||
// The current signature algorithm sets version as 1, but we need to support the older version as well
|
|
||||||
// for previously generated content. In this case, we default to version 0.
|
// The current signature algorithm sets version as 2, but we need to support the older version as well
|
||||||
const signatureVersion = (request.nextUrl.searchParams.get('sv') as '1') || '0';
|
const signatureVersion = request.nextUrl.searchParams.get('sv') as string | undefined;
|
||||||
if (!urlParam || !signature) {
|
if (!urlParam || !signature) {
|
||||||
return new Response('Missing url/sign parameters', { status: 400 });
|
return new Response('Missing url/sign parameters', { status: 400 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = parseImageAPIURL(urlParam);
|
const url = parseImageAPIURL(urlParam);
|
||||||
|
|
||||||
// Prevent infinite loops
|
|
||||||
if (url.includes('/~gitbook/image')) {
|
|
||||||
return new Response('Invalid url parameter', { status: 400 });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check again if the image can be sized, even though we checked when rendering the Image component
|
// Check again if the image can be sized, even though we checked when rendering the Image component
|
||||||
// Otherwise, it's possible to pass just any link to this endpoint and trigger HTML injection on the domain
|
// Otherwise, it's possible to pass just any link to this endpoint and trigger HTML injection on the domain
|
||||||
|
// Also prevent infinite redirects.
|
||||||
if (!checkIsSizableImageURL(url)) {
|
if (!checkIsSizableImageURL(url)) {
|
||||||
return new Response('Invalid url parameter', { status: 400 });
|
return new Response('Invalid url parameter', { status: 400 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For older signatures, we redirect to the url.
|
||||||
|
if (signatureVersion !== imagesResizingSignVersion) {
|
||||||
|
return Response.redirect(url, 302);
|
||||||
|
}
|
||||||
|
|
||||||
// Verify the signature
|
// Verify the signature
|
||||||
const verified = await verifyImageSignature(url, { signature, version: signatureVersion });
|
const verified = await verifyImageSignature(url, { signature });
|
||||||
if (!verified) {
|
if (!verified) {
|
||||||
return new Response(`Invalid signature "${signature ?? ''}" for "${url}"`, { status: 400 });
|
return new Response(`Invalid signature "${signature ?? ''}" for "${url}"`, { status: 400 });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ export async function POST(req: NextRequest) {
|
|||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
success: true,
|
success: true,
|
||||||
keys: result.keys,
|
|
||||||
stats: result.stats,
|
stats: result.stats,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -3,15 +3,15 @@
|
|||||||
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { useScrollToHash } from '@/components/hooks';
|
import { useScrollPage } from '@/components/hooks';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client component to initialize interactivity for a page.
|
* Client component to initialize interactivity for a page.
|
||||||
*/
|
*/
|
||||||
export function PageClientLayout(props: {}) {
|
export function PageClientLayout(props: { withSections?: boolean }) {
|
||||||
// We use this hook in the page layout to ensure the elements for the blocks
|
// We use this hook in the page layout to ensure the elements for the blocks
|
||||||
// are rendered before we scroll to the hash.
|
// are rendered before we scroll to a hash or to the top of the page
|
||||||
useScrollToHash();
|
useScrollPage({ scrollMarginTop: props.withSections ? 50 : undefined });
|
||||||
|
|
||||||
useStripFallbackQueryParam();
|
useStripFallbackQueryParam();
|
||||||
return null;
|
return null;
|
||||||
+1
-1
@@ -19,7 +19,7 @@ export default function PageSkeleton() {
|
|||||||
'lg:items-start',
|
'lg:items-start',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className={tcls('flex-1', 'max-w-3xl', 'mx-auto')}>
|
<div className={tcls('flex-1', 'max-w-3xl', 'mx-auto', 'page-full-width:mx-0')}>
|
||||||
<SkeletonHeading style={tcls('mb-8')} />
|
<SkeletonHeading style={tcls('mb-8')} />
|
||||||
<SkeletonParagraph style={tcls('mb-4')} />
|
<SkeletonParagraph style={tcls('mb-4')} />
|
||||||
</div>
|
</div>
|
||||||
+4
-7
@@ -1,14 +1,11 @@
|
|||||||
import { getSpaceLanguage, t } from '@/intl/server';
|
import { getSpaceLanguage, t } from '@/intl/server';
|
||||||
import { getCurrentSiteLayoutData, getSpaceLayoutData } from '@/lib/api';
|
import { getSiteData } from '@/lib/api';
|
||||||
|
import { getSiteContentPointer } from '@/lib/pointer';
|
||||||
import { tcls } from '@/lib/tailwind';
|
import { tcls } from '@/lib/tailwind';
|
||||||
|
|
||||||
import { getContentPointer } from '../../fetch';
|
|
||||||
|
|
||||||
export default async function NotFound() {
|
export default async function NotFound() {
|
||||||
const pointer = getContentPointer();
|
const pointer = getSiteContentPointer();
|
||||||
const { customization } = await ('siteId' in pointer
|
const { customization } = await getSiteData(pointer);
|
||||||
? getCurrentSiteLayoutData(pointer)
|
|
||||||
: getSpaceLayoutData(pointer.spaceId));
|
|
||||||
|
|
||||||
const language = getSpaceLanguage(customization);
|
const language = getSpaceLanguage(customization);
|
||||||
|
|
||||||
+34
-20
@@ -8,6 +8,7 @@ import { PageBody, PageCover } from '@/components/PageBody';
|
|||||||
import { PageHrefContext, absoluteHref, pageHref } from '@/lib/links';
|
import { PageHrefContext, absoluteHref, pageHref } from '@/lib/links';
|
||||||
import { getPagePath, resolveFirstDocument } from '@/lib/pages';
|
import { getPagePath, resolveFirstDocument } from '@/lib/pages';
|
||||||
import { ContentRefContext } from '@/lib/references';
|
import { ContentRefContext } from '@/lib/references';
|
||||||
|
import { isSpaceIndexable, isPageIndexable } from '@/lib/seo';
|
||||||
import { tcls } from '@/lib/tailwind';
|
import { tcls } from '@/lib/tailwind';
|
||||||
import { getContentTitle } from '@/lib/utils';
|
import { getContentTitle } from '@/lib/utils';
|
||||||
|
|
||||||
@@ -28,11 +29,13 @@ export default async function Page(props: {
|
|||||||
const {
|
const {
|
||||||
content: contentPointer,
|
content: contentPointer,
|
||||||
contentTarget,
|
contentTarget,
|
||||||
|
sections,
|
||||||
space,
|
space,
|
||||||
parent,
|
site,
|
||||||
customization,
|
customization,
|
||||||
pages,
|
pages,
|
||||||
page,
|
page,
|
||||||
|
ancestors,
|
||||||
document,
|
document,
|
||||||
} = await getPageDataWithFallback({
|
} = await getPageDataWithFallback({
|
||||||
pagePathParams: params,
|
pagePathParams: params,
|
||||||
@@ -64,47 +67,53 @@ export default async function Page(props: {
|
|||||||
const withPageFeedback = customization.feedback.enabled;
|
const withPageFeedback = customization.feedback.enabled;
|
||||||
|
|
||||||
const contentRefContext: ContentRefContext = {
|
const contentRefContext: ContentRefContext = {
|
||||||
|
siteContext: contentPointer,
|
||||||
space,
|
space,
|
||||||
revisionId: contentTarget.revisionId,
|
revisionId: contentTarget.revisionId,
|
||||||
pages,
|
pages,
|
||||||
page,
|
page,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const withSections = Boolean(sections && sections.list.length > 0);
|
||||||
|
const headerOffset = { sectionsHeader: withSections, topHeader: withTopHeader };
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{withFullPageCover && page.cover ? (
|
{withFullPageCover && page.cover ? (
|
||||||
<PageCover as="full" page={page} cover={page.cover} context={contentRefContext} />
|
<PageCover as="full" page={page} cover={page.cover} context={contentRefContext} />
|
||||||
) : null}
|
) : null}
|
||||||
<div className={tcls('flex', 'flex-row')}>
|
{/* We use a flex row reverse to render the aside first because the page is streamed. */}
|
||||||
|
<div className="flex flex-row-reverse justify-end">
|
||||||
|
{page.layout.outline ? (
|
||||||
|
<PageAside
|
||||||
|
space={space}
|
||||||
|
site={site}
|
||||||
|
customization={customization}
|
||||||
|
page={page}
|
||||||
|
document={document}
|
||||||
|
withHeaderOffset={headerOffset}
|
||||||
|
withFullPageCover={withFullPageCover}
|
||||||
|
withPageFeedback={withPageFeedback}
|
||||||
|
context={contentRefContext}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
<PageBody
|
<PageBody
|
||||||
space={space}
|
space={space}
|
||||||
contentPointer={contentPointer}
|
pointer={contentPointer}
|
||||||
contentTarget={contentTarget}
|
contentTarget={contentTarget}
|
||||||
customization={customization}
|
customization={customization}
|
||||||
context={contentRefContext}
|
context={contentRefContext}
|
||||||
page={page}
|
page={page}
|
||||||
|
ancestors={ancestors}
|
||||||
document={document}
|
document={document}
|
||||||
withPageFeedback={
|
withPageFeedback={
|
||||||
// Display the page feedback in the page footer if the aside is not visible
|
// Display the page feedback in the page footer if the aside is not visible
|
||||||
withPageFeedback && !page.layout.outline
|
withPageFeedback && !page.layout.outline
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
{page.layout.outline ? (
|
|
||||||
<PageAside
|
|
||||||
space={space}
|
|
||||||
site={parent?.object === 'site' ? parent : undefined}
|
|
||||||
customization={customization}
|
|
||||||
page={page}
|
|
||||||
document={document}
|
|
||||||
withHeaderOffset={withTopHeader}
|
|
||||||
withFullPageCover={withFullPageCover}
|
|
||||||
withPageFeedback={withPageFeedback}
|
|
||||||
context={contentRefContext}
|
|
||||||
/>
|
|
||||||
) : null}
|
|
||||||
</div>
|
</div>
|
||||||
<React.Suspense fallback={null}>
|
<React.Suspense fallback={null}>
|
||||||
<PageClientLayout />
|
<PageClientLayout withSections={withSections} />
|
||||||
</React.Suspense>
|
</React.Suspense>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
@@ -128,7 +137,7 @@ export async function generateMetadata({
|
|||||||
params: PagePathParams;
|
params: PagePathParams;
|
||||||
searchParams: { fallback?: string };
|
searchParams: { fallback?: string };
|
||||||
}): Promise<Metadata> {
|
}): Promise<Metadata> {
|
||||||
const { space, pages, page, customization, parent } = await getPageDataWithFallback({
|
const { space, pages, page, customization, site, ancestors } = await getPageDataWithFallback({
|
||||||
pagePathParams: params,
|
pagePathParams: params,
|
||||||
searchParams,
|
searchParams,
|
||||||
});
|
});
|
||||||
@@ -138,12 +147,13 @@ export async function generateMetadata({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: [page.title, getContentTitle(space, customization, parent)]
|
title: [page.title, getContentTitle(space, customization, site ?? null)]
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.join(' | '),
|
.join(' | '),
|
||||||
description: page.description ?? '',
|
description: page.description ?? '',
|
||||||
alternates: {
|
alternates: {
|
||||||
canonical: absoluteHref(getPagePath(pages, page), true),
|
// Trim trailing slashes in canonical URL to match the redirect behavior
|
||||||
|
canonical: absoluteHref(getPagePath(pages, page), true).replace(/\/+$/, ''),
|
||||||
},
|
},
|
||||||
openGraph: {
|
openGraph: {
|
||||||
images: [
|
images: [
|
||||||
@@ -151,6 +161,10 @@ export async function generateMetadata({
|
|||||||
absoluteHref(`~gitbook/ogimage/${page.id}`, true),
|
absoluteHref(`~gitbook/ogimage/${page.id}`, true),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
robots:
|
||||||
|
isSpaceIndexable({ space, site: site ?? null }) && isPageIndexable(ancestors, page)
|
||||||
|
? 'index, follow'
|
||||||
|
: 'noindex, nofollow',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
+12
-10
@@ -13,12 +13,12 @@ import { assetsDomain } from '@/lib/assets';
|
|||||||
import { buildVersion } from '@/lib/build';
|
import { buildVersion } from '@/lib/build';
|
||||||
import { getContentSecurityPolicyNonce } from '@/lib/csp';
|
import { getContentSecurityPolicyNonce } from '@/lib/csp';
|
||||||
import { absoluteHref, baseUrl } from '@/lib/links';
|
import { absoluteHref, baseUrl } from '@/lib/links';
|
||||||
import { shouldIndexSpace } from '@/lib/seo';
|
import { isSpaceIndexable } from '@/lib/seo';
|
||||||
import { getContentTitle } from '@/lib/utils';
|
import { getContentTitle } from '@/lib/utils';
|
||||||
|
|
||||||
import { ClientContexts } from './ClientContexts';
|
import { ClientContexts } from './ClientContexts';
|
||||||
import { RocketLoaderDetector } from './RocketLoaderDetector';
|
import { RocketLoaderDetector } from './RocketLoaderDetector';
|
||||||
import { fetchSpaceData } from '../fetch';
|
import { fetchContentData } from '../fetch';
|
||||||
|
|
||||||
export const runtime = 'edge';
|
export const runtime = 'edge';
|
||||||
|
|
||||||
@@ -35,13 +35,14 @@ export default async function ContentLayout(props: { children: React.ReactNode }
|
|||||||
contentTarget,
|
contentTarget,
|
||||||
customization,
|
customization,
|
||||||
pages,
|
pages,
|
||||||
parent,
|
site,
|
||||||
spaces,
|
spaces,
|
||||||
ancestors,
|
ancestors,
|
||||||
scripts,
|
scripts,
|
||||||
} = await fetchSpaceData();
|
sections,
|
||||||
|
} = await fetchContentData();
|
||||||
|
|
||||||
ReactDOM.preconnect(api().endpoint);
|
ReactDOM.preconnect(api().client.endpoint);
|
||||||
if (assetsDomain) {
|
if (assetsDomain) {
|
||||||
ReactDOM.preconnect(assetsDomain);
|
ReactDOM.preconnect(assetsDomain);
|
||||||
}
|
}
|
||||||
@@ -64,8 +65,9 @@ export default async function ContentLayout(props: { children: React.ReactNode }
|
|||||||
<SpaceLayout
|
<SpaceLayout
|
||||||
space={space}
|
space={space}
|
||||||
contentTarget={contentTarget}
|
contentTarget={contentTarget}
|
||||||
parent={parent}
|
site={site}
|
||||||
spaces={spaces}
|
spaces={spaces}
|
||||||
|
sections={sections}
|
||||||
customization={customization}
|
customization={customization}
|
||||||
pages={pages}
|
pages={pages}
|
||||||
ancestors={ancestors}
|
ancestors={ancestors}
|
||||||
@@ -97,7 +99,7 @@ export default async function ContentLayout(props: { children: React.ReactNode }
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function generateViewport(): Promise<Viewport> {
|
export async function generateViewport(): Promise<Viewport> {
|
||||||
const { customization } = await fetchSpaceData();
|
const { customization } = await fetchContentData();
|
||||||
return {
|
return {
|
||||||
colorScheme: customization.themes.toggeable
|
colorScheme: customization.themes.toggeable
|
||||||
? customization.themes.default === CustomizationThemeMode.Dark
|
? customization.themes.default === CustomizationThemeMode.Dark
|
||||||
@@ -108,11 +110,11 @@ export async function generateViewport(): Promise<Viewport> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function generateMetadata(): Promise<Metadata> {
|
export async function generateMetadata(): Promise<Metadata> {
|
||||||
const { space, parent, customization } = await fetchSpaceData();
|
const { space, site, customization } = await fetchContentData();
|
||||||
const customIcon = 'icon' in customization.favicon ? customization.favicon.icon : null;
|
const customIcon = 'icon' in customization.favicon ? customization.favicon.icon : null;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: getContentTitle(space, customization, parent),
|
title: getContentTitle(space, customization, site),
|
||||||
generator: `GitBook (${buildVersion()})`,
|
generator: `GitBook (${buildVersion()})`,
|
||||||
metadataBase: new URL(baseUrl()),
|
metadataBase: new URL(baseUrl()),
|
||||||
icons: {
|
icons: {
|
||||||
@@ -133,7 +135,7 @@ export async function generateMetadata(): Promise<Metadata> {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
robots: shouldIndexSpace({ space, parent }) ? 'index, follow' : 'noindex, nofollow',
|
robots: isSpaceIndexable({ space, site }) ? 'index, follow' : 'noindex, nofollow',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import { NextRequest } from 'next/server';
|
||||||
|
|
||||||
|
import { getSpace, getSite } from '@/lib/api';
|
||||||
|
import { absoluteHref } from '@/lib/links';
|
||||||
|
import { getSiteContentPointer } from '@/lib/pointer';
|
||||||
|
import { isSpaceIndexable } from '@/lib/seo';
|
||||||
|
|
||||||
|
export const runtime = 'edge';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a robots.txt for the current space.
|
||||||
|
*/
|
||||||
|
export async function GET(req: NextRequest) {
|
||||||
|
const pointer = getSiteContentPointer();
|
||||||
|
const [site, space] = await Promise.all([
|
||||||
|
getSite(pointer.organizationId, pointer.siteId),
|
||||||
|
getSpace(pointer.spaceId, pointer.siteShareKey),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const lines = [
|
||||||
|
`User-agent: *`,
|
||||||
|
'Disallow: /~gitbook/',
|
||||||
|
...(isSpaceIndexable({ space, site })
|
||||||
|
? [`Allow: /`, `Sitemap: ${absoluteHref(`/sitemap.xml`, true)}`]
|
||||||
|
: [`Disallow: /`]),
|
||||||
|
];
|
||||||
|
const content = lines.join('\n');
|
||||||
|
|
||||||
|
return new Response(content, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'text/plain',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
+17
-8
@@ -5,8 +5,8 @@ import { NextRequest } from 'next/server';
|
|||||||
import { getSpaceContentData } from '@/lib/api';
|
import { getSpaceContentData } from '@/lib/api';
|
||||||
import { absoluteHref } from '@/lib/links';
|
import { absoluteHref } from '@/lib/links';
|
||||||
import { getPagePath } from '@/lib/pages';
|
import { getPagePath } from '@/lib/pages';
|
||||||
|
import { getSiteContentPointer } from '@/lib/pointer';
|
||||||
import { getContentPointer } from '../../fetch';
|
import { isPageIndexable } from '@/lib/seo';
|
||||||
|
|
||||||
export const runtime = 'edge';
|
export const runtime = 'edge';
|
||||||
|
|
||||||
@@ -14,8 +14,10 @@ export const runtime = 'edge';
|
|||||||
* Generate a sitemap.xml for the current space.
|
* Generate a sitemap.xml for the current space.
|
||||||
*/
|
*/
|
||||||
export async function GET(req: NextRequest) {
|
export async function GET(req: NextRequest) {
|
||||||
const { pages: rootPages } = await getSpaceContentData(getContentPointer());
|
const pointer = getSiteContentPointer();
|
||||||
const pages = flattenPages(rootPages, (page) => !page.hidden);
|
const { pages: rootPages } = await getSpaceContentData(pointer, pointer.siteShareKey);
|
||||||
|
|
||||||
|
const pages = flattenPages(rootPages, (page) => !page.hidden && isPageIndexable([], page));
|
||||||
const urls = pages.map(({ page, depth }) => {
|
const urls = pages.map(({ page, depth }) => {
|
||||||
// Decay priority with depth
|
// Decay priority with depth
|
||||||
const priority = Math.pow(2, -0.25 * depth);
|
const priority = Math.pow(2, -0.25 * depth);
|
||||||
@@ -68,19 +70,26 @@ type FlatPageEntry = { page: RevisionPageDocument; depth: number };
|
|||||||
|
|
||||||
function flattenPages(
|
function flattenPages(
|
||||||
rootPags: RevisionPage[],
|
rootPags: RevisionPage[],
|
||||||
filter: (page: RevisionPageDocument) => boolean,
|
filter: (page: RevisionPageDocument | RevisionPageGroup) => boolean,
|
||||||
): FlatPageEntry[] {
|
): FlatPageEntry[] {
|
||||||
const flattenPage = (
|
const flattenPage = (
|
||||||
page: RevisionPageDocument | RevisionPageGroup,
|
page: RevisionPageDocument | RevisionPageGroup,
|
||||||
depth: number,
|
depth: number,
|
||||||
): FlatPageEntry[] => {
|
): FlatPageEntry[] => {
|
||||||
|
const allowed = filter(page);
|
||||||
|
if (!allowed) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
...(page.type === 'document' && filter(page) ? [{ page, depth }] : []),
|
...(page.type === 'document' ? [{ page, depth }] : []),
|
||||||
...page.pages.flatMap((child) =>
|
...page.pages.flatMap((child) =>
|
||||||
child.type === 'link' ? [] : flattenPage(child, depth + 1),
|
child.type === 'document' ? flattenPage(child, depth + 1) : [],
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
return rootPags.flatMap((page) => (page.type === 'link' ? [] : flattenPage(page, 0)));
|
return rootPags.flatMap((page) =>
|
||||||
|
page.type === 'group' || page.type === 'document' ? flattenPage(page, 0) : [],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
+8
-20
@@ -1,18 +1,11 @@
|
|||||||
import { ContentVisibility } from '@gitbook/api';
|
|
||||||
import { notFound } from 'next/navigation';
|
import { notFound } from 'next/navigation';
|
||||||
import { ImageResponse } from 'next/og';
|
import { ImageResponse } from 'next/og';
|
||||||
import { NextRequest } from 'next/server';
|
import { NextRequest } from 'next/server';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { getContentPointer } from '@/app/(space)/fetch';
|
import { getSite, getSiteData, getSpace } from '@/lib/api';
|
||||||
import {
|
|
||||||
getCollection,
|
|
||||||
getCurrentSiteCustomization,
|
|
||||||
getSite,
|
|
||||||
getSpace,
|
|
||||||
getSpaceCustomization,
|
|
||||||
} from '@/lib/api';
|
|
||||||
import { getEmojiForCode } from '@/lib/emojis';
|
import { getEmojiForCode } from '@/lib/emojis';
|
||||||
|
import { getSiteContentPointer } from '@/lib/pointer';
|
||||||
import { tcls } from '@/lib/tailwind';
|
import { tcls } from '@/lib/tailwind';
|
||||||
import { getContentTitle } from '@/lib/utils';
|
import { getContentTitle } from '@/lib/utils';
|
||||||
|
|
||||||
@@ -42,20 +35,15 @@ export async function GET(req: NextRequest) {
|
|||||||
const options = getOptions(req.url);
|
const options = getOptions(req.url);
|
||||||
const size = SIZES[options.size];
|
const size = SIZES[options.size];
|
||||||
|
|
||||||
const pointer = getContentPointer();
|
const pointer = getSiteContentPointer();
|
||||||
const spaceId = pointer.spaceId;
|
const spaceId = pointer.spaceId;
|
||||||
|
|
||||||
const [space, customization] = await Promise.all([
|
const [space, { customization }] = await Promise.all([
|
||||||
getSpace(spaceId),
|
getSpace(spaceId, pointer.siteShareKey),
|
||||||
'siteId' in pointer ? getCurrentSiteCustomization(pointer) : getSpaceCustomization(spaceId),
|
getSiteData(pointer),
|
||||||
]);
|
]);
|
||||||
const parent =
|
const site = await getSite(pointer.organizationId, pointer.siteId);
|
||||||
'siteId' in pointer
|
const contentTitle = getContentTitle(space, customization, site);
|
||||||
? await getSite(pointer.organizationId, pointer.siteId)
|
|
||||||
: space.visibility === ContentVisibility.InCollection && space.parent
|
|
||||||
? await getCollection(space.parent)
|
|
||||||
: null;
|
|
||||||
const contentTitle = getContentTitle(space, customization, parent);
|
|
||||||
|
|
||||||
return new ImageResponse(
|
return new ImageResponse(
|
||||||
(
|
(
|
||||||
@@ -0,0 +1,223 @@
|
|||||||
|
import { CustomizationHeaderPreset } from '@gitbook/api';
|
||||||
|
import { redirect } from 'next/navigation';
|
||||||
|
import { ImageResponse } from 'next/og';
|
||||||
|
import { NextRequest } from 'next/server';
|
||||||
|
import colorContrast from 'postcss-color-contrast/js';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { absoluteHref } from '@/lib/links';
|
||||||
|
import { tcls } from '@/lib/tailwind';
|
||||||
|
import { getContentTitle } from '@/lib/utils';
|
||||||
|
|
||||||
|
import { PageIdParams, fetchPageData } from '../../../../fetch';
|
||||||
|
|
||||||
|
export const runtime = 'edge';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render the OpenGraph image for a space.
|
||||||
|
*/
|
||||||
|
export async function GET(req: NextRequest, { params }: { params: PageIdParams }) {
|
||||||
|
const { space, page, customization, site } = await fetchPageData(params);
|
||||||
|
|
||||||
|
if (customization.socialPreview.url) {
|
||||||
|
// If user configured a custom social preview, we redirect to it.
|
||||||
|
redirect(customization.socialPreview.url);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Support all fonts available in GitBook
|
||||||
|
// Right now this is impossible since next/font/google does not expose the cached font file
|
||||||
|
// Another option would be to use the Satori prop `loadAdditionalAsset` [example](https://github.com/vercel/satori/blob/main/playground/pages/index.tsx),
|
||||||
|
// but this prop isn't (yet) exposed through `ImageResponse`.
|
||||||
|
const interRegular = await fetch(
|
||||||
|
new URL('../../../../../../fonts/Inter/Inter-Regular.ttf', import.meta.url),
|
||||||
|
).then((res) => res.arrayBuffer());
|
||||||
|
const interBold = await fetch(
|
||||||
|
new URL('../../../../../../fonts/Inter/Inter-Bold.ttf', import.meta.url),
|
||||||
|
).then((res) => res.arrayBuffer());
|
||||||
|
|
||||||
|
const theme = customization.themes.default;
|
||||||
|
const useLightTheme = theme === 'light';
|
||||||
|
|
||||||
|
// We have no access to CSS variables, so we'll have to hardcode some values
|
||||||
|
const baseColors = {
|
||||||
|
light: '#ffffff',
|
||||||
|
dark: '#111827',
|
||||||
|
};
|
||||||
|
|
||||||
|
let colors = {
|
||||||
|
background: baseColors[theme],
|
||||||
|
gradient: customization.styling.primaryColor[theme],
|
||||||
|
title: customization.styling.primaryColor[theme],
|
||||||
|
body: baseColors[useLightTheme ? 'dark' : 'light'], // Invert text on background
|
||||||
|
};
|
||||||
|
|
||||||
|
const gridWhite = absoluteHref('~gitbook/static/images/ogimage-grid-white.png', true);
|
||||||
|
const gridBlack = absoluteHref('~gitbook/static/images/ogimage-grid-black.png', true);
|
||||||
|
|
||||||
|
let gridAsset = useLightTheme ? gridBlack : gridWhite;
|
||||||
|
|
||||||
|
switch (customization.header.preset) {
|
||||||
|
case CustomizationHeaderPreset.Custom:
|
||||||
|
colors = {
|
||||||
|
background: customization.header.backgroundColor?.[theme] || colors.background,
|
||||||
|
gradient: customization.header.linkColor?.[theme] || colors.gradient,
|
||||||
|
title: customization.header.linkColor?.[theme] || colors.title,
|
||||||
|
body: colorContrast(
|
||||||
|
customization.header.backgroundColor?.[theme] || colors.background,
|
||||||
|
[baseColors.light, baseColors.dark],
|
||||||
|
),
|
||||||
|
};
|
||||||
|
gridAsset = colors.body == baseColors.light ? gridWhite : gridBlack;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CustomizationHeaderPreset.Bold:
|
||||||
|
colors = {
|
||||||
|
background: customization.styling.primaryColor[theme],
|
||||||
|
gradient: colorContrast(customization.styling.primaryColor[theme], [
|
||||||
|
baseColors.light,
|
||||||
|
baseColors.dark,
|
||||||
|
]),
|
||||||
|
title: colorContrast(customization.styling.primaryColor[theme], [
|
||||||
|
baseColors.light,
|
||||||
|
baseColors.dark,
|
||||||
|
]),
|
||||||
|
body: colorContrast(customization.styling.primaryColor[theme], [
|
||||||
|
baseColors.light,
|
||||||
|
baseColors.dark,
|
||||||
|
]),
|
||||||
|
};
|
||||||
|
gridAsset = colors.body == baseColors.light ? gridWhite : gridBlack;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
const favicon = function () {
|
||||||
|
if ('icon' in customization.favicon)
|
||||||
|
return (
|
||||||
|
<img
|
||||||
|
src={customization.favicon.icon[theme]}
|
||||||
|
width={40}
|
||||||
|
height={40}
|
||||||
|
tw={tcls('mr-4')}
|
||||||
|
alt="Icon"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
if ('emoji' in customization.favicon)
|
||||||
|
return (
|
||||||
|
<span tw={tcls('text-4xl', 'mr-4')}>
|
||||||
|
{String.fromCodePoint(parseInt('0x' + customization.favicon.emoji))}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
<img
|
||||||
|
src={absoluteHref(
|
||||||
|
`~gitbook/icon?size=medium&theme=${customization.themes.default}`,
|
||||||
|
true,
|
||||||
|
)}
|
||||||
|
alt="Icon"
|
||||||
|
width={40}
|
||||||
|
height={40}
|
||||||
|
tw={tcls('mr-4')}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return new ImageResponse(
|
||||||
|
(
|
||||||
|
<div
|
||||||
|
tw={tcls(
|
||||||
|
'justify-between',
|
||||||
|
'p-20',
|
||||||
|
'relative',
|
||||||
|
'w-full',
|
||||||
|
'h-full',
|
||||||
|
'flex',
|
||||||
|
'flex-col',
|
||||||
|
`bg-[${colors.background}]`,
|
||||||
|
`text-[${colors.body}]`,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{/* Gradient */}
|
||||||
|
<div
|
||||||
|
tw={tcls('absolute', 'inset-0')}
|
||||||
|
style={{
|
||||||
|
backgroundImage: `radial-gradient(ellipse 100% 100% at top right , ${colors.gradient}, ${colors.gradient}00)`,
|
||||||
|
opacity: 0.5,
|
||||||
|
}}
|
||||||
|
></div>
|
||||||
|
|
||||||
|
{/* Grid */}
|
||||||
|
<img
|
||||||
|
tw={tcls('absolute', 'inset-0', 'w-[100vw]', 'h-[100vh]')}
|
||||||
|
src={gridAsset}
|
||||||
|
alt="Grid"
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Logo */}
|
||||||
|
{customization.header.logo ? (
|
||||||
|
<img
|
||||||
|
alt="Logo"
|
||||||
|
height={60}
|
||||||
|
src={
|
||||||
|
useLightTheme
|
||||||
|
? customization.header.logo.light
|
||||||
|
: customization.header.logo.dark
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div tw={tcls('flex')}>
|
||||||
|
{favicon()}
|
||||||
|
<h3 tw={tcls('text-4xl', 'my-0')}>
|
||||||
|
{getContentTitle(space, customization, site ?? null)}
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Title and description */}
|
||||||
|
<div tw={tcls('flex', 'flex-col')}>
|
||||||
|
<h1
|
||||||
|
tw={tcls(
|
||||||
|
'text-8xl',
|
||||||
|
'my-0',
|
||||||
|
'tracking-tight',
|
||||||
|
'leading-none',
|
||||||
|
'text-left',
|
||||||
|
`text-[${colors.title}]`,
|
||||||
|
'font-bold',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{page
|
||||||
|
? page.title.length > 64
|
||||||
|
? page.title.slice(0, 64) + '...'
|
||||||
|
: page.title
|
||||||
|
: 'Not found'}
|
||||||
|
</h1>
|
||||||
|
{page?.description && page?.title.length <= 64 ? (
|
||||||
|
<h2 tw={tcls('text-4xl', 'mb-0', 'mt-8', 'w-[75%]', 'font-normal')}>
|
||||||
|
{page.description.length > 164
|
||||||
|
? page.description.slice(0, 164) + '...'
|
||||||
|
: page.description}
|
||||||
|
</h2>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
{
|
||||||
|
width: 1200,
|
||||||
|
height: 630,
|
||||||
|
fonts: [
|
||||||
|
{
|
||||||
|
name: 'Inter',
|
||||||
|
data: interRegular,
|
||||||
|
weight: 400,
|
||||||
|
style: 'normal',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Inter',
|
||||||
|
data: interBold,
|
||||||
|
weight: 700,
|
||||||
|
style: 'normal',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,145 @@
|
|||||||
|
import { RevisionPage } from '@gitbook/api';
|
||||||
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
|
import {
|
||||||
|
getRevisionPageByPath,
|
||||||
|
getDocument,
|
||||||
|
getSpaceContentData,
|
||||||
|
getSiteData,
|
||||||
|
getSiteRedirectBySource,
|
||||||
|
} from '@/lib/api';
|
||||||
|
import { resolvePagePath, resolvePageId } from '@/lib/pages';
|
||||||
|
import { getSiteContentPointer } from '@/lib/pointer';
|
||||||
|
|
||||||
|
export interface PagePathParams {
|
||||||
|
pathname?: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PageIdParams {
|
||||||
|
pageId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch all the data needed to render the content layout.
|
||||||
|
*/
|
||||||
|
export async function fetchContentData() {
|
||||||
|
const content = getSiteContentPointer();
|
||||||
|
|
||||||
|
const [{ space, contentTarget, pages }, { customization, site, sections, spaces, scripts }] =
|
||||||
|
await Promise.all([
|
||||||
|
getSpaceContentData(content, content.siteShareKey),
|
||||||
|
getSiteData(content),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// we grab the space attached to the parent as it contains overriden customizations
|
||||||
|
const spaceRelativeToParent = spaces?.find((space) => space.id === content.spaceId);
|
||||||
|
|
||||||
|
return {
|
||||||
|
content,
|
||||||
|
contentTarget,
|
||||||
|
space: spaceRelativeToParent ?? space,
|
||||||
|
pages,
|
||||||
|
site,
|
||||||
|
sections,
|
||||||
|
spaces,
|
||||||
|
shareKey: content.siteShareKey,
|
||||||
|
customization,
|
||||||
|
scripts,
|
||||||
|
ancestors: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch all the data needed to render the content.
|
||||||
|
* Optimized to fetch in parallel as much as possible.
|
||||||
|
*/
|
||||||
|
export async function fetchPageData(params: PagePathParams | PageIdParams) {
|
||||||
|
const contentData = await fetchContentData();
|
||||||
|
|
||||||
|
const page = await resolvePage({
|
||||||
|
organizationId: contentData.space.organization,
|
||||||
|
siteId: contentData.site.id,
|
||||||
|
spaceId: contentData.contentTarget.spaceId,
|
||||||
|
revisionId: contentData.contentTarget.revisionId,
|
||||||
|
pages: contentData.pages,
|
||||||
|
shareKey: contentData.shareKey,
|
||||||
|
params,
|
||||||
|
});
|
||||||
|
const document = page?.page.documentId
|
||||||
|
? await getDocument(contentData.space.id, page.page.documentId)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...contentData,
|
||||||
|
...page,
|
||||||
|
document,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve a page from the params.
|
||||||
|
* If the path can't be found, we try to resolve it from the API to handle redirects.
|
||||||
|
*/
|
||||||
|
async function resolvePage(input: {
|
||||||
|
organizationId: string;
|
||||||
|
siteId: string;
|
||||||
|
spaceId: string;
|
||||||
|
revisionId: string;
|
||||||
|
shareKey: string | undefined;
|
||||||
|
pages: RevisionPage[];
|
||||||
|
params: PagePathParams | PageIdParams;
|
||||||
|
}) {
|
||||||
|
const { organizationId, siteId, spaceId, revisionId, pages, shareKey, params } = input;
|
||||||
|
|
||||||
|
if ('pageId' in params) {
|
||||||
|
return resolvePageId(pages, params.pageId);
|
||||||
|
}
|
||||||
|
|
||||||
|
const rawPathname = getPathnameParam(params);
|
||||||
|
const pathname = normalizePathname(rawPathname);
|
||||||
|
|
||||||
|
// When resolving a page, we use the lowercased pathname
|
||||||
|
const page = resolvePagePath(pages, pathname);
|
||||||
|
if (page) {
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We don't test path that are too long as GitBook doesn't support them and will return a 404 anyway.
|
||||||
|
if (rawPathname.length <= 512) {
|
||||||
|
// If page can't be found, we try with the API, in case we have a redirect at space level.
|
||||||
|
// We use the raw pathname to handle special/malformed redirects setup by users in the GitSync.
|
||||||
|
// The page rendering will take care of redirecting to a normalized pathname.
|
||||||
|
const resolved = await getRevisionPageByPath(spaceId, revisionId, rawPathname);
|
||||||
|
if (resolved) {
|
||||||
|
return resolvePageId(pages, resolved.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If a page still can't be found, we try with the API, in case we have a redirect at site level.
|
||||||
|
const resolvedSiteRedirect = await getSiteRedirectBySource({
|
||||||
|
organizationId,
|
||||||
|
siteId,
|
||||||
|
source: rawPathname.startsWith('/') ? rawPathname : `/${rawPathname}`,
|
||||||
|
siteShareKey: input.shareKey,
|
||||||
|
});
|
||||||
|
if (resolvedSiteRedirect) {
|
||||||
|
return redirect(resolvedSiteRedirect.target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the page path from the params.
|
||||||
|
*/
|
||||||
|
export function getPathnameParam(params: PagePathParams): string {
|
||||||
|
const { pathname } = params;
|
||||||
|
return pathname ? pathname.map((part) => decodeURIComponent(part)).join('/') : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize the URL pathname into the format used in the revision page path.
|
||||||
|
*/
|
||||||
|
export function normalizePathname(pathname: string) {
|
||||||
|
return pathname.toLowerCase();
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { CustomizationRootLayout } from '@/components/RootLayout';
|
||||||
|
import { getSiteData } from '@/lib/api';
|
||||||
|
import { getSiteContentPointer } from '@/lib/pointer';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Layout to be used for the site root. It fetches the customization data for the site
|
||||||
|
* and initializes the CustomizationRootLayout with it.
|
||||||
|
*/
|
||||||
|
export default async function SiteRootLayout(props: { children: React.ReactNode }) {
|
||||||
|
const { children } = props;
|
||||||
|
|
||||||
|
const pointer = getSiteContentPointer();
|
||||||
|
const { customization } = await getSiteData(pointer);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<CustomizationRootLayout customization={customization}>{children}</CustomizationRootLayout>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
import { ContentVisibility } from '@gitbook/api';
|
|
||||||
import { NextRequest } from 'next/server';
|
|
||||||
|
|
||||||
import { getCollection, getSite, getSpace } from '@/lib/api';
|
|
||||||
import { absoluteHref } from '@/lib/links';
|
|
||||||
import { shouldIndexSpace } from '@/lib/seo';
|
|
||||||
|
|
||||||
import { getContentPointer } from '../../fetch';
|
|
||||||
|
|
||||||
export const runtime = 'edge';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a robots.txt for the current space.
|
|
||||||
*/
|
|
||||||
export async function GET(req: NextRequest) {
|
|
||||||
const pointer = getContentPointer();
|
|
||||||
const space = await getSpace(pointer.spaceId);
|
|
||||||
const parent =
|
|
||||||
'siteId' in pointer
|
|
||||||
? await getSite(pointer.organizationId, pointer.siteId)
|
|
||||||
: space.visibility === ContentVisibility.InCollection && space.parent
|
|
||||||
? await getCollection(space.parent)
|
|
||||||
: null;
|
|
||||||
|
|
||||||
const lines = [
|
|
||||||
`User-agent: *`,
|
|
||||||
'Disallow: /~gitbook/',
|
|
||||||
...(shouldIndexSpace({ space, parent })
|
|
||||||
? [`Allow: /`, `Sitemap: ${absoluteHref(`/sitemap.xml`, true)}`]
|
|
||||||
: [`Disallow: /`]),
|
|
||||||
];
|
|
||||||
const content = lines.join('\n');
|
|
||||||
|
|
||||||
return new Response(content, {
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'text/plain',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
import { redirect } from 'next/navigation';
|
|
||||||
import { ImageResponse } from 'next/og';
|
|
||||||
import { NextRequest } from 'next/server';
|
|
||||||
import React from 'react';
|
|
||||||
|
|
||||||
import { getContentTitle } from '@/lib/utils';
|
|
||||||
|
|
||||||
import { PageIdParams, fetchPageData } from '../../../../fetch';
|
|
||||||
|
|
||||||
export const runtime = 'edge';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Render the OpenGraph image for a space.
|
|
||||||
*/
|
|
||||||
export async function GET(req: NextRequest, { params }: { params: PageIdParams }) {
|
|
||||||
const { space, page, customization, parent } = await fetchPageData(params);
|
|
||||||
const url = new URL(space.urls.published ?? space.urls.app);
|
|
||||||
|
|
||||||
if (customization.socialPreview.url) {
|
|
||||||
// If user configured a custom social preview, we redirect to it.
|
|
||||||
redirect(customization.socialPreview.url);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ImageResponse(
|
|
||||||
(
|
|
||||||
<div
|
|
||||||
tw="bg-gray-50 py-16 px-14"
|
|
||||||
style={{
|
|
||||||
height: '100%',
|
|
||||||
width: '100%',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<h2 tw="text-7xl font-bold tracking-tight text-left">
|
|
||||||
{getContentTitle(space, customization, parent)}
|
|
||||||
</h2>
|
|
||||||
<div tw="flex flex-1">
|
|
||||||
<p tw="text-4xl">{page ? page.title : 'Not found'}</p>
|
|
||||||
</div>
|
|
||||||
<div tw="flex">
|
|
||||||
<p tw="text-4xl">
|
|
||||||
{url.hostname + (url.pathname.length > 1 ? url.pathname : '')}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
{
|
|
||||||
width: 1200,
|
|
||||||
height: 630,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,227 +0,0 @@
|
|||||||
import { ContentVisibility, RevisionPage, Space } from '@gitbook/api';
|
|
||||||
import { headers } from 'next/headers';
|
|
||||||
|
|
||||||
import {
|
|
||||||
getCollectionSpaces,
|
|
||||||
getCollection,
|
|
||||||
ContentPointer,
|
|
||||||
getRevisionPageByPath,
|
|
||||||
getDocument,
|
|
||||||
getSpaceData,
|
|
||||||
ContentTarget,
|
|
||||||
SiteContentPointer,
|
|
||||||
getCurrentSiteData,
|
|
||||||
getSite,
|
|
||||||
getSiteSpaces,
|
|
||||||
} from '@/lib/api';
|
|
||||||
import { resolvePagePath, resolvePageId } from '@/lib/pages';
|
|
||||||
|
|
||||||
export interface PagePathParams {
|
|
||||||
pathname?: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PageIdParams {
|
|
||||||
pageId: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the current content pointer from the params.
|
|
||||||
*/
|
|
||||||
export function getContentPointer(): ContentPointer | SiteContentPointer {
|
|
||||||
const headerSet = headers();
|
|
||||||
const spaceId = headerSet.get('x-gitbook-content-space');
|
|
||||||
if (!spaceId) {
|
|
||||||
throw new Error(
|
|
||||||
'getContentPointer is called outside the scope of a request processed by the middleware',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const siteId = headerSet.get('x-gitbook-content-site');
|
|
||||||
if (siteId) {
|
|
||||||
const organizationId = headerSet.get('x-gitbook-content-organization');
|
|
||||||
const siteSpaceId = headerSet.get('x-gitbook-content-site-space');
|
|
||||||
const siteShareKey = headerSet.get('x-gitbook-content-site-share-key');
|
|
||||||
if (!organizationId) {
|
|
||||||
throw new Error('Missing site content headers');
|
|
||||||
}
|
|
||||||
|
|
||||||
const siteContent: SiteContentPointer = {
|
|
||||||
siteId,
|
|
||||||
spaceId,
|
|
||||||
siteSpaceId: siteSpaceId ?? undefined,
|
|
||||||
siteShareKey: siteShareKey ?? undefined,
|
|
||||||
organizationId,
|
|
||||||
revisionId: headerSet.get('x-gitbook-content-revision') ?? undefined,
|
|
||||||
changeRequestId: headerSet.get('x-gitbook-content-changerequest') ?? undefined,
|
|
||||||
};
|
|
||||||
return siteContent;
|
|
||||||
} else {
|
|
||||||
const content: ContentPointer = {
|
|
||||||
spaceId,
|
|
||||||
revisionId: headerSet.get('x-gitbook-content-revision') ?? undefined,
|
|
||||||
changeRequestId: headerSet.get('x-gitbook-content-changerequest') ?? undefined,
|
|
||||||
};
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch all the data needed to render the space layout.
|
|
||||||
*/
|
|
||||||
export async function fetchSpaceData() {
|
|
||||||
const content = getContentPointer();
|
|
||||||
|
|
||||||
const [{ space, contentTarget, pages, customization, scripts }, parentSite] = await Promise.all(
|
|
||||||
'siteId' in content
|
|
||||||
? [
|
|
||||||
getCurrentSiteData(content),
|
|
||||||
fetchParentSite({
|
|
||||||
organizationId: content.organizationId,
|
|
||||||
siteId: content.siteId,
|
|
||||||
siteShareKey: content.siteShareKey,
|
|
||||||
}),
|
|
||||||
]
|
|
||||||
: [getSpaceData(content)],
|
|
||||||
);
|
|
||||||
|
|
||||||
const parent = await (parentSite ?? fetchParentCollection(space));
|
|
||||||
|
|
||||||
return {
|
|
||||||
content,
|
|
||||||
contentTarget,
|
|
||||||
space,
|
|
||||||
pages,
|
|
||||||
customization,
|
|
||||||
scripts,
|
|
||||||
ancestors: [],
|
|
||||||
...parent,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch all the data needed to render the content.
|
|
||||||
* Optimized to fetch in parallel as much as possible.
|
|
||||||
*/
|
|
||||||
export async function fetchPageData(params: PagePathParams | PageIdParams) {
|
|
||||||
const content = getContentPointer();
|
|
||||||
const { space, contentTarget, pages, customization, scripts } = await ('siteId' in content
|
|
||||||
? getCurrentSiteData(content)
|
|
||||||
: getSpaceData(content));
|
|
||||||
|
|
||||||
const page = await resolvePage(contentTarget, pages, params);
|
|
||||||
const [parent, document] = await Promise.all([
|
|
||||||
'siteId' in content
|
|
||||||
? fetchParentSite({
|
|
||||||
organizationId: content.organizationId,
|
|
||||||
siteId: content.siteId,
|
|
||||||
siteShareKey: content.siteShareKey,
|
|
||||||
})
|
|
||||||
: fetchParentCollection(space),
|
|
||||||
page?.page.documentId ? getDocument(space.id, page.page.documentId) : null,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return {
|
|
||||||
content,
|
|
||||||
contentTarget,
|
|
||||||
space,
|
|
||||||
pages,
|
|
||||||
customization,
|
|
||||||
scripts,
|
|
||||||
ancestors: [],
|
|
||||||
...page,
|
|
||||||
...parent,
|
|
||||||
document,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resolve a page from the params.
|
|
||||||
* If the path can't be found, we try to resolve it from the API to handle redirects.
|
|
||||||
*/
|
|
||||||
async function resolvePage(
|
|
||||||
contentTarget: ContentTarget,
|
|
||||||
pages: RevisionPage[],
|
|
||||||
params: PagePathParams | PageIdParams,
|
|
||||||
) {
|
|
||||||
if ('pageId' in params) {
|
|
||||||
return resolvePageId(pages, params.pageId);
|
|
||||||
}
|
|
||||||
|
|
||||||
const rawPathname = getPathnameParam(params);
|
|
||||||
const pathname = normalizePathname(rawPathname);
|
|
||||||
|
|
||||||
// When resolving a page, we use the lowercased pathname
|
|
||||||
const page = resolvePagePath(pages, pathname);
|
|
||||||
if (page) {
|
|
||||||
return page;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If page can't be found, we try with the API, in case we have a redirect
|
|
||||||
// We use the raw pathname to handle special/malformed redirects setup by users in the GitSync.
|
|
||||||
// The page rendering will take care of redirecting to a normalized pathname.
|
|
||||||
//
|
|
||||||
// We don't test path that are too long as GitBook doesn't support them and will return a 404 anyway.
|
|
||||||
if (rawPathname.length <= 512) {
|
|
||||||
const resolved = await getRevisionPageByPath(
|
|
||||||
contentTarget.spaceId,
|
|
||||||
contentTarget.revisionId,
|
|
||||||
rawPathname,
|
|
||||||
);
|
|
||||||
if (resolved) {
|
|
||||||
return resolvePageId(pages, resolved.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function fetchParentCollection(space: Space) {
|
|
||||||
const parentCollectionId =
|
|
||||||
space.visibility === ContentVisibility.InCollection ? space.parent : undefined;
|
|
||||||
const [collection, spaces] = await Promise.all([
|
|
||||||
parentCollectionId ? getCollection(parentCollectionId) : null,
|
|
||||||
parentCollectionId ? getCollectionSpaces(parentCollectionId) : ([] as Space[]),
|
|
||||||
]);
|
|
||||||
|
|
||||||
return { parent: collection, spaces };
|
|
||||||
}
|
|
||||||
|
|
||||||
async function fetchParentSite(args: {
|
|
||||||
organizationId: string;
|
|
||||||
siteId: string;
|
|
||||||
siteShareKey: string | undefined;
|
|
||||||
}) {
|
|
||||||
const { organizationId, siteId, siteShareKey } = args;
|
|
||||||
const [site, siteSpaces] = await Promise.all([
|
|
||||||
getSite(organizationId, siteId),
|
|
||||||
getSiteSpaces({ organizationId, siteId, siteShareKey }),
|
|
||||||
]);
|
|
||||||
|
|
||||||
const spaces: Record<string, Space> = {};
|
|
||||||
siteSpaces.forEach((siteSpace) => {
|
|
||||||
spaces[siteSpace.space.id] = {
|
|
||||||
...siteSpace.space,
|
|
||||||
urls: {
|
|
||||||
...siteSpace.space.urls,
|
|
||||||
published: siteSpace.urls.published,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
return { parent: site, spaces: Object.values(spaces) };
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the page path from the params.
|
|
||||||
*/
|
|
||||||
export function getPathnameParam(params: PagePathParams): string {
|
|
||||||
const { pathname } = params;
|
|
||||||
return pathname ? pathname.map((part) => decodeURIComponent(part)).join('/') : '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Normalize the URL pathname into the format used in the revision page path.
|
|
||||||
*/
|
|
||||||
export function normalizePathname(pathname: string) {
|
|
||||||
return pathname.toLowerCase();
|
|
||||||
}
|
|
||||||
@@ -1,190 +0,0 @@
|
|||||||
import {
|
|
||||||
CustomizationBackground,
|
|
||||||
CustomizationCorners,
|
|
||||||
CustomizationHeaderPreset,
|
|
||||||
CustomizationSettings,
|
|
||||||
SiteCustomizationSettings,
|
|
||||||
} from '@gitbook/api';
|
|
||||||
import assertNever from 'assert-never';
|
|
||||||
import colors from 'tailwindcss/colors';
|
|
||||||
|
|
||||||
import { emojiFontClassName } from '@/components/primitives';
|
|
||||||
import { fonts, ibmPlexMono } from '@/fonts';
|
|
||||||
import { getSpaceLanguage } from '@/intl/server';
|
|
||||||
import { getCurrentSiteLayoutData, getSpaceLayoutData } from '@/lib/api';
|
|
||||||
import { hexToRgb, shadesOfColor } from '@/lib/colors';
|
|
||||||
import { tcls } from '@/lib/tailwind';
|
|
||||||
|
|
||||||
import { ClientContexts } from './ClientContexts';
|
|
||||||
import './globals.css';
|
|
||||||
import { getContentPointer } from './fetch';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Layout shared between the content and the PDF renderer.
|
|
||||||
* It takes care of setting the theme and the language.
|
|
||||||
*/
|
|
||||||
export default async function SpaceRootLayout(props: { children: React.ReactNode }) {
|
|
||||||
const { children } = props;
|
|
||||||
|
|
||||||
const pointer = getContentPointer();
|
|
||||||
const { customization } = await ('siteId' in pointer
|
|
||||||
? getCurrentSiteLayoutData(pointer)
|
|
||||||
: getSpaceLayoutData(pointer.spaceId));
|
|
||||||
const headerTheme = generateHeaderTheme(customization);
|
|
||||||
const language = getSpaceLanguage(customization);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<html
|
|
||||||
suppressHydrationWarning
|
|
||||||
lang={customization.internationalization.locale}
|
|
||||||
className={
|
|
||||||
tcls(
|
|
||||||
customization.header.preset === CustomizationHeaderPreset.None
|
|
||||||
? null
|
|
||||||
: [
|
|
||||||
// Take the sticky header in consideration for the scrolling
|
|
||||||
`scroll-pt-[76px]`,
|
|
||||||
],
|
|
||||||
) +
|
|
||||||
(customization.styling.corners === CustomizationCorners.Straight
|
|
||||||
? ' straight-corners'
|
|
||||||
: '') +
|
|
||||||
(customization.styling.background === CustomizationBackground.Plain
|
|
||||||
? ' plain-background'
|
|
||||||
: '')
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<head>
|
|
||||||
{customization.privacyPolicy.url ? (
|
|
||||||
<link rel="privacy-policy" href={customization.privacyPolicy.url} />
|
|
||||||
) : null}
|
|
||||||
<style
|
|
||||||
nonce={
|
|
||||||
//Since I can't get the nonce to work for inline styles, we need to allow unsafe-inline
|
|
||||||
undefined
|
|
||||||
}
|
|
||||||
>{`
|
|
||||||
:root {
|
|
||||||
${generateColorVariable(
|
|
||||||
'primary-color',
|
|
||||||
customization.styling.primaryColor.light,
|
|
||||||
)}
|
|
||||||
${generateColorVariable(
|
|
||||||
'primary-base',
|
|
||||||
customization.styling.primaryColor.light,
|
|
||||||
)}
|
|
||||||
${generateColorVariable(
|
|
||||||
'header-background',
|
|
||||||
headerTheme.backgroundColor.light,
|
|
||||||
)}
|
|
||||||
${generateColorVariable('header-link', headerTheme.linkColor.light)}
|
|
||||||
}
|
|
||||||
.dark {
|
|
||||||
${generateColorVariable(
|
|
||||||
'primary-color',
|
|
||||||
customization.styling.primaryColor.dark,
|
|
||||||
)}
|
|
||||||
${generateColorVariable(
|
|
||||||
'primary-base',
|
|
||||||
customization.styling.primaryColor.dark,
|
|
||||||
)}
|
|
||||||
${generateColorVariable(
|
|
||||||
'header-background',
|
|
||||||
headerTheme.backgroundColor.dark,
|
|
||||||
)}
|
|
||||||
${generateColorVariable('header-link', headerTheme.linkColor.dark)}
|
|
||||||
}
|
|
||||||
`}</style>
|
|
||||||
</head>
|
|
||||||
<body
|
|
||||||
className={tcls(
|
|
||||||
emojiFontClassName,
|
|
||||||
`${fonts[customization.styling.font].className}`,
|
|
||||||
`${ibmPlexMono.variable}`,
|
|
||||||
'bg-light',
|
|
||||||
'dark:bg-dark',
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<ClientContexts language={language}>{children}</ClientContexts>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
type ColorInput = string | Record<string, string>;
|
|
||||||
function generateColorVariable(name: string, color: ColorInput) {
|
|
||||||
const shades: Record<string, string> = typeof color === 'string' ? shadesOfColor(color) : color;
|
|
||||||
|
|
||||||
return Object.entries(shades)
|
|
||||||
.map(([key, value]) => {
|
|
||||||
// Check the original hex value
|
|
||||||
const rgbValue = hexToRgb(value);
|
|
||||||
return `--${name}-${key}: ${rgbValue};`;
|
|
||||||
})
|
|
||||||
.join('\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
function generateHeaderTheme(customization: CustomizationSettings | SiteCustomizationSettings): {
|
|
||||||
backgroundColor: { light: ColorInput; dark: ColorInput };
|
|
||||||
linkColor: { light: ColorInput; dark: ColorInput };
|
|
||||||
} {
|
|
||||||
switch (customization.header.preset) {
|
|
||||||
case CustomizationHeaderPreset.None:
|
|
||||||
case CustomizationHeaderPreset.Default: {
|
|
||||||
return {
|
|
||||||
backgroundColor: {
|
|
||||||
light: colors.white,
|
|
||||||
dark: colors.black,
|
|
||||||
},
|
|
||||||
linkColor: {
|
|
||||||
light: customization.styling.primaryColor.light,
|
|
||||||
dark: customization.styling.primaryColor.dark,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
case CustomizationHeaderPreset.Bold: {
|
|
||||||
return {
|
|
||||||
backgroundColor: {
|
|
||||||
light: customization.styling.primaryColor.light,
|
|
||||||
dark: customization.styling.primaryColor.dark,
|
|
||||||
},
|
|
||||||
linkColor: {
|
|
||||||
// TODO: should depend on the color of the background
|
|
||||||
light: colors.white,
|
|
||||||
dark: colors.black,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
case CustomizationHeaderPreset.Contrast: {
|
|
||||||
return {
|
|
||||||
backgroundColor: {
|
|
||||||
light: colors.black,
|
|
||||||
dark: colors.white,
|
|
||||||
},
|
|
||||||
linkColor: {
|
|
||||||
light: colors.white,
|
|
||||||
dark: colors.black,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
case CustomizationHeaderPreset.Custom: {
|
|
||||||
return {
|
|
||||||
backgroundColor: {
|
|
||||||
light: customization.header.backgroundColor?.light ?? colors.white,
|
|
||||||
dark: customization.header.backgroundColor?.dark ?? colors.black,
|
|
||||||
},
|
|
||||||
linkColor: {
|
|
||||||
light:
|
|
||||||
customization.header.linkColor?.light ??
|
|
||||||
customization.styling.primaryColor.light,
|
|
||||||
dark:
|
|
||||||
customization.header.linkColor?.dark ??
|
|
||||||
customization.styling.primaryColor.dark,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
assertNever(customization.header.preset);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+5
-2
@@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { AlertTriangle } from '@geist-ui/icons';
|
import { Icon } from '@gitbook/icons';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { useScrollActiveId } from '@/components/hooks';
|
import { useScrollActiveId } from '@/components/hooks';
|
||||||
@@ -105,7 +105,10 @@ export function PageControlButtons(props: {
|
|||||||
'max-w-sm',
|
'max-w-sm',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<AlertTriangle className={tcls('size-6', 'mr-3', 'mt-1')} />{' '}
|
<Icon
|
||||||
|
icon="triangle-exclamation"
|
||||||
|
className={tcls('size-6', 'mr-3', 'mt-1')}
|
||||||
|
/>{' '}
|
||||||
<div>
|
<div>
|
||||||
<div>{t(language, 'pdf_limit_reached', total, pageIds.length)}</div>
|
<div>{t(language, 'pdf_limit_reached', total, pageIds.length)}</div>
|
||||||
<div>
|
<div>
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import { SpaceIntegrationScript } from '@gitbook/api';
|
||||||
|
|
||||||
|
import { CustomizationRootLayout } from '@/components/RootLayout';
|
||||||
|
import { getSiteData, getSpaceCustomization } from '@/lib/api';
|
||||||
|
|
||||||
|
import { getSiteOrSpacePointerForPDF } from './pointer';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Layout to be used for the site root. It fetches the customization data for the
|
||||||
|
* site or space and initializes the CustomizationRootLayout with it.
|
||||||
|
*/
|
||||||
|
export default async function PDFRootLayout(props: { children: React.ReactNode }) {
|
||||||
|
const { children } = props;
|
||||||
|
|
||||||
|
const pointer = getSiteOrSpacePointerForPDF();
|
||||||
|
const { customization } = await ('siteId' in pointer
|
||||||
|
? getSiteData(pointer)
|
||||||
|
: getSpaceLayoutData(pointer.spaceId));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<CustomizationRootLayout customization={customization}>{children}</CustomizationRootLayout>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch all the layout data about a space at once.
|
||||||
|
*/
|
||||||
|
async function getSpaceLayoutData(spaceId: string) {
|
||||||
|
const [{ customization }, scripts] = await Promise.all([
|
||||||
|
getSpaceCustomization(spaceId),
|
||||||
|
[] as SpaceIntegrationScript[],
|
||||||
|
]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
customization,
|
||||||
|
scripts,
|
||||||
|
};
|
||||||
|
}
|
||||||
+17
-23
@@ -1,19 +1,17 @@
|
|||||||
import { ArrowLeft, Printer } from '@geist-ui/icons';
|
|
||||||
import {
|
import {
|
||||||
CustomizationSettings,
|
CustomizationSettings,
|
||||||
Revision,
|
Revision,
|
||||||
RevisionPageDocument,
|
RevisionPageDocument,
|
||||||
RevisionPageGroup,
|
RevisionPageGroup,
|
||||||
RevisionPageLink,
|
|
||||||
SiteCustomizationSettings,
|
SiteCustomizationSettings,
|
||||||
Space,
|
Space,
|
||||||
} from '@gitbook/api';
|
} from '@gitbook/api';
|
||||||
|
import { Icon } from '@gitbook/icons';
|
||||||
import { Metadata } from 'next';
|
import { Metadata } from 'next';
|
||||||
import { notFound } from 'next/navigation';
|
import { notFound } from 'next/navigation';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
|
||||||
import { getContentPointer } from '@/app/(space)/fetch';
|
import { DocumentView } from '@/components/DocumentView';
|
||||||
import { DocumentView, createHighlightingContext } from '@/components/DocumentView';
|
|
||||||
import { TrademarkLink } from '@/components/TableOfContents/Trademark';
|
import { TrademarkLink } from '@/components/TableOfContents/Trademark';
|
||||||
import { PolymorphicComponentProp } from '@/components/utils/types';
|
import { PolymorphicComponentProp } from '@/components/utils/types';
|
||||||
import { getSpaceLanguage } from '@/intl/server';
|
import { getSpaceLanguage } from '@/intl/server';
|
||||||
@@ -23,7 +21,7 @@ import {
|
|||||||
getSpace,
|
getSpace,
|
||||||
getSpaceCustomization,
|
getSpaceCustomization,
|
||||||
getSpaceContentData,
|
getSpaceContentData,
|
||||||
getCurrentSiteCustomization,
|
getSiteData,
|
||||||
} from '@/lib/api';
|
} from '@/lib/api';
|
||||||
import { pagePDFContainerId, PageHrefContext, absoluteHref } from '@/lib/links';
|
import { pagePDFContainerId, PageHrefContext, absoluteHref } from '@/lib/links';
|
||||||
import { resolvePageId } from '@/lib/pages';
|
import { resolvePageId } from '@/lib/pages';
|
||||||
@@ -33,6 +31,7 @@ import { PDFSearchParams, getPDFSearchParams } from '@/lib/urls';
|
|||||||
|
|
||||||
import './pdf.css';
|
import './pdf.css';
|
||||||
import { PageControlButtons } from './PageControlButtons';
|
import { PageControlButtons } from './PageControlButtons';
|
||||||
|
import { getSiteOrSpacePointerForPDF } from './pointer';
|
||||||
import { PrintButton } from './PrintButton';
|
import { PrintButton } from './PrintButton';
|
||||||
|
|
||||||
const DEFAULT_LIMIT = 100;
|
const DEFAULT_LIMIT = 100;
|
||||||
@@ -40,12 +39,10 @@ const DEFAULT_LIMIT = 100;
|
|||||||
export const runtime = 'edge';
|
export const runtime = 'edge';
|
||||||
|
|
||||||
export async function generateMetadata(): Promise<Metadata> {
|
export async function generateMetadata(): Promise<Metadata> {
|
||||||
const contentPointer = getContentPointer();
|
const pointer = getSiteOrSpacePointerForPDF();
|
||||||
const [space, customization] = await Promise.all([
|
const [space, { customization }] = await Promise.all([
|
||||||
getSpace(contentPointer.spaceId),
|
getSpace(pointer.spaceId, 'siteId' in pointer ? pointer.siteShareKey : undefined),
|
||||||
'siteId' in contentPointer
|
'siteId' in pointer ? getSiteData(pointer) : getSpaceCustomization(pointer.spaceId),
|
||||||
? getCurrentSiteCustomization(contentPointer)
|
|
||||||
: getSpaceCustomization(contentPointer.spaceId),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -58,7 +55,7 @@ export async function generateMetadata(): Promise<Metadata> {
|
|||||||
* Render a space as a standalone HTML page that can be printed as a PDF.
|
* Render a space as a standalone HTML page that can be printed as a PDF.
|
||||||
*/
|
*/
|
||||||
export default async function PDFHTMLOutput(props: { searchParams: { [key: string]: string } }) {
|
export default async function PDFHTMLOutput(props: { searchParams: { [key: string]: string } }) {
|
||||||
const contentPointer = getContentPointer();
|
const pointer = getSiteOrSpacePointerForPDF();
|
||||||
|
|
||||||
const searchParams = new URLSearchParams(props.searchParams);
|
const searchParams = new URLSearchParams(props.searchParams);
|
||||||
const pdfParams = getPDFSearchParams(new URLSearchParams(searchParams));
|
const pdfParams = getPDFSearchParams(new URLSearchParams(searchParams));
|
||||||
@@ -68,11 +65,9 @@ export default async function PDFHTMLOutput(props: { searchParams: { [key: strin
|
|||||||
currentPDFUrl += '?' + searchParams.toString();
|
currentPDFUrl += '?' + searchParams.toString();
|
||||||
|
|
||||||
// Load the content,
|
// Load the content,
|
||||||
const [customization, { space, contentTarget, pages: rootPages }] = await Promise.all([
|
const [{ customization }, { space, contentTarget, pages: rootPages }] = await Promise.all([
|
||||||
'siteId' in contentPointer
|
'siteId' in pointer ? getSiteData(pointer) : getSpaceCustomization(pointer.spaceId),
|
||||||
? getCurrentSiteCustomization(contentPointer)
|
getSpaceContentData(pointer, 'siteId' in pointer ? pointer.siteShareKey : undefined),
|
||||||
: getSpaceCustomization(contentPointer.spaceId),
|
|
||||||
getSpaceContentData(contentPointer),
|
|
||||||
]);
|
]);
|
||||||
const language = getSpaceLanguage(customization);
|
const language = getSpaceLanguage(customization);
|
||||||
|
|
||||||
@@ -110,7 +105,7 @@ export default async function PDFHTMLOutput(props: { searchParams: { [key: strin
|
|||||||
'border',
|
'border',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<ArrowLeft className={tcls('size-6')} />
|
<Icon icon="arrow-left" className={tcls('size-6')} />
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
@@ -136,7 +131,7 @@ export default async function PDFHTMLOutput(props: { searchParams: { [key: strin
|
|||||||
'border',
|
'border',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<Printer className={tcls('size-6')} />
|
<Icon icon="print" className={tcls('size-6')} />
|
||||||
</PrintButton>
|
</PrintButton>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -170,6 +165,7 @@ export default async function PDFHTMLOutput(props: { searchParams: { [key: strin
|
|||||||
space={space}
|
space={space}
|
||||||
page={page}
|
page={page}
|
||||||
refContext={{
|
refContext={{
|
||||||
|
siteContext: 'siteId' in pointer ? pointer : null,
|
||||||
space,
|
space,
|
||||||
revisionId: contentTarget.revisionId,
|
revisionId: contentTarget.revisionId,
|
||||||
pages: rootPages,
|
pages: rootPages,
|
||||||
@@ -231,7 +227,6 @@ async function PDFPageDocument(props: {
|
|||||||
const { space, page, refContext } = props;
|
const { space, page, refContext } = props;
|
||||||
|
|
||||||
const document = page.documentId ? await getDocument(space.id, page.documentId) : null;
|
const document = page.documentId ? await getDocument(space.id, page.documentId) : null;
|
||||||
const shouldHighlightCode = createHighlightingContext();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PrintPage id={pagePDFContainerId(page)}>
|
<PrintPage id={pagePDFContainerId(page)}>
|
||||||
@@ -254,7 +249,6 @@ async function PDFPageDocument(props: {
|
|||||||
contentRefContext: refContext,
|
contentRefContext: refContext,
|
||||||
resolveContentRef: (ref) => resolveContentRef(ref, refContext),
|
resolveContentRef: (ref) => resolveContentRef(ref, refContext),
|
||||||
getId: (id) => pagePDFContainerId(page, id),
|
getId: (id) => pagePDFContainerId(page, id),
|
||||||
shouldHighlightCode,
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
@@ -315,7 +309,7 @@ function selectPages(
|
|||||||
return [
|
return [
|
||||||
{ page, depth },
|
{ page, depth },
|
||||||
...page.pages.flatMap((child) => {
|
...page.pages.flatMap((child) => {
|
||||||
if (child.type === 'link') {
|
if (child.type !== 'document') {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,7 +344,7 @@ function selectPages(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const allPages = rootPages.flatMap((page) => {
|
const allPages = rootPages.flatMap((page) => {
|
||||||
if (page.type === 'link') {
|
if (page.type !== 'document' && page.type !== 'group') {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import { SiteContentPointer, SpaceContentPointer } from '@/lib/api';
|
||||||
|
import { getSiteContentPointer, getSpacePointer } from '@/lib/pointer';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PDF generation can be done at the site level (e.g. docs.foo.com/~gitbook/pdf) or
|
||||||
|
* at the space level (e.g. open.gitbook.com/~space/:spaceId/~gitbook/pdf) which is
|
||||||
|
* for PDF export of in-app private spaces.
|
||||||
|
*
|
||||||
|
* This function returns the pointer depending on the context.
|
||||||
|
*/
|
||||||
|
export function getSiteOrSpacePointerForPDF(): SiteContentPointer | SpaceContentPointer {
|
||||||
|
try {
|
||||||
|
return getSiteContentPointer();
|
||||||
|
} catch (error) {
|
||||||
|
return getSpacePointer();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,7 +30,7 @@ export async function POST(req: NextRequest) {
|
|||||||
// no-cors, *cors, same-origin
|
// no-cors, *cors, same-origin
|
||||||
// mode: 'cors', // Not supported on Cloudflare Workers
|
// mode: 'cors', // Not supported on Cloudflare Workers
|
||||||
// *default, no-cache, reload, force-cache, only-if-cached
|
// *default, no-cache, reload, force-cache, only-if-cached
|
||||||
cache: 'no-cache',
|
// cache: 'no-cache', // Not supported on Cloudflare Workers
|
||||||
// include, *same-origin, omit
|
// include, *same-origin, omit
|
||||||
// credentials: 'include', // Not supported on Cloudflare Workers
|
// credentials: 'include', // Not supported on Cloudflare Workers
|
||||||
headers: requestBody.headers,
|
headers: requestBody.headers,
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
// @ts-ignore
|
||||||
|
import nextOnPagesHandler from '@cloudflare/next-on-pages/fetch-handler';
|
||||||
|
|
||||||
|
import { withMiddlewareHeadersStorage } from './lib/middleware';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We use a custom entrypoint until we can move to opennext (https://github.com/opennextjs/opennextjs-cloudflare/issues/92).
|
||||||
|
* There is a bug in next-on-pages where headers can't be set on the response in the middleware for RSC requests (https://github.com/cloudflare/next-on-pages/issues/897).
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
async fetch(request, env, ctx) {
|
||||||
|
const response = await withMiddlewareHeadersStorage(() =>
|
||||||
|
nextOnPagesHandler.fetch(request, env, ctx),
|
||||||
|
);
|
||||||
|
|
||||||
|
return response;
|
||||||
|
},
|
||||||
|
} as ExportedHandler<{ ASSETS: Fetcher }>;
|
||||||
@@ -1,11 +1,16 @@
|
|||||||
import { Space } from '@gitbook/api';
|
import { Space } from '@gitbook/api';
|
||||||
|
import { Icon } from '@gitbook/icons';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { ContentPointer, getChangeRequest, getRevision } from '@/lib/api';
|
import { getChangeRequest, getRevision, SiteContentPointer } from '@/lib/api';
|
||||||
import { tcls } from '@/lib/tailwind';
|
import { tcls } from '@/lib/tailwind';
|
||||||
|
|
||||||
|
import { RefreshChangeRequestButton } from './RefreshChangeRequestButton';
|
||||||
|
import { Toolbar, ToolbarBody, ToolbarButton, ToolbarButtonGroups } from './Toolbar';
|
||||||
|
import { DateRelative } from '../primitives';
|
||||||
|
|
||||||
interface AdminToolbarProps {
|
interface AdminToolbarProps {
|
||||||
content: ContentPointer;
|
content: SiteContentPointer;
|
||||||
space: Space;
|
space: Space;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,9 +72,30 @@ async function ChangeRequestToolbar(props: { spaceId: string; changeRequestId: s
|
|||||||
const changeRequest = await getChangeRequest(spaceId, changeRequestId);
|
const changeRequest = await getChangeRequest(spaceId, changeRequestId);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ToolbarButton href={changeRequest.urls.app}>
|
<Toolbar>
|
||||||
Change request #{changeRequest.number}: {changeRequest.subject ?? 'No subject'}
|
<ToolbarButton title="Open in application" href={changeRequest.urls.app}>
|
||||||
|
<Icon icon="code-branch" className="size-4" />
|
||||||
</ToolbarButton>
|
</ToolbarButton>
|
||||||
|
<ToolbarBody>
|
||||||
|
<p>
|
||||||
|
#{changeRequest.number}: {changeRequest.subject ?? 'No subject'}
|
||||||
|
</p>
|
||||||
|
<p className="text-xs text-light/8 dark:text-light/8">
|
||||||
|
Change request updated <DateRelative value={changeRequest.updatedAt} />
|
||||||
|
</p>
|
||||||
|
</ToolbarBody>
|
||||||
|
<ToolbarButtonGroups>
|
||||||
|
<ToolbarButton title="Open in application" href={changeRequest.urls.app}>
|
||||||
|
<Icon icon="arrow-up-right-from-square" className="size-4" />
|
||||||
|
</ToolbarButton>
|
||||||
|
<RefreshChangeRequestButton
|
||||||
|
spaceId={spaceId}
|
||||||
|
changeRequestId={changeRequestId}
|
||||||
|
revisionId={changeRequest.revision}
|
||||||
|
updatedAt={new Date(changeRequest.updatedAt).getTime()}
|
||||||
|
/>
|
||||||
|
</ToolbarButtonGroups>
|
||||||
|
</Toolbar>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,37 +103,35 @@ async function RevisionToolbar(props: { spaceId: string; revisionId: string }) {
|
|||||||
const { spaceId, revisionId } = props;
|
const { spaceId, revisionId } = props;
|
||||||
|
|
||||||
const revision = await getRevision(spaceId, revisionId, {
|
const revision = await getRevision(spaceId, revisionId, {
|
||||||
metadata: false,
|
metadata: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ToolbarButton href={revision.urls.app}>
|
<Toolbar>
|
||||||
Revision created on {new Date(revision.createdAt).toLocaleDateString()}
|
<ToolbarButton title="Open in application" href={revision.urls.app}>
|
||||||
|
<Icon icon="code-commit" className="size-4" />
|
||||||
</ToolbarButton>
|
</ToolbarButton>
|
||||||
);
|
<ToolbarBody>
|
||||||
}
|
<p>
|
||||||
|
Revision created <DateRelative value={revision.createdAt} />
|
||||||
function ToolbarButton(props: { href: string; children: React.ReactNode }) {
|
</p>
|
||||||
const { href, children } = props;
|
{revision.git ? (
|
||||||
|
<p className="text-xs text-light/8 dark:text-light/8">{revision.git.message}</p>
|
||||||
return (
|
) : null}
|
||||||
<a
|
</ToolbarBody>
|
||||||
href={href}
|
<ToolbarButtonGroups>
|
||||||
className={tcls(
|
<ToolbarButton title="Open in application" href={revision.urls.app}>
|
||||||
'block',
|
<Icon icon="arrow-up-right-from-square" className="size-4" />
|
||||||
'text-sm',
|
</ToolbarButton>
|
||||||
'px-4',
|
{revision.git?.url ? (
|
||||||
'py-1',
|
<ToolbarButton title="Open git commit" href={revision.git.url}>
|
||||||
'rounded-full',
|
<Icon
|
||||||
'hover:bg-dark-1',
|
icon={revision.git.url.includes('github.com') ? 'github' : 'gitlab'}
|
||||||
'hover:text-white',
|
className="size-4"
|
||||||
'truncate',
|
/>
|
||||||
'text-light',
|
</ToolbarButton>
|
||||||
'dark:text-light',
|
) : null}
|
||||||
'dark:hover:bg-dark-2',
|
</ToolbarButtonGroups>
|
||||||
)}
|
</Toolbar>
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</a>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
'use client';
|
||||||
|
import { Icon } from '@gitbook/icons';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { useCheckForContentUpdate } from '@/components/AutoRefreshContent';
|
||||||
|
import { tcls } from '@/lib/tailwind';
|
||||||
|
|
||||||
|
import { ToolbarButton } from './Toolbar';
|
||||||
|
|
||||||
|
// We don't show the button if the content has been updated 30s ago or less.
|
||||||
|
const minInterval = 1000 * 30; // 5 minutes
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Button to refresh the page if the content has been updated.
|
||||||
|
*/
|
||||||
|
export function RefreshChangeRequestButton(props: {
|
||||||
|
spaceId: string;
|
||||||
|
changeRequestId: string;
|
||||||
|
revisionId: string;
|
||||||
|
updatedAt: number;
|
||||||
|
}) {
|
||||||
|
const { updatedAt } = props;
|
||||||
|
|
||||||
|
const [visible, setVisible] = React.useState(false);
|
||||||
|
const [loading, setLoading] = React.useState(false);
|
||||||
|
const checkForUpdates = useCheckForContentUpdate(props);
|
||||||
|
|
||||||
|
const refresh = React.useCallback(async () => {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
await checkForUpdates();
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
setVisible(false);
|
||||||
|
}
|
||||||
|
}, [checkForUpdates]);
|
||||||
|
|
||||||
|
// Show the button if the content has been updated more than 30s ago.
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (updatedAt < Date.now() - minInterval) {
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
}, [updatedAt]);
|
||||||
|
|
||||||
|
// 30sec after being hidden, we show the button again
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (!visible) {
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
setVisible(true);
|
||||||
|
}, minInterval);
|
||||||
|
return () => clearTimeout(timeout);
|
||||||
|
}
|
||||||
|
}, [visible]);
|
||||||
|
|
||||||
|
if (!visible) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ToolbarButton
|
||||||
|
title="Refresh"
|
||||||
|
onClick={(event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
refresh();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Icon icon="rotate" className={tcls('size-4', loading ? 'animate-spin' : null)} />
|
||||||
|
</ToolbarButton>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import { tcls } from '@/lib/tailwind';
|
||||||
|
|
||||||
|
export function Toolbar(props: { children: React.ReactNode }) {
|
||||||
|
const { children } = props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={tcls(
|
||||||
|
'flex',
|
||||||
|
'flex-row',
|
||||||
|
'items-center',
|
||||||
|
'gap-4',
|
||||||
|
'text-sm',
|
||||||
|
'px-4',
|
||||||
|
'py-1',
|
||||||
|
'rounded-full',
|
||||||
|
'truncate',
|
||||||
|
'text-light',
|
||||||
|
'dark:text-light',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ToolbarBody(props: { children: React.ReactNode }) {
|
||||||
|
return <div className="flex flex-col gap-1">{props.children}</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ToolbarButtonGroups(props: { children: React.ReactNode }) {
|
||||||
|
return <div className="flex flex-row gap-2">{props.children}</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ToolbarButton(props: React.HTMLProps<HTMLAnchorElement>) {
|
||||||
|
const { children, ...rest } = props;
|
||||||
|
return (
|
||||||
|
<a
|
||||||
|
{...rest}
|
||||||
|
className={tcls(
|
||||||
|
'flex',
|
||||||
|
'flex-col',
|
||||||
|
'items-center',
|
||||||
|
'justify-center',
|
||||||
|
'size-11',
|
||||||
|
'gap-1',
|
||||||
|
'text-sm',
|
||||||
|
'rounded-full',
|
||||||
|
'hover:bg-dark-1',
|
||||||
|
'hover:text-white',
|
||||||
|
'truncate',
|
||||||
|
'text-light',
|
||||||
|
'dark:text-light',
|
||||||
|
'dark:hover:bg-dark-2',
|
||||||
|
'hover:shadow-lg',
|
||||||
|
'cursor-pointer',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</a>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,13 +1,17 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import IconHeart from '@geist-ui/icons/heart';
|
import { SiteAds, SiteAdsStatus } from '@gitbook/api';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import { t, useLanguage } from '@/intl/client';
|
||||||
import { ClassValue, tcls } from '@/lib/tailwind';
|
import { ClassValue, tcls } from '@/lib/tailwind';
|
||||||
|
|
||||||
import { AdClassicRendering } from './AdClassicRendering';
|
import { renderAd } from './renderAd';
|
||||||
import { AdCoverRendering } from './AdCoverRendering';
|
|
||||||
import { AdItem, AdsResponse } from './types';
|
/**
|
||||||
|
* Zone ID provided by BuySellAds for the preview.
|
||||||
|
*/
|
||||||
|
const PREVIEW_ZONE_ID = 'CVAIKKQM';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch and render the Ad placement.
|
* Fetch and render the Ad placement.
|
||||||
@@ -18,20 +22,21 @@ export function Ad({
|
|||||||
spaceId,
|
spaceId,
|
||||||
placement,
|
placement,
|
||||||
ignore,
|
ignore,
|
||||||
|
siteAdsStatus,
|
||||||
style,
|
style,
|
||||||
mode = 'auto',
|
mode = 'auto',
|
||||||
}: {
|
}: {
|
||||||
zoneId: string;
|
zoneId: string | null;
|
||||||
spaceId: string;
|
spaceId: string;
|
||||||
placement: string;
|
placement: string;
|
||||||
ignore: boolean;
|
ignore: boolean;
|
||||||
style?: ClassValue;
|
style?: ClassValue;
|
||||||
|
siteAdsStatus?: SiteAds['status'];
|
||||||
mode?: 'classic' | 'auto' | 'cover';
|
mode?: 'classic' | 'auto' | 'cover';
|
||||||
}) {
|
}) {
|
||||||
const containerRef = React.useRef<HTMLDivElement>(null);
|
const containerRef = React.useRef<HTMLDivElement>(null);
|
||||||
const [visible, setVisible] = React.useState(false);
|
const [visible, setVisible] = React.useState(false);
|
||||||
const [failed, setFailed] = React.useState(false);
|
const [ad, setAd] = React.useState<React.ReactNode | undefined>(undefined);
|
||||||
const [ad, setAd] = React.useState<AdItem | undefined>(undefined);
|
|
||||||
|
|
||||||
// Observe the container visibility
|
// Observe the container visibility
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
@@ -68,55 +73,68 @@ export function Ad({
|
|||||||
|
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
|
|
||||||
(async () => {
|
const previewParam = new URL(window.location.href).searchParams.get('ads_preview');
|
||||||
const url = new URL(`https://srv.buysellads.com/ads/${zoneId}.json`);
|
const preview = !!previewParam;
|
||||||
url.searchParams.set('segment', `placement:${placement}`);
|
const realZoneId = preview ? PREVIEW_ZONE_ID : zoneId;
|
||||||
url.searchParams.set('v', 'true');
|
const showPlaceholderAd =
|
||||||
if (ignore) {
|
previewParam === 'placeholder' ||
|
||||||
url.searchParams.set('ignore', 'true');
|
(siteAdsStatus &&
|
||||||
|
(siteAdsStatus === SiteAdsStatus.Pending ||
|
||||||
|
siteAdsStatus === SiteAdsStatus.InReview));
|
||||||
|
|
||||||
|
if (!realZoneId && !showPlaceholderAd) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
(async () => {
|
||||||
const res = await fetch(url);
|
const result = showPlaceholderAd
|
||||||
const json: AdsResponse = await res.json();
|
? await renderAd({ source: 'placeholder' })
|
||||||
|
: realZoneId
|
||||||
|
? await renderAd({
|
||||||
|
placement,
|
||||||
|
ignore: ignore || preview,
|
||||||
|
zoneId: realZoneId,
|
||||||
|
mode,
|
||||||
|
source: 'live',
|
||||||
|
})
|
||||||
|
: undefined;
|
||||||
|
|
||||||
if (cancelled) {
|
if (cancelled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const first = json.ads[0];
|
if (result) {
|
||||||
if (first && 'active' in first) {
|
setAd(result);
|
||||||
setAd(first);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(
|
|
||||||
'Failed to fetch ad, it might have been blocked by a ad-blocker',
|
|
||||||
error,
|
|
||||||
);
|
|
||||||
setFailed(true);
|
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
};
|
};
|
||||||
}, [visible, zoneId, ignore, placement]);
|
}, [visible, zoneId, ignore, placement, mode, siteAdsStatus]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div ref={containerRef} className={tcls(style)} data-visual-test="removed">
|
||||||
|
{ad ? (
|
||||||
|
<>
|
||||||
|
{ad}
|
||||||
|
<AdSponsoredLink spaceId={spaceId} />
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function AdSponsoredLink(props: { spaceId: string }) {
|
||||||
|
const { spaceId } = props;
|
||||||
|
const language = useLanguage();
|
||||||
|
|
||||||
const viaUrl = new URL('https://www.gitbook.com');
|
const viaUrl = new URL('https://www.gitbook.com');
|
||||||
viaUrl.searchParams.set('utm_source', 'content');
|
viaUrl.searchParams.set('utm_source', 'content');
|
||||||
viaUrl.searchParams.set('utm_medium', 'ads');
|
viaUrl.searchParams.set('utm_medium', 'sponsored-by-gitbook');
|
||||||
viaUrl.searchParams.set('utm_campaign', spaceId);
|
viaUrl.searchParams.set('utm_campaign', spaceId);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={containerRef} className={tcls(style)}>
|
|
||||||
{ad && ad.description && ad.statlink ? (
|
|
||||||
<>
|
|
||||||
{mode === 'classic' || !('callToAction' in ad) ? (
|
|
||||||
<AdClassicRendering ad={ad} />
|
|
||||||
) : (
|
|
||||||
<AdCoverRendering ad={ad} />
|
|
||||||
)}
|
|
||||||
{ad.pixel ? <AdPixels rawPixel={ad.pixel} /> : null}
|
|
||||||
<p
|
<p
|
||||||
className={tcls(
|
className={tcls(
|
||||||
'mt-2',
|
'mt-2',
|
||||||
@@ -127,74 +145,9 @@ export function Ad({
|
|||||||
'dark:text-light/5',
|
'dark:text-light/5',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<a
|
<a target="_blank" href={viaUrl.toString()} className={tcls('hover:underline')}>
|
||||||
target="_blank"
|
{t(language, 'sponsored_via_gitbook')}
|
||||||
href={viaUrl.toString()}
|
|
||||||
className={tcls('hover:underline')}
|
|
||||||
>
|
|
||||||
Ads via GitBook
|
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
</>
|
|
||||||
) : failed ? (
|
|
||||||
<AdBlockerPlaceholder />
|
|
||||||
) : null}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Render attribution or verification pixels.
|
|
||||||
* https://docs.buysellads.com/ad-serving-api#pixels
|
|
||||||
*/
|
|
||||||
function AdPixels({ rawPixel }: { rawPixel: string }) {
|
|
||||||
const pixels = rawPixel.split('||');
|
|
||||||
const time = String(Math.round(Date.now() / 1e4) | 0);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={tcls('hidden')}>
|
|
||||||
{pixels.map((pixel, index) => {
|
|
||||||
return (
|
|
||||||
<img
|
|
||||||
key={index}
|
|
||||||
src={pixel.replace('[timestamp]', time)}
|
|
||||||
width="1"
|
|
||||||
height="1"
|
|
||||||
style={{ display: 'none' }}
|
|
||||||
alt="Ads tracking pixel"
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Placeholder when visitor has an ad-blocker.
|
|
||||||
*/
|
|
||||||
function AdBlockerPlaceholder() {
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className={tcls(
|
|
||||||
'flex',
|
|
||||||
'flex-col',
|
|
||||||
'gap-3',
|
|
||||||
'bg-light-2',
|
|
||||||
'text-dark/7',
|
|
||||||
'dark:bg-dark-2',
|
|
||||||
'dark:text-light/7',
|
|
||||||
'rounded-lg',
|
|
||||||
'p-4',
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<div className={tcls('flex', 'flex-row', 'gap-2', 'items-center')}>
|
|
||||||
<IconHeart className={tcls('w-4', 'h-4', 'text-primary-500')} />
|
|
||||||
<p className={tcls('text-xs', 'font-semibold')}>Ad disabled</p>
|
|
||||||
</div>
|
|
||||||
<p className={tcls('text-xs')}>
|
|
||||||
{`It looks like you're using an adblocker. Whitelist this site to help support this
|
|
||||||
project.`}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import { getResizedImageURL } from '@/lib/images';
|
||||||
import { tcls } from '@/lib/tailwind';
|
import { tcls } from '@/lib/tailwind';
|
||||||
|
|
||||||
import { AdItem } from './types';
|
import { AdItem } from './types';
|
||||||
@@ -29,14 +30,21 @@ export function AdClassicRendering({ ad }: { ad: AdItem }) {
|
|||||||
>
|
>
|
||||||
{'smallImage' in ad ? (
|
{'smallImage' in ad ? (
|
||||||
<div>
|
<div>
|
||||||
<img alt="Ads logo" className={tcls('rounded-md')} src={ad.smallImage} />
|
<img
|
||||||
|
alt="Ads logo"
|
||||||
|
className={tcls('rounded-md')}
|
||||||
|
src={getResizedImageURL(ad.smallImage, { width: 192, dpr: 2 })}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div
|
<div
|
||||||
className={tcls('px-6', 'py-4', 'rounded-md')}
|
className={tcls('px-6', 'py-4', 'rounded-md')}
|
||||||
style={{ backgroundColor: ad.backgroundColor }}
|
style={{ backgroundColor: ad.backgroundColor }}
|
||||||
>
|
>
|
||||||
<img alt="Ads logo" src={ad.logo} />
|
<img
|
||||||
|
alt="Ads logo"
|
||||||
|
src={getResizedImageURL(ad.logo, { width: 192 - 48, dpr: 2 })}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className={tcls('flex', 'flex-col')}>
|
<div className={tcls('flex', 'flex-col')}>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
|
||||||
import { hexToRgba } from '@/lib/colors';
|
import { hexToRgba } from '@/lib/colors';
|
||||||
|
import { getResizedImageURL } from '@/lib/images';
|
||||||
import { tcls } from '@/lib/tailwind';
|
import { tcls } from '@/lib/tailwind';
|
||||||
|
|
||||||
import { AdCover } from './types';
|
import { AdCover } from './types';
|
||||||
@@ -9,6 +10,8 @@ import { AdCover } from './types';
|
|||||||
* Cover rendering for an ad.
|
* Cover rendering for an ad.
|
||||||
*/
|
*/
|
||||||
export function AdCoverRendering({ ad }: { ad: AdCover }) {
|
export function AdCoverRendering({ ad }: { ad: AdCover }) {
|
||||||
|
const largeImage = getResizedImageURL(ad.largeImage, { width: 128, dpr: 2 });
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<a
|
<a
|
||||||
className={tcls(
|
className={tcls(
|
||||||
@@ -43,14 +46,14 @@ export function AdCoverRendering({ ad }: { ad: AdCover }) {
|
|||||||
'z-0',
|
'z-0',
|
||||||
)}
|
)}
|
||||||
style={{
|
style={{
|
||||||
backgroundImage: `url(${ad.largeImage})`,
|
backgroundImage: `url(${largeImage})`,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className={tcls('z-[2]')}>
|
<div className={tcls('z-[2]')}>
|
||||||
<img
|
<img
|
||||||
alt="Large image"
|
alt="Large image"
|
||||||
src={ad.largeImage}
|
src={largeImage}
|
||||||
className={tcls(
|
className={tcls(
|
||||||
'rounded-md',
|
'rounded-md',
|
||||||
'shadow-md',
|
'shadow-md',
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import { tcls } from '@/lib/tailwind';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render attribution or verification pixels.
|
||||||
|
* https://docs.buysellads.com/ad-serving-api#pixels
|
||||||
|
*/
|
||||||
|
export function AdPixels({ rawPixel }: { rawPixel: string }) {
|
||||||
|
const pixels = rawPixel.split('||');
|
||||||
|
const time = String(Math.round(Date.now() / 1e4) | 0);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={tcls('hidden')}>
|
||||||
|
{pixels.map((pixel, index) => {
|
||||||
|
return (
|
||||||
|
<img
|
||||||
|
key={index}
|
||||||
|
src={pixel.replace('[timestamp]', time)}
|
||||||
|
width="1"
|
||||||
|
height="1"
|
||||||
|
style={{ display: 'none' }}
|
||||||
|
alt="Ads tracking pixel"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
<svg width="193" height="120" viewBox="0 0 193 120" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path
|
||||||
|
d="M183.432 0.776855H10.2788C5.07442 0.776855 0.855469 4.14309 0.855469 8.29556V111.678C0.855469 115.831 5.07442 119.197 10.2788 119.197H183.432C188.637 119.197 192.855 115.831 192.855 111.678V8.29556C192.855 4.14309 188.637 0.776855 183.432 0.776855Z"
|
||||||
|
fill="#14171C" />
|
||||||
|
<path fill-rule="evenodd" clip-rule="evenodd"
|
||||||
|
d="M96.8556 72.2159C84.724 72.2159 74.8894 82.0505 74.8894 94.1818C74.8894 95.9661 73.4431 97.4124 71.659 97.4124C69.875 97.4124 68.4287 95.9661 68.4287 94.1818C68.4287 78.4825 81.1558 65.7554 96.8556 65.7554C112.556 65.7554 125.282 78.4825 125.282 94.1818C125.282 95.9661 123.836 97.4124 122.053 97.4124C120.268 97.4124 118.822 95.9661 118.822 94.1818C118.822 82.0505 108.987 72.2159 96.8556 72.2159Z"
|
||||||
|
fill="url(#paint0_radial_3089_1090)" />
|
||||||
|
<path fill-rule="evenodd" clip-rule="evenodd"
|
||||||
|
d="M129.621 94.1816C129.621 76.0865 114.951 61.4172 96.8558 61.4172C78.7603 61.4172 64.091 76.0865 64.091 94.1816C64.091 95.9658 62.6447 97.4122 60.8607 97.4122C59.0766 97.4122 57.6304 95.9658 57.6304 94.1816C57.6304 72.5183 75.1922 54.9565 96.8558 54.9565C118.52 54.9565 136.081 72.5183 136.081 94.1816C136.081 95.9658 134.635 97.4122 132.85 97.4122C131.067 97.4122 129.621 95.9658 129.621 94.1816Z"
|
||||||
|
fill="url(#paint1_radial_3089_1090)" />
|
||||||
|
<path fill-rule="evenodd" clip-rule="evenodd"
|
||||||
|
d="M96.856 50.3419C72.6438 50.3419 53.0159 69.9698 53.0159 94.1818C53.0159 95.966 51.5695 97.4124 49.7855 97.4124C48.0014 97.4124 46.5552 95.966 46.5552 94.1818C46.5552 66.4018 69.0756 43.8813 96.856 43.8813C124.637 43.8813 147.157 66.4018 147.157 94.1818C147.157 95.966 145.711 97.4124 143.927 97.4124C142.142 97.4124 140.696 95.966 140.696 94.1818C140.696 69.9698 121.068 50.3419 96.856 50.3419Z"
|
||||||
|
fill="url(#paint2_radial_3089_1090)" />
|
||||||
|
<path fill-rule="evenodd" clip-rule="evenodd"
|
||||||
|
d="M151.587 94.1815C151.587 63.9548 127.083 39.4509 96.8557 39.4509C66.6286 39.4509 42.1246 63.9548 42.1246 94.1815C42.1246 95.9658 40.6784 97.4121 38.8943 97.4121C37.1103 97.4121 35.6641 95.9658 35.6641 94.1815C35.6641 60.3866 63.0605 32.9902 96.8557 32.9902C130.651 32.9902 158.047 60.3866 158.047 94.1815C158.047 95.9658 156.601 97.4121 154.818 97.4121C153.033 97.4121 151.587 95.9658 151.587 94.1815Z"
|
||||||
|
fill="url(#paint3_radial_3089_1090)" />
|
||||||
|
<path fill-rule="evenodd" clip-rule="evenodd"
|
||||||
|
d="M96.8554 29.0217C60.8683 29.0217 31.6951 58.195 31.6951 94.1817C31.6951 95.966 30.2488 97.4123 28.4647 97.4123C26.6807 97.4123 25.2344 95.966 25.2344 94.1817C25.2344 54.6269 57.3003 22.561 96.8554 22.561C136.411 22.561 168.477 54.6269 168.477 94.1817C168.477 95.966 167.03 97.4123 165.246 97.4123C163.462 97.4123 162.015 95.966 162.015 94.1817C162.015 58.195 132.842 29.0217 96.8554 29.0217Z"
|
||||||
|
fill="url(#paint4_radial_3089_1090)" />
|
||||||
|
<defs>
|
||||||
|
<radialGradient id="paint0_radial_3089_1090" cx="0" cy="0" r="1"
|
||||||
|
gradientUnits="userSpaceOnUse"
|
||||||
|
gradientTransform="translate(88.9053 80.4777) rotate(64.8515) scale(18.7082 33.8612)">
|
||||||
|
<stop stop-color="#3F89A1" />
|
||||||
|
<stop offset="0.339725" stop-color="#F4E28D" />
|
||||||
|
<stop offset="0.505624" stop-color="#BBDDE5" />
|
||||||
|
<stop offset="0.848958" stop-color="#FDA599" />
|
||||||
|
</radialGradient>
|
||||||
|
<radialGradient id="paint1_radial_3089_1090" cx="0" cy="0" r="1"
|
||||||
|
gradientUnits="userSpaceOnUse"
|
||||||
|
gradientTransform="translate(143.478 58.0317) rotate(168.06) scale(87.7455 57.2588)">
|
||||||
|
<stop stop-color="#3F89A1" />
|
||||||
|
<stop offset="0.19" stop-color="#F4E28D" />
|
||||||
|
<stop offset="0.614011" stop-color="#BBDDE5" />
|
||||||
|
<stop offset="1" stop-color="#FDA599" />
|
||||||
|
</radialGradient>
|
||||||
|
<radialGradient id="paint2_radial_3089_1090" cx="0" cy="0" r="1"
|
||||||
|
gradientUnits="userSpaceOnUse"
|
||||||
|
gradientTransform="translate(82.7879 68.7762) rotate(63.8366) scale(31.9052 59.4091)">
|
||||||
|
<stop stop-color="#3F89A1" />
|
||||||
|
<stop offset="0.339725" stop-color="#F4E28D" />
|
||||||
|
<stop offset="0.505624" stop-color="#BBDDE5" />
|
||||||
|
<stop offset="0.848958" stop-color="#FDA599" />
|
||||||
|
</radialGradient>
|
||||||
|
<radialGradient id="paint3_radial_3089_1090" cx="0" cy="0" r="1"
|
||||||
|
gradientUnits="userSpaceOnUse"
|
||||||
|
gradientTransform="translate(101.132 56.1925) rotate(172.165) scale(66.0854 41.9909)">
|
||||||
|
<stop stop-color="#3F89A1" />
|
||||||
|
<stop offset="0.339725" stop-color="#F4E28D" />
|
||||||
|
<stop offset="0.505624" stop-color="#BBDDE5" />
|
||||||
|
<stop offset="0.848958" stop-color="#FDA599" />
|
||||||
|
</radialGradient>
|
||||||
|
<radialGradient id="paint4_radial_3089_1090" cx="0" cy="0" r="1"
|
||||||
|
gradientUnits="userSpaceOnUse"
|
||||||
|
gradientTransform="translate(76.8246 57.371) rotate(63.4233) scale(44.7721 84.288)">
|
||||||
|
<stop stop-color="#3F89A1" />
|
||||||
|
<stop offset="0.339725" stop-color="#F4E28D" />
|
||||||
|
<stop offset="0.505624" stop-color="#BBDDE5" />
|
||||||
|
<stop offset="0.848958" stop-color="#FDA599" />
|
||||||
|
</radialGradient>
|
||||||
|
</defs>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 5.1 KiB |
@@ -0,0 +1,134 @@
|
|||||||
|
'use server';
|
||||||
|
|
||||||
|
import { headers } from 'next/headers';
|
||||||
|
|
||||||
|
import { AdClassicRendering } from './AdClassicRendering';
|
||||||
|
import { AdCoverRendering } from './AdCoverRendering';
|
||||||
|
import { AdPixels } from './AdPixels';
|
||||||
|
import adRainbow from './assets/ad-rainbow.svg';
|
||||||
|
import { AdItem, AdsResponse } from './types';
|
||||||
|
|
||||||
|
type FetchAdOptions = FetchLiveAdOptions | FetchPlaceholderAdOptions;
|
||||||
|
|
||||||
|
interface FetchLiveAdOptions {
|
||||||
|
/**
|
||||||
|
* Source of the ad (live: from the platform)
|
||||||
|
*/
|
||||||
|
source: 'live';
|
||||||
|
/** ID of the zone to fetch Ads for */
|
||||||
|
zoneId: string;
|
||||||
|
/** Mode to render the Ad */
|
||||||
|
mode: 'classic' | 'auto' | 'cover';
|
||||||
|
/** Name of the placement for the ad */
|
||||||
|
placement: string;
|
||||||
|
/** If true, we'll not track it as an impression */
|
||||||
|
ignore: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface FetchPlaceholderAdOptions {
|
||||||
|
/**
|
||||||
|
* Source of the ad (placeholder: static placeholder ad)
|
||||||
|
*/
|
||||||
|
source: 'placeholder';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Server action to render the Ad placement.
|
||||||
|
* We use a server-action to avoid caching issues with server-side components,
|
||||||
|
* and properly access user-agent and IP.
|
||||||
|
*/
|
||||||
|
export async function renderAd(options: FetchAdOptions) {
|
||||||
|
const mode = options.source === 'live' ? options.mode : 'classic';
|
||||||
|
|
||||||
|
const result = options.source === 'live' ? await fetchAd(options) : getPlaceholderAd();
|
||||||
|
if (!result || !result.ad.description || !result.ad.statlink) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { ad } = result;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{mode === 'classic' || !('callToAction' in ad) ? (
|
||||||
|
<AdClassicRendering ad={ad} />
|
||||||
|
) : (
|
||||||
|
<AdCoverRendering ad={ad} />
|
||||||
|
)}
|
||||||
|
{ad.pixel ? <AdPixels rawPixel={ad.pixel} /> : null}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchAd({
|
||||||
|
zoneId,
|
||||||
|
placement,
|
||||||
|
ignore,
|
||||||
|
}: FetchLiveAdOptions): Promise<{ ad: AdItem; ip: string } | null> {
|
||||||
|
const { ip, userAgent } = getUserAgentAndIp();
|
||||||
|
|
||||||
|
const url = new URL(`https://srv.buysellads.com/ads/${zoneId}.json`);
|
||||||
|
url.searchParams.set('segment', `placement:${placement}`);
|
||||||
|
url.searchParams.set('v', 'true');
|
||||||
|
url.searchParams.set('forwardedip', ip);
|
||||||
|
url.searchParams.set('useragent', userAgent);
|
||||||
|
if (ignore) {
|
||||||
|
url.searchParams.set('ignore', 'true');
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await fetch(url);
|
||||||
|
const json: AdsResponse = await res.json();
|
||||||
|
|
||||||
|
const first = json.ads[0];
|
||||||
|
if (first && 'active' in first) {
|
||||||
|
return { ad: first, ip };
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPlaceholderAd(): { ad: AdItem; ip: string } {
|
||||||
|
const { ip } = getUserAgentAndIp();
|
||||||
|
|
||||||
|
return {
|
||||||
|
ad: {
|
||||||
|
active: '1',
|
||||||
|
ad_via_link: '',
|
||||||
|
bannerid: '',
|
||||||
|
creativeid: '',
|
||||||
|
description:
|
||||||
|
'Your docs could be this good.\nPublish incredible open source docs for free with GitBook',
|
||||||
|
evenodd: '0',
|
||||||
|
external_id: '',
|
||||||
|
height: '0',
|
||||||
|
i: '0',
|
||||||
|
identifier: '',
|
||||||
|
longimp: '',
|
||||||
|
longlink: '',
|
||||||
|
num_slots: '1',
|
||||||
|
rendering: 'carbon',
|
||||||
|
smallImage: adRainbow.src,
|
||||||
|
statimp: '',
|
||||||
|
statlink:
|
||||||
|
'https://www.gitbook.com/solutions/open-source?utm_campaign=sponsored-content&utm_medium=ad&utm_source=content',
|
||||||
|
timestamp: Date.now().toString(),
|
||||||
|
width: '0',
|
||||||
|
zoneid: '',
|
||||||
|
zonekey: '',
|
||||||
|
},
|
||||||
|
ip,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function getUserAgentAndIp() {
|
||||||
|
const headersSet = headers();
|
||||||
|
const ip =
|
||||||
|
headersSet.get('x-gitbook-ipv4') ??
|
||||||
|
headersSet.get('x-gitbook-ip') ??
|
||||||
|
headersSet.get('cf-pseudo-ipv4') ??
|
||||||
|
headersSet.get('cf-connecting-ip') ??
|
||||||
|
headersSet.get('x-forwarded-for') ??
|
||||||
|
'';
|
||||||
|
const userAgent = headersSet.get('user-agent') ?? '';
|
||||||
|
|
||||||
|
return { ip, userAgent };
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export * from './useCheckForContentUpdate';
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
'use server';
|
||||||
|
|
||||||
|
import { getChangeRequest } from '@/lib/api';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if a change-request has been updated.
|
||||||
|
*/
|
||||||
|
export async function hasContentBeenUpdated(props: {
|
||||||
|
spaceId: string;
|
||||||
|
changeRequestId: string;
|
||||||
|
revisionId: string;
|
||||||
|
}) {
|
||||||
|
const changeRequest = await getChangeRequest.revalidate(props.spaceId, props.changeRequestId);
|
||||||
|
return changeRequest.revision !== props.revisionId;
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { hasContentBeenUpdated } from './server-actions';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a callback to check if a change request has been updated and to refresh the page if it has.
|
||||||
|
*/
|
||||||
|
export function useCheckForContentUpdate(props: {
|
||||||
|
spaceId: string;
|
||||||
|
changeRequestId: string;
|
||||||
|
revisionId: string;
|
||||||
|
}) {
|
||||||
|
const { spaceId, changeRequestId, revisionId } = props;
|
||||||
|
|
||||||
|
return React.useCallback(async () => {
|
||||||
|
const updated = await hasContentBeenUpdated({ spaceId, changeRequestId, revisionId });
|
||||||
|
|
||||||
|
if (updated) {
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
}, [spaceId, changeRequestId, revisionId]);
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import IconX from '@geist-ui/icons/x';
|
import { Icon } from '@gitbook/icons';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
|
||||||
import { Button } from '@/components/primitives';
|
import { Button } from '@/components/primitives';
|
||||||
@@ -27,7 +27,6 @@ export function CookiesToast(props: { privacyPolicy?: string }) {
|
|||||||
|
|
||||||
const onUpdateState = (enabled: boolean) => {
|
const onUpdateState = (enabled: boolean) => {
|
||||||
setCookiesTracking(enabled);
|
setCookiesTracking(enabled);
|
||||||
|
|
||||||
// Reload the page to take the change in consideration
|
// Reload the page to take the change in consideration
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
};
|
};
|
||||||
@@ -75,6 +74,7 @@ export function CookiesToast(props: { privacyPolicy?: string }) {
|
|||||||
)}
|
)}
|
||||||
</p>
|
</p>
|
||||||
<button
|
<button
|
||||||
|
type="button"
|
||||||
onClick={() => setShow(false)}
|
onClick={() => setShow(false)}
|
||||||
aria-label={tString(language, 'cookies_close')}
|
aria-label={tString(language, 'cookies_close')}
|
||||||
className={tcls(
|
className={tcls(
|
||||||
@@ -92,7 +92,7 @@ export function CookiesToast(props: { privacyPolicy?: string }) {
|
|||||||
)}
|
)}
|
||||||
title={tString(language, 'cookies_close')}
|
title={tString(language, 'cookies_close')}
|
||||||
>
|
>
|
||||||
<IconX className={tcls('w-4')} />
|
<Icon icon="xmark" className={tcls('size-4')} />
|
||||||
</button>
|
</button>
|
||||||
<div className={tcls('mt-3', 'flex', 'flex-row', 'gap-2')}>
|
<div className={tcls('mt-3', 'flex', 'flex-row', 'gap-2')}>
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ export async function Annotation(props: InlineProps<DocumentInlineAnnotation>) {
|
|||||||
ancestorBlocks={[]}
|
ancestorBlocks={[]}
|
||||||
context={context}
|
context={context}
|
||||||
nodes={fragment.nodes}
|
nodes={fragment.nodes}
|
||||||
|
style={['space-y-4']}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { DocumentBlock, JSONDocument } from '@gitbook/api';
|
import { DocumentBlock, JSONDocument } from '@gitbook/api';
|
||||||
import assertNever from 'assert-never';
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -12,7 +11,6 @@ import {
|
|||||||
import { ClassValue } from '@/lib/tailwind';
|
import { ClassValue } from '@/lib/tailwind';
|
||||||
|
|
||||||
import { BlockContentRef } from './BlockContentRef';
|
import { BlockContentRef } from './BlockContentRef';
|
||||||
import { BlockSyncedBlock } from './BlockSyncedBlock';
|
|
||||||
import { CodeBlock } from './CodeBlock';
|
import { CodeBlock } from './CodeBlock';
|
||||||
import { Divider } from './Divider';
|
import { Divider } from './Divider';
|
||||||
import { DocumentContextProps } from './DocumentView';
|
import { DocumentContextProps } from './DocumentView';
|
||||||
@@ -24,14 +22,15 @@ import { Heading } from './Heading';
|
|||||||
import { Hint } from './Hint';
|
import { Hint } from './Hint';
|
||||||
import { Images } from './Images';
|
import { Images } from './Images';
|
||||||
import { IntegrationBlock } from './Integration';
|
import { IntegrationBlock } from './Integration';
|
||||||
|
import { List } from './List';
|
||||||
import { ListItem } from './ListItem';
|
import { ListItem } from './ListItem';
|
||||||
import { ListOrdered } from './ListOrdered';
|
|
||||||
import { ListTasks } from './ListTasks';
|
|
||||||
import { ListUnordered } from './ListUnordered';
|
|
||||||
import { BlockMath } from './Math';
|
import { BlockMath } from './Math';
|
||||||
import { OpenAPI } from './OpenAPI';
|
import { OpenAPI } from './OpenAPI';
|
||||||
import { Paragraph } from './Paragraph';
|
import { Paragraph } from './Paragraph';
|
||||||
import { Quote } from './Quote';
|
import { Quote } from './Quote';
|
||||||
|
import { ReusableContent } from './ReusableContent';
|
||||||
|
import { Stepper } from './Stepper';
|
||||||
|
import { StepperStep } from './StepperStep';
|
||||||
import { Table } from './Table';
|
import { Table } from './Table';
|
||||||
import { Tabs } from './Tabs';
|
import { Tabs } from './Tabs';
|
||||||
|
|
||||||
@@ -39,77 +38,98 @@ export interface BlockProps<Block extends DocumentBlock> extends DocumentContext
|
|||||||
block: Block;
|
block: Block;
|
||||||
document: JSONDocument;
|
document: JSONDocument;
|
||||||
ancestorBlocks: DocumentBlock[];
|
ancestorBlocks: DocumentBlock[];
|
||||||
|
/** If true, we estimate that the block will be outside the initial viewport */
|
||||||
|
isEstimatedOffscreen: boolean;
|
||||||
|
/** Class names to be passed to the underlying DOM element */
|
||||||
style?: ClassValue;
|
style?: ClassValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alternative to `assertNever` that returns `null` instead of throwing an error.
|
||||||
|
*/
|
||||||
|
function nullIfNever(value: never): null {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
export function Block<T extends DocumentBlock>(props: BlockProps<T>) {
|
export function Block<T extends DocumentBlock>(props: BlockProps<T>) {
|
||||||
const { block, style, ...contextProps } = props;
|
const { block, style, isEstimatedOffscreen, context } = props;
|
||||||
|
|
||||||
const content = (() => {
|
const content = (() => {
|
||||||
switch (block.type) {
|
switch (block.type) {
|
||||||
case 'paragraph':
|
case 'paragraph':
|
||||||
return <Paragraph {...props} {...contextProps} block={block} />;
|
return <Paragraph {...props} block={block} />;
|
||||||
case 'heading-1':
|
case 'heading-1':
|
||||||
case 'heading-2':
|
case 'heading-2':
|
||||||
case 'heading-3':
|
case 'heading-3':
|
||||||
return <Heading {...props} {...contextProps} block={block} />;
|
return <Heading {...props} block={block} />;
|
||||||
case 'list-ordered':
|
case 'list-ordered':
|
||||||
return <ListOrdered {...props} {...contextProps} block={block} />;
|
|
||||||
case 'list-unordered':
|
case 'list-unordered':
|
||||||
return <ListUnordered {...props} {...contextProps} block={block} />;
|
|
||||||
case 'list-tasks':
|
case 'list-tasks':
|
||||||
return <ListTasks {...props} {...contextProps} block={block} />;
|
return <List {...props} block={block} />;
|
||||||
case 'list-item':
|
case 'list-item':
|
||||||
return <ListItem {...props} {...contextProps} block={block} />;
|
return <ListItem {...props} block={block} />;
|
||||||
case 'code':
|
case 'code':
|
||||||
return <CodeBlock {...props} {...contextProps} block={block} />;
|
return <CodeBlock {...props} block={block} />;
|
||||||
case 'hint':
|
case 'hint':
|
||||||
return <Hint {...props} {...contextProps} block={block} />;
|
return <Hint {...props} block={block} />;
|
||||||
case 'images':
|
case 'images':
|
||||||
return <Images {...props} {...contextProps} block={block} />;
|
return <Images {...props} block={block} />;
|
||||||
case 'tabs':
|
case 'tabs':
|
||||||
return <Tabs {...props} {...contextProps} block={block} />;
|
return <Tabs {...props} block={block} />;
|
||||||
case 'expandable':
|
case 'expandable':
|
||||||
return <Expandable {...props} {...contextProps} block={block} />;
|
return <Expandable {...props} block={block} />;
|
||||||
case 'table':
|
case 'table':
|
||||||
return <Table {...props} {...contextProps} block={block} />;
|
return <Table {...props} block={block} />;
|
||||||
case 'swagger':
|
case 'swagger':
|
||||||
return <OpenAPI {...props} {...contextProps} block={block} />;
|
return <OpenAPI {...props} block={block} />;
|
||||||
case 'embed':
|
case 'embed':
|
||||||
return <Embed {...props} {...contextProps} block={block} />;
|
return <Embed {...props} block={block} />;
|
||||||
case 'blockquote':
|
case 'blockquote':
|
||||||
return <Quote {...props} {...contextProps} block={block} />;
|
return <Quote {...props} block={block} />;
|
||||||
case 'math':
|
case 'math':
|
||||||
return <BlockMath {...props} {...contextProps} block={block} />;
|
return <BlockMath {...props} block={block} />;
|
||||||
case 'file':
|
case 'file':
|
||||||
return <File {...props} {...contextProps} block={block} />;
|
return <File {...props} block={block} />;
|
||||||
case 'divider':
|
case 'divider':
|
||||||
return <Divider {...props} {...contextProps} block={block} />;
|
return <Divider {...props} block={block} />;
|
||||||
case 'drawing':
|
case 'drawing':
|
||||||
return <Drawing {...props} {...contextProps} block={block} />;
|
return <Drawing {...props} block={block} />;
|
||||||
case 'content-ref':
|
case 'content-ref':
|
||||||
return <BlockContentRef {...props} {...contextProps} block={block} />;
|
return <BlockContentRef {...props} block={block} />;
|
||||||
case 'image':
|
case 'image':
|
||||||
case 'code-line':
|
case 'code-line':
|
||||||
case 'tabs-item':
|
case 'tabs-item':
|
||||||
throw new Error('Blocks should be directly rendered by parent');
|
throw new Error('Blocks should be directly rendered by parent');
|
||||||
case 'integration':
|
case 'integration':
|
||||||
return <IntegrationBlock {...props} {...contextProps} block={block} />;
|
return <IntegrationBlock {...props} block={block} />;
|
||||||
case 'synced-block':
|
case 'reusable-content':
|
||||||
return <BlockSyncedBlock {...props} {...contextProps} block={block} />;
|
return <ReusableContent {...props} block={block} />;
|
||||||
|
case 'stepper':
|
||||||
|
return <Stepper {...props} block={block} />;
|
||||||
|
case 'stepper-step':
|
||||||
|
return <StepperStep {...props} block={block} />;
|
||||||
default:
|
default:
|
||||||
assertNever(block);
|
return nullIfNever(block);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
if (!isEstimatedOffscreen || context.wrapBlocksInSuspense === false) {
|
||||||
|
// When blocks are estimated to be on the initial viewport, we render them immediately
|
||||||
|
// to avoid a flash of a loading skeleton.
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Suspense fallback={<BlockPlaceholder block={block} style={style} />}>
|
<React.Suspense fallback={<BlockSkeleton block={block} style={style} />}>
|
||||||
{content}
|
{content}
|
||||||
</React.Suspense>
|
</React.Suspense>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function BlockPlaceholder(props: { block: DocumentBlock; style: ClassValue }) {
|
/**
|
||||||
|
* Skeleton for a block while it is being loaded.
|
||||||
|
*/
|
||||||
|
export function BlockSkeleton(props: { block: DocumentBlock; style: ClassValue }) {
|
||||||
const { block, style } = props;
|
const { block, style } = props;
|
||||||
const id = 'meta' in block && block.meta && 'id' in block.meta ? block.meta.id : undefined;
|
const id = 'meta' in block && block.meta && 'id' in block.meta ? block.meta.id : undefined;
|
||||||
|
|
||||||
@@ -129,7 +149,6 @@ function BlockPlaceholder(props: { block: DocumentBlock; style: ClassValue }) {
|
|||||||
case 'code':
|
case 'code':
|
||||||
case 'hint':
|
case 'hint':
|
||||||
case 'tabs':
|
case 'tabs':
|
||||||
case 'synced-block':
|
|
||||||
return <SkeletonParagraph id={id} style={style} />;
|
return <SkeletonParagraph id={id} style={style} />;
|
||||||
case 'expandable':
|
case 'expandable':
|
||||||
case 'table':
|
case 'table':
|
||||||
@@ -138,6 +157,8 @@ function BlockPlaceholder(props: { block: DocumentBlock; style: ClassValue }) {
|
|||||||
case 'divider':
|
case 'divider':
|
||||||
case 'content-ref':
|
case 'content-ref':
|
||||||
case 'integration':
|
case 'integration':
|
||||||
|
case 'stepper':
|
||||||
|
case 'reusable-content':
|
||||||
return <SkeletonCard id={id} style={style} />;
|
return <SkeletonCard id={id} style={style} />;
|
||||||
case 'embed':
|
case 'embed':
|
||||||
case 'images':
|
case 'images':
|
||||||
@@ -146,8 +167,9 @@ function BlockPlaceholder(props: { block: DocumentBlock; style: ClassValue }) {
|
|||||||
case 'image':
|
case 'image':
|
||||||
case 'code-line':
|
case 'code-line':
|
||||||
case 'tabs-item':
|
case 'tabs-item':
|
||||||
|
case 'stepper-step':
|
||||||
throw new Error('Blocks should be directly rendered by parent');
|
throw new Error('Blocks should be directly rendered by parent');
|
||||||
default:
|
default:
|
||||||
assertNever(block);
|
return nullIfNever(block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
import { DocumentBlockContentRef } from '@gitbook/api';
|
import { DocumentBlockContentRef } from '@gitbook/api';
|
||||||
|
|
||||||
import { LogoIcon } from '@/components/icons';
|
|
||||||
import { Card, Emoji } from '@/components/primitives';
|
import { Card, Emoji } from '@/components/primitives';
|
||||||
import { getSpaceCustomization, ignoreAPIError } from '@/lib/api';
|
import { getSpaceCustomization, ignoreAPIError } from '@/lib/api';
|
||||||
import { ResolvedContentRef } from '@/lib/references';
|
import { ResolvedContentRef } from '@/lib/references';
|
||||||
|
|
||||||
import { BlockProps } from './Block';
|
import { BlockProps } from './Block';
|
||||||
|
import { SpaceIcon } from '../Space/SpaceIcon';
|
||||||
|
|
||||||
export async function BlockContentRef(props: BlockProps<DocumentBlockContentRef>) {
|
export async function BlockContentRef(props: BlockProps<DocumentBlockContentRef>) {
|
||||||
const { block, context, style } = props;
|
const { block, context, style } = props;
|
||||||
|
|
||||||
const resolved = await context.resolveContentRef(block.data.ref, {
|
const resolved = await context.resolveContentRef(block.data.ref, {
|
||||||
resolveAnchorText: true,
|
resolveAnchorText: true,
|
||||||
|
iconStyle: ['text-xl', 'text-dark/6', 'dark:text-light/6'],
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!resolved) {
|
if (!resolved) {
|
||||||
@@ -29,7 +30,7 @@ export async function BlockContentRef(props: BlockProps<DocumentBlockContentRef>
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Card
|
<Card
|
||||||
leadingIcon={resolved.emoji ? <Emoji code={resolved.emoji} style="text-xl" /> : null}
|
leadingIcon={resolved.icon ? resolved.icon : null}
|
||||||
href={resolved.href}
|
href={resolved.href}
|
||||||
title={resolved.text}
|
title={resolved.text}
|
||||||
style={style}
|
style={style}
|
||||||
@@ -47,7 +48,7 @@ async function SpaceRefCard(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const spaceCustomization = await ignoreAPIError(getSpaceCustomization(spaceId));
|
const { customization: spaceCustomization } = getSpaceCustomization(spaceId);
|
||||||
const customFavicon = spaceCustomization?.favicon;
|
const customFavicon = spaceCustomization?.favicon;
|
||||||
const customEmoji = customFavicon && 'emoji' in customFavicon ? customFavicon.emoji : undefined;
|
const customEmoji = customFavicon && 'emoji' in customFavicon ? customFavicon.emoji : undefined;
|
||||||
const customIcon = customFavicon && 'icon' in customFavicon ? customFavicon.icon : undefined;
|
const customIcon = customFavicon && 'icon' in customFavicon ? customFavicon.icon : undefined;
|
||||||
@@ -55,7 +56,7 @@ async function SpaceRefCard(
|
|||||||
return (
|
return (
|
||||||
<Card
|
<Card
|
||||||
leadingIcon={
|
leadingIcon={
|
||||||
<LogoIcon
|
<SpaceIcon
|
||||||
icon={customIcon}
|
icon={customIcon}
|
||||||
emoji={customEmoji}
|
emoji={customEmoji}
|
||||||
alt=""
|
alt=""
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
import { DocumentBlockSyncedBlock } from '@gitbook/api';
|
|
||||||
|
|
||||||
import { getSyncedBlockContent } from '@/lib/api';
|
|
||||||
import { resolveContentRefWithFiles } from '@/lib/references';
|
|
||||||
|
|
||||||
import { BlockProps } from './Block';
|
|
||||||
import { Blocks } from './Blocks';
|
|
||||||
|
|
||||||
export async function BlockSyncedBlock(props: BlockProps<DocumentBlockSyncedBlock>) {
|
|
||||||
const { block, ancestorBlocks, context, style } = props;
|
|
||||||
|
|
||||||
const apiToken = block.meta?.apiToken;
|
|
||||||
if (!apiToken) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We can't resolve the synced block without an organization context.
|
|
||||||
if (!context.contentRefContext) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const syncedBlock = await getSyncedBlockContent(
|
|
||||||
apiToken,
|
|
||||||
context.contentRefContext.space.organization,
|
|
||||||
block.data.ref.syncedBlock,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!syncedBlock) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Blocks
|
|
||||||
nodes={syncedBlock.document.nodes}
|
|
||||||
document={syncedBlock.document}
|
|
||||||
ancestorBlocks={[...ancestorBlocks, block]}
|
|
||||||
context={{
|
|
||||||
...context,
|
|
||||||
resolveContentRef: async (ref, options) => {
|
|
||||||
if (!syncedBlock?.files) {
|
|
||||||
return context.resolveContentRef(ref, options);
|
|
||||||
}
|
|
||||||
const result = resolveContentRefWithFiles(syncedBlock.files, ref);
|
|
||||||
if (result !== undefined) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
return context.resolveContentRef(ref, options);
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
style={style}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -4,11 +4,35 @@ import { tcls, ClassValue } from '@/lib/tailwind';
|
|||||||
|
|
||||||
import { Block } from './Block';
|
import { Block } from './Block';
|
||||||
import { DocumentContextProps } from './DocumentView';
|
import { DocumentContextProps } from './DocumentView';
|
||||||
|
import { isBlockOffscreen } from './utils';
|
||||||
|
|
||||||
export function Blocks<T extends DocumentBlock, Tag extends React.ElementType = 'div'>(
|
/**
|
||||||
props: DocumentContextProps & {
|
* Renders a list of blocks with a wrapper element.
|
||||||
|
*/
|
||||||
|
export function Blocks<TBlock extends DocumentBlock, Tag extends React.ElementType = 'div'>(
|
||||||
|
props: UnwrappedBlocksProps<TBlock> & {
|
||||||
|
/** HTML tag to use for the wrapper */
|
||||||
|
tag?: Tag;
|
||||||
|
|
||||||
|
/** Style passed to the wrapper */
|
||||||
|
style?: ClassValue;
|
||||||
|
|
||||||
|
/** Props to pass to the wrapper element */
|
||||||
|
wrapperProps?: React.ComponentProps<Tag>;
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
const { tag: Tag = 'div', style, wrapperProps, ...blocksProps } = props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tag {...wrapperProps} className={tcls(style)}>
|
||||||
|
<UnwrappedBlocks {...blocksProps} />
|
||||||
|
</Tag>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
type UnwrappedBlocksProps<TBlock extends DocumentBlock> = DocumentContextProps & {
|
||||||
/** Blocks to render */
|
/** Blocks to render */
|
||||||
nodes: T[];
|
nodes: TBlock[];
|
||||||
|
|
||||||
/** Document being rendered */
|
/** Document being rendered */
|
||||||
document: JSONDocument;
|
document: JSONDocument;
|
||||||
@@ -16,36 +40,45 @@ export function Blocks<T extends DocumentBlock, Tag extends React.ElementType =
|
|||||||
/** Ancestors of the blocks */
|
/** Ancestors of the blocks */
|
||||||
ancestorBlocks: DocumentBlock[];
|
ancestorBlocks: DocumentBlock[];
|
||||||
|
|
||||||
/** HTML tag to use */
|
|
||||||
tag?: Tag;
|
|
||||||
|
|
||||||
/** Style passed to the wrapper */
|
|
||||||
style?: ClassValue;
|
|
||||||
|
|
||||||
/** Style passed to all blocks */
|
/** Style passed to all blocks */
|
||||||
blockStyle?: ClassValue;
|
blockStyle?: ClassValue;
|
||||||
},
|
};
|
||||||
) {
|
|
||||||
const { nodes, tag: Tag = 'div', style, blockStyle, ...contextProps } = props;
|
/**
|
||||||
|
* Renders a list of blocks without a wrapper element.
|
||||||
|
*/
|
||||||
|
export function UnwrappedBlocks<TBlock extends DocumentBlock>(props: UnwrappedBlocksProps<TBlock>) {
|
||||||
|
const { nodes, blockStyle, ...contextProps } = props;
|
||||||
|
|
||||||
|
let isOffscreen = false;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{nodes.map((node) => {
|
||||||
|
isOffscreen =
|
||||||
|
isOffscreen ||
|
||||||
|
isBlockOffscreen({
|
||||||
|
document: props.document,
|
||||||
|
block: node,
|
||||||
|
ancestorBlocks: props.ancestorBlocks,
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tag className={tcls(style)}>
|
|
||||||
{nodes.map((node, index) => (
|
|
||||||
<Block
|
<Block
|
||||||
key={node.key}
|
key={node.key}
|
||||||
block={node}
|
block={node}
|
||||||
style={[
|
style={[
|
||||||
|
'w-full mx-auto decoration-primary/6',
|
||||||
node.data && 'fullWidth' in node.data && node.data.fullWidth
|
node.data && 'fullWidth' in node.data && node.data.fullWidth
|
||||||
? 'max-w-screen-xl'
|
? 'max-w-screen-xl'
|
||||||
: 'max-w-3xl',
|
: 'max-w-3xl',
|
||||||
'w-full',
|
|
||||||
'mx-auto',
|
|
||||||
'decoration-primary/6',
|
|
||||||
blockStyle,
|
blockStyle,
|
||||||
]}
|
]}
|
||||||
|
isEstimatedOffscreen={isOffscreen}
|
||||||
{...contextProps}
|
{...contextProps}
|
||||||
/>
|
/>
|
||||||
))}
|
);
|
||||||
</Tag>
|
})}
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
DocumentBlockDrawing,
|
DocumentBlockDrawing,
|
||||||
DocumentBlockEmbed,
|
DocumentBlockEmbed,
|
||||||
|
DocumentBlockFile,
|
||||||
DocumentBlockImage,
|
DocumentBlockImage,
|
||||||
JSONDocument,
|
JSONDocument,
|
||||||
} from '@gitbook/api';
|
} from '@gitbook/api';
|
||||||
@@ -21,7 +22,7 @@ export function Caption(
|
|||||||
style?: ClassValue;
|
style?: ClassValue;
|
||||||
fit?: boolean;
|
fit?: boolean;
|
||||||
wrapperStyle?: ClassValue;
|
wrapperStyle?: ClassValue;
|
||||||
block: DocumentBlockImage | DocumentBlockDrawing | DocumentBlockEmbed;
|
block: DocumentBlockImage | DocumentBlockDrawing | DocumentBlockEmbed | DocumentBlockFile;
|
||||||
} & DocumentContextProps,
|
} & DocumentContextProps,
|
||||||
) {
|
) {
|
||||||
const {
|
const {
|
||||||
@@ -70,7 +71,7 @@ export function Caption(
|
|||||||
'text-center',
|
'text-center',
|
||||||
'mt-2',
|
'mt-2',
|
||||||
'text-dark/7',
|
'text-dark/7',
|
||||||
'dark:text-light/6',
|
'dark:text-light/7',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<Inlines
|
<Inlines
|
||||||
|
|||||||
@@ -15,8 +15,7 @@ import './theme.css';
|
|||||||
*/
|
*/
|
||||||
export async function CodeBlock(props: BlockProps<DocumentBlockCode>) {
|
export async function CodeBlock(props: BlockProps<DocumentBlockCode>) {
|
||||||
const { block, document, style, context } = props;
|
const { block, document, style, context } = props;
|
||||||
const withHighlighting = context.shouldHighlightCode(context.content?.spaceId);
|
const lines = await highlight(block);
|
||||||
const lines = withHighlighting ? await highlight(block) : plainHighlighting(block);
|
|
||||||
|
|
||||||
const id = block.key!;
|
const id = block.key!;
|
||||||
|
|
||||||
@@ -99,6 +98,8 @@ export async function CodeBlock(props: BlockProps<DocumentBlockCode>) {
|
|||||||
'overflow-auto',
|
'overflow-auto',
|
||||||
'bg-light-2',
|
'bg-light-2',
|
||||||
'dark:bg-dark-2',
|
'dark:bg-dark-2',
|
||||||
|
'border-light-4',
|
||||||
|
'dark:border-dark-4',
|
||||||
'hide-scroll',
|
'hide-scroll',
|
||||||
titleRoundingStyle,
|
titleRoundingStyle,
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -50,10 +50,10 @@ export function PlainCodeBlock(props: { code: string; syntax: string }) {
|
|||||||
mode: 'default',
|
mode: 'default',
|
||||||
contentRefContext: null,
|
contentRefContext: null,
|
||||||
resolveContentRef: async () => null,
|
resolveContentRef: async () => null,
|
||||||
shouldHighlightCode: () => true,
|
|
||||||
}}
|
}}
|
||||||
block={block}
|
block={block}
|
||||||
ancestorBlocks={[]}
|
ancestorBlocks={[]}
|
||||||
|
isEstimatedOffscreen={false}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
const CODE_HIGHLIGHT_BLOCK_LIMIT = 50;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Spaces where we'll always use plain highlighting.
|
|
||||||
*/
|
|
||||||
const PLAIN_HIGHLIGHTING_SPACES: string[] = [
|
|
||||||
'V9geAO9ITPi8WOYK5o0r',
|
|
||||||
'puRmcwVxGFtHph8IjXaf',
|
|
||||||
'e3jwbMOrr4RhKtZ9C0XL',
|
|
||||||
'ryjzVNizLfd6pYogN3dm',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Protect against memory issues when highlighting a large number of code blocks.
|
|
||||||
* This context only allows 50 code blocks per render to be highlighted.
|
|
||||||
* Once highlighting can scale up to a large number of code blocks, it can be removed.
|
|
||||||
*
|
|
||||||
* https://linear.app/gitbook-x/issue/RND-3588/gitbook-open-code-syntax-highlighting-runs-out-of-memory-after-a
|
|
||||||
*/
|
|
||||||
export function createHighlightingContext() {
|
|
||||||
let count = 0;
|
|
||||||
return (spaceId?: string | undefined) => {
|
|
||||||
if (!spaceId || PLAIN_HIGHLIGHTING_SPACES.includes(spaceId)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
count += 1;
|
|
||||||
return count < CODE_HIGHLIGHT_BLOCK_LIMIT;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
import { DocumentBlockCode, DocumentBlockCodeLine, DocumentInlineAnnotation } from '@gitbook/api';
|
import { DocumentBlockCode, DocumentBlockCodeLine, DocumentInlineAnnotation } from '@gitbook/api';
|
||||||
import {
|
import {
|
||||||
loadWasm,
|
createdBundledHighlighter,
|
||||||
ThemedToken,
|
ThemedToken,
|
||||||
getHighlighter,
|
|
||||||
createCssVariablesTheme,
|
createCssVariablesTheme,
|
||||||
HighlighterGeneric,
|
HighlighterGeneric,
|
||||||
bundledLanguages,
|
} from 'shiki/core';
|
||||||
bundledThemes,
|
import { loadWasm, createOnigurumaEngine } from 'shiki/engine/oniguruma';
|
||||||
} from 'shiki';
|
import { bundledLanguages } from 'shiki/langs';
|
||||||
// @ts-ignore - onigWasm is a Wasm module
|
// @ts-ignore - onigWasm is a Wasm module
|
||||||
import onigWasm from 'shiki/onig.wasm?module';
|
import onigWasm from 'shiki/onig.wasm?module';
|
||||||
|
|
||||||
@@ -15,8 +14,6 @@ import { asyncMutexFunction, singleton } from '@/lib/async';
|
|||||||
import { getNodeText } from '@/lib/document';
|
import { getNodeText } from '@/lib/document';
|
||||||
import { trace } from '@/lib/tracing';
|
import { trace } from '@/lib/tracing';
|
||||||
|
|
||||||
import { DocumentContext } from '../DocumentView';
|
|
||||||
|
|
||||||
export type HighlightLine = {
|
export type HighlightLine = {
|
||||||
highlighted: boolean;
|
highlighted: boolean;
|
||||||
tokens: HighlightToken[];
|
tokens: HighlightToken[];
|
||||||
@@ -53,7 +50,7 @@ export async function highlight(block: DocumentBlockCode): Promise<HighlightLine
|
|||||||
|
|
||||||
const lines = highlighter.codeToTokensBase(code, {
|
const lines = highlighter.codeToTokensBase(code, {
|
||||||
lang: langName,
|
lang: langName,
|
||||||
tokenizeMaxLineLength: 120,
|
tokenizeMaxLineLength: 400,
|
||||||
});
|
});
|
||||||
|
|
||||||
let currentIndex = 0;
|
let currentIndex = 0;
|
||||||
@@ -299,6 +296,12 @@ function cleanupLine(line: string): string {
|
|||||||
return line.replace(/\r/g, '');
|
return line.replace(/\r/g, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const createHighlighter = createdBundledHighlighter<any, any>({
|
||||||
|
langs: bundledLanguages,
|
||||||
|
themes: {},
|
||||||
|
engine: () => createOnigurumaEngine(import('shiki/wasm')),
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the highlighter, only once, and reuse it.
|
* Load the highlighter, only once, and reuse it.
|
||||||
* It makes sure to handle concurrent calls.
|
* It makes sure to handle concurrent calls.
|
||||||
@@ -312,7 +315,8 @@ const loadHighlighter = singleton(async () => {
|
|||||||
// Otherwise for Vercel/Cloudflare, we need to load it ourselves.
|
// Otherwise for Vercel/Cloudflare, we need to load it ourselves.
|
||||||
await loadWasm((obj) => WebAssembly.instantiate(onigWasm, obj));
|
await loadWasm((obj) => WebAssembly.instantiate(onigWasm, obj));
|
||||||
}
|
}
|
||||||
const highlighter = await getHighlighter({
|
|
||||||
|
const highlighter = await createHighlighter({
|
||||||
themes: [createCssVariablesTheme()],
|
themes: [createCssVariablesTheme()],
|
||||||
langs: [],
|
langs: [],
|
||||||
});
|
});
|
||||||
@@ -322,7 +326,7 @@ const loadHighlighter = singleton(async () => {
|
|||||||
|
|
||||||
const loadLanguagesMutex = asyncMutexFunction();
|
const loadLanguagesMutex = asyncMutexFunction();
|
||||||
async function loadHighlighterLanguage(
|
async function loadHighlighterLanguage(
|
||||||
highlighter: HighlighterGeneric<keyof typeof bundledLanguages, keyof typeof bundledThemes>,
|
highlighter: HighlighterGeneric<any, any>,
|
||||||
lang: keyof typeof bundledLanguages,
|
lang: keyof typeof bundledLanguages,
|
||||||
) {
|
) {
|
||||||
await loadLanguagesMutex.runBlocking(async () => {
|
await loadLanguagesMutex.runBlocking(async () => {
|
||||||
|
|||||||
@@ -1,3 +1,2 @@
|
|||||||
export * from './CodeBlock';
|
export * from './CodeBlock';
|
||||||
export * from './PlainCodeBlock';
|
export * from './PlainCodeBlock';
|
||||||
export * from './createHighlightingContext';
|
|
||||||
|
|||||||
@@ -9,6 +9,9 @@
|
|||||||
--shiki-token-string-expression: #6a4906;
|
--shiki-token-string-expression: #6a4906;
|
||||||
--shiki-token-punctuation: theme('colors.pomegranate.700/.92');
|
--shiki-token-punctuation: theme('colors.pomegranate.700/.92');
|
||||||
--shiki-token-link: theme('colors.dark.DEFAULT');
|
--shiki-token-link: theme('colors.dark.DEFAULT');
|
||||||
|
--shiki-token-inserted: #22863a;
|
||||||
|
--shiki-token-deleted: #b31d28;
|
||||||
|
--shiki-token-changed: #8250df;
|
||||||
}
|
}
|
||||||
|
|
||||||
html.dark {
|
html.dark {
|
||||||
@@ -22,4 +25,7 @@ html.dark {
|
|||||||
--shiki-token-string-expression: theme('colors.light.4');
|
--shiki-token-string-expression: theme('colors.light.4');
|
||||||
--shiki-token-punctuation: #acc6ee;
|
--shiki-token-punctuation: #acc6ee;
|
||||||
--shiki-token-link: theme('colors.pomegranate.400');
|
--shiki-token-link: theme('colors.pomegranate.400');
|
||||||
|
--shiki-token-inserted: #85e89d;
|
||||||
|
--shiki-token-deleted: #fdaeb7;
|
||||||
|
--shiki-token-changed: #56b6c2;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { ContentTarget } from '@/lib/api';
|
|||||||
import { ContentRefContext, ResolveContentRefOptions, ResolvedContentRef } from '@/lib/references';
|
import { ContentRefContext, ResolveContentRefOptions, ResolvedContentRef } from '@/lib/references';
|
||||||
import { ClassValue } from '@/lib/tailwind';
|
import { ClassValue } from '@/lib/tailwind';
|
||||||
|
|
||||||
|
import { BlockSkeleton } from './Block';
|
||||||
import { Blocks } from './Blocks';
|
import { Blocks } from './Blocks';
|
||||||
|
|
||||||
export interface DocumentContext {
|
export interface DocumentContext {
|
||||||
@@ -38,14 +39,10 @@ export interface DocumentContext {
|
|||||||
getId?: (id: string) => string;
|
getId?: (id: string) => string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the given code block should be highlighted.
|
* True if the blocks should be wrapped in suspense boundary for isolated loading skeletons.
|
||||||
* This function was added to protect against memory issues when highlighting
|
* @default true
|
||||||
* a large number of code blocks.
|
|
||||||
* Once highlighting can scale up to a large number of code blocks, it can be removed.
|
|
||||||
*
|
|
||||||
* https://linear.app/gitbook-x/issue/RND-3588/gitbook-open-code-syntax-highlighting-runs-out-of-memory-after-a
|
|
||||||
*/
|
*/
|
||||||
shouldHighlightCode: (spaceId: string | undefined) => boolean;
|
wrapBlocksInSuspense?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DocumentContextProps {
|
export interface DocumentContextProps {
|
||||||
@@ -83,3 +80,28 @@ export function DocumentView(
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Placeholder for the entire document layout.
|
||||||
|
*/
|
||||||
|
export function DocumentViewSkeleton(props: { document: JSONDocument; blockStyle: ClassValue }) {
|
||||||
|
const { document, blockStyle } = props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-4">
|
||||||
|
{document.nodes.map((block, index) => (
|
||||||
|
<BlockSkeleton
|
||||||
|
key={block.key!}
|
||||||
|
block={block}
|
||||||
|
style={[
|
||||||
|
'w-full mx-auto decoration-primary/6',
|
||||||
|
block.data && 'fullWidth' in block.data && block.data.fullWidth
|
||||||
|
? 'max-w-screen-xl'
|
||||||
|
: 'max-w-3xl',
|
||||||
|
blockStyle,
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import Script from 'next/script';
|
|||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
|
|
||||||
import { Card } from '@/components/primitives';
|
import { Card } from '@/components/primitives';
|
||||||
import { api } from '@/lib/api';
|
import { getEmbedByUrlInSpace, getEmbedByUrl } from '@/lib/api';
|
||||||
import { tcls } from '@/lib/tailwind';
|
import { tcls } from '@/lib/tailwind';
|
||||||
|
|
||||||
import { BlockProps } from './Block';
|
import { BlockProps } from './Block';
|
||||||
@@ -17,9 +17,9 @@ export async function Embed(props: BlockProps<gitbookAPI.DocumentBlockEmbed>) {
|
|||||||
|
|
||||||
ReactDOM.preload('https://cdn.iframe.ly/embed.js', { as: 'script', nonce });
|
ReactDOM.preload('https://cdn.iframe.ly/embed.js', { as: 'script', nonce });
|
||||||
|
|
||||||
const { data: embed } = await (context.content
|
const embed = await (context.content
|
||||||
? api().spaces.getEmbedByUrlInSpace(context.content.spaceId, { url: block.data.url })
|
? getEmbedByUrlInSpace(context.content.spaceId, block.data.url)
|
||||||
: api().urls.getEmbedByUrl({ url: block.data.url }));
|
: getEmbedByUrl(block.data.url));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Caption {...props}>
|
<Caption {...props}>
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { useHash } from '@/components/hooks';
|
||||||
|
import { ClassValue, tcls } from '@/lib/tailwind';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Details component rendered on client so it can expand dependent on url hash changes.
|
||||||
|
*/
|
||||||
|
export function Details(props: {
|
||||||
|
children: React.ReactNode;
|
||||||
|
id: string;
|
||||||
|
contentIds?: string[];
|
||||||
|
open?: boolean;
|
||||||
|
className?: ClassValue;
|
||||||
|
}) {
|
||||||
|
const { children, id, className } = props;
|
||||||
|
|
||||||
|
const detailsRef = React.useRef<HTMLDetailsElement>(null);
|
||||||
|
|
||||||
|
const [openFromHash, setOpenFromHash] = React.useState(false);
|
||||||
|
|
||||||
|
const hash = useHash();
|
||||||
|
/**
|
||||||
|
* Open the details element if the url hash refers to the id of the details element
|
||||||
|
* or the id of some element contained within the details element.
|
||||||
|
*/
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (!hash || !detailsRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (hash === id) {
|
||||||
|
setOpenFromHash(true);
|
||||||
|
}
|
||||||
|
const activeElement = document.getElementById(hash);
|
||||||
|
setOpenFromHash(Boolean(activeElement && detailsRef.current?.contains(activeElement)));
|
||||||
|
}, [hash, id]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<details
|
||||||
|
ref={detailsRef}
|
||||||
|
id={id}
|
||||||
|
open={props.open || openFromHash}
|
||||||
|
className={tcls(
|
||||||
|
className,
|
||||||
|
'group/expandable',
|
||||||
|
'shadow-dark/1',
|
||||||
|
'bg-gradient-to-t',
|
||||||
|
'from-light-1',
|
||||||
|
'to-light-1',
|
||||||
|
'border',
|
||||||
|
'border-b-0',
|
||||||
|
'border-dark-3/3',
|
||||||
|
//all
|
||||||
|
'[&]:mt-[0px]',
|
||||||
|
//select first child
|
||||||
|
'[&:first-child]:mt-5',
|
||||||
|
'[&:first-child]:rounded-t-lg',
|
||||||
|
//select first in group
|
||||||
|
'[:not(&)_+&]:mt-5',
|
||||||
|
'[:not(&)_+&]:rounded-t-lg',
|
||||||
|
//select last in group
|
||||||
|
'[&:not(:has(+_&))]:mb-5',
|
||||||
|
'[&:not(:has(+_&))]:rounded-b-lg',
|
||||||
|
'[&:not(:has(+_&))]:border-b',
|
||||||
|
/* '[&:not(:has(+_&))]:shadow-1xs', */
|
||||||
|
|
||||||
|
'dark:border-light-2/[0.06]',
|
||||||
|
'dark:from-dark-2',
|
||||||
|
'dark:to-dark-2',
|
||||||
|
'dark:shadow-none',
|
||||||
|
|
||||||
|
'group open:dark:to-dark-2/8',
|
||||||
|
'group open:to-light-1/6',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</details>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
import ChevronRight from '@geist-ui/icons/chevronRight';
|
|
||||||
import IconHash from '@geist-ui/icons/hash';
|
|
||||||
import { DocumentBlockExpandable } from '@gitbook/api';
|
import { DocumentBlockExpandable } from '@gitbook/api';
|
||||||
|
import { Icon } from '@gitbook/icons';
|
||||||
|
|
||||||
import { getNodeFragmentByType } from '@/lib/document';
|
import { getNodeFragmentByType } from '@/lib/document';
|
||||||
import { tcls } from '@/lib/tailwind';
|
import { tcls } from '@/lib/tailwind';
|
||||||
|
|
||||||
|
import { Details } from './Details';
|
||||||
import { BlockProps } from '../Block';
|
import { BlockProps } from '../Block';
|
||||||
import { Blocks } from '../Blocks';
|
import { Blocks } from '../Blocks';
|
||||||
import { Inlines } from '../Inlines';
|
import { Inlines } from '../Inlines';
|
||||||
@@ -25,42 +25,7 @@ export function Expandable(props: BlockProps<DocumentBlockExpandable>) {
|
|||||||
id = context.getId ? context.getId(id) : id;
|
id = context.getId ? context.getId(id) : id;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<details
|
<Details id={id} open={context.mode === 'print'} className={style}>
|
||||||
id={id}
|
|
||||||
open={context.mode === 'print'}
|
|
||||||
className={tcls(
|
|
||||||
style,
|
|
||||||
'group/expandable',
|
|
||||||
'shadow-dark/1',
|
|
||||||
'bg-gradient-to-t',
|
|
||||||
'from-light-1',
|
|
||||||
'to-light-1',
|
|
||||||
'border',
|
|
||||||
'border-b-0',
|
|
||||||
'border-dark-3/3',
|
|
||||||
//all
|
|
||||||
'[&]:mt-[0px]',
|
|
||||||
//select first child
|
|
||||||
'[&:first-child]:mt-5',
|
|
||||||
'[&:first-child]:rounded-t-lg',
|
|
||||||
//select first in group
|
|
||||||
'[:not(&)_+&]:mt-5',
|
|
||||||
'[:not(&)_+&]:rounded-t-lg',
|
|
||||||
//select last in group
|
|
||||||
'[&:not(:has(+_&))]:mb-5',
|
|
||||||
'[&:not(:has(+_&))]:rounded-b-lg',
|
|
||||||
'[&:not(:has(+_&))]:border-b',
|
|
||||||
/* '[&:not(:has(+_&))]:shadow-1xs', */
|
|
||||||
|
|
||||||
'dark:border-light-2/[0.06]',
|
|
||||||
'dark:from-dark-2',
|
|
||||||
'dark:to-dark-2',
|
|
||||||
'dark:shadow-none',
|
|
||||||
|
|
||||||
'group open:dark:to-dark-2/8',
|
|
||||||
'group open:to-light-1/6',
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<summary
|
<summary
|
||||||
className={tcls(
|
className={tcls(
|
||||||
'cursor-pointer',
|
'cursor-pointer',
|
||||||
@@ -78,11 +43,11 @@ export function Expandable(props: BlockProps<DocumentBlockExpandable>) {
|
|||||||
'[&::-webkit-details-marker]:hidden',
|
'[&::-webkit-details-marker]:hidden',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<ChevronRight
|
<Icon
|
||||||
|
icon="chevron-right"
|
||||||
className={tcls(
|
className={tcls(
|
||||||
'inline-block',
|
'inline-block',
|
||||||
'w-4',
|
'size-3',
|
||||||
'h-4',
|
|
||||||
'mr-2',
|
'mr-2',
|
||||||
'mb-1',
|
'mb-1',
|
||||||
'transition-transform',
|
'transition-transform',
|
||||||
@@ -111,15 +76,15 @@ export function Expandable(props: BlockProps<DocumentBlockExpandable>) {
|
|||||||
'dark:ring-0',
|
'dark:ring-0',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<IconHash
|
<Icon
|
||||||
|
icon="hashtag"
|
||||||
className={tcls(
|
className={tcls(
|
||||||
'inline-block',
|
'inline-block',
|
||||||
'w-4',
|
'size-3',
|
||||||
'h-4',
|
|
||||||
'transition-colors',
|
'transition-colors',
|
||||||
'stroke-transparent',
|
'text-transparent',
|
||||||
'group-hover:stroke-dark/6',
|
'group-hover:text-dark/6',
|
||||||
'dark:group-hover:stroke-light/5',
|
'dark:group-hover:text-light/5',
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</a>
|
</a>
|
||||||
@@ -129,8 +94,8 @@ export function Expandable(props: BlockProps<DocumentBlockExpandable>) {
|
|||||||
document={document}
|
document={document}
|
||||||
ancestorBlocks={[...ancestorBlocks, block]}
|
ancestorBlocks={[...ancestorBlocks, block]}
|
||||||
context={context}
|
context={context}
|
||||||
style={['px-10', 'pb-5', 'space-y-3']}
|
style={['px-10', 'pb-5', 'space-y-4']}
|
||||||
/>
|
/>
|
||||||
</details>
|
</Details>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,11 @@ import { getSimplifiedContentType } from '@/lib/files';
|
|||||||
import { tcls } from '@/lib/tailwind';
|
import { tcls } from '@/lib/tailwind';
|
||||||
|
|
||||||
import { BlockProps } from './Block';
|
import { BlockProps } from './Block';
|
||||||
|
import { Caption } from './Caption';
|
||||||
import { FileIcon } from './FileIcon';
|
import { FileIcon } from './FileIcon';
|
||||||
|
|
||||||
export async function File(props: BlockProps<DocumentBlockFile>) {
|
export async function File(props: BlockProps<DocumentBlockFile>) {
|
||||||
const { block, context, style } = props;
|
const { block, context } = props;
|
||||||
|
|
||||||
const contentRef = await context.resolveContentRef(block.data.ref);
|
const contentRef = await context.resolveContentRef(block.data.ref);
|
||||||
const file = contentRef?.file;
|
const file = contentRef?.file;
|
||||||
@@ -19,6 +20,7 @@ export async function File(props: BlockProps<DocumentBlockFile>) {
|
|||||||
const contentType = getSimplifiedContentType(file.contentType);
|
const contentType = getSimplifiedContentType(file.contentType);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<Caption {...props} wrapperStyle={[]}>
|
||||||
<a
|
<a
|
||||||
href={file.downloadURL}
|
href={file.downloadURL}
|
||||||
download={file.name}
|
download={file.name}
|
||||||
@@ -28,28 +30,13 @@ export async function File(props: BlockProps<DocumentBlockFile>) {
|
|||||||
'flex-row',
|
'flex-row',
|
||||||
'items-center',
|
'items-center',
|
||||||
'border',
|
'border',
|
||||||
'border-b-0',
|
|
||||||
'px-5',
|
'px-5',
|
||||||
'py-3',
|
'py-3',
|
||||||
'border-dark/3',
|
'border-dark/3',
|
||||||
|
'rounded-lg',
|
||||||
//all
|
|
||||||
'[&]:mt-[0px]',
|
|
||||||
//select first child
|
|
||||||
'[&:first-child]:mt-5',
|
|
||||||
'[&:first-child]:rounded-t-lg',
|
|
||||||
//select first in group
|
|
||||||
'[:not(&)_+&]:mt-5',
|
|
||||||
'[:not(&)_+&]:rounded-t-lg',
|
|
||||||
//select last in group
|
|
||||||
'[&:not(:has(+_&))]:mb-5',
|
|
||||||
'[&:not(:has(+_&))]:rounded-b-lg',
|
|
||||||
'[&:not(:has(+_&))]:border-b',
|
|
||||||
|
|
||||||
'hover:text-primary-600',
|
'hover:text-primary-600',
|
||||||
'dark:border-light/3',
|
'dark:border-light/3',
|
||||||
'dark:hover:text-primary-300',
|
'dark:hover:text-primary-300',
|
||||||
style,
|
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
@@ -66,8 +53,11 @@ export async function File(props: BlockProps<DocumentBlockFile>) {
|
|||||||
'dark:border-light/2',
|
'dark:border-light/2',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className={tcls('*:w-5', '*:h-5', '*:stroke-primary')}>
|
<div>
|
||||||
<FileIcon contentType={contentType} />
|
<FileIcon
|
||||||
|
contentType={contentType}
|
||||||
|
className={tcls('size-5', 'text-primary')}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className={tcls(
|
className={tcls(
|
||||||
@@ -83,9 +73,12 @@ export async function File(props: BlockProps<DocumentBlockFile>) {
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div className={tcls('text-base')}>{file.name}</div>
|
<div className={tcls('text-base')}>{file.name}</div>
|
||||||
<div className={tcls('text-sm', 'opacity-9', 'dark:opacity-8')}>{contentType}</div>
|
<div className={tcls('text-sm', 'opacity-9', 'dark:opacity-8')}>
|
||||||
|
{contentType}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
|
</Caption>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,21 @@
|
|||||||
import IconDownload from '@geist-ui/icons/download';
|
import { Icon } from '@gitbook/icons';
|
||||||
import IconFileText from '@geist-ui/icons/fileText';
|
|
||||||
import IconImage from '@geist-ui/icons/image';
|
|
||||||
import IconPaperClip from '@geist-ui/icons/paperclip';
|
|
||||||
|
|
||||||
import { SimplifiedFileType } from '@/lib/files';
|
import { SimplifiedFileType } from '@/lib/files';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render an appropriate icon for a file.
|
* Render an appropriate icon for a file.
|
||||||
*/
|
*/
|
||||||
export function FileIcon(props: { contentType: SimplifiedFileType | null }) {
|
export function FileIcon(props: { contentType: SimplifiedFileType | null; className: string }) {
|
||||||
const { contentType } = props;
|
const { contentType, className } = props;
|
||||||
|
|
||||||
switch (contentType) {
|
switch (contentType) {
|
||||||
case 'pdf':
|
case 'pdf':
|
||||||
return <IconFileText />;
|
return <Icon icon="file-pdf" className={className} />;
|
||||||
case 'image':
|
case 'image':
|
||||||
return <IconImage />;
|
return <Icon icon="file-image" className={className} />;
|
||||||
case 'archive':
|
case 'archive':
|
||||||
return <IconPaperClip />;
|
return <Icon icon="file-archive" className={className} />;
|
||||||
default:
|
default:
|
||||||
return <IconDownload />;
|
return <Icon icon="file-download" className={className} />;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import IconHash from '@geist-ui/icons/hash';
|
|
||||||
import { DocumentBlockHeading } from '@gitbook/api';
|
import { DocumentBlockHeading } from '@gitbook/api';
|
||||||
|
import { Icon } from '@gitbook/icons';
|
||||||
|
|
||||||
import { tcls } from '@/lib/tailwind';
|
import { tcls } from '@/lib/tailwind';
|
||||||
|
|
||||||
@@ -48,14 +48,15 @@ export function Heading(props: BlockProps<DocumentBlockHeading>) {
|
|||||||
textStyle.lineHeight,
|
textStyle.lineHeight,
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<IconHash
|
<Icon
|
||||||
|
icon="hashtag"
|
||||||
className={tcls(
|
className={tcls(
|
||||||
'w-3.5',
|
'w-3.5',
|
||||||
'h-[1lh]',
|
'h-[1lh]',
|
||||||
'transition-colors',
|
'transition-colors',
|
||||||
'stroke-transparent',
|
'text-transparent',
|
||||||
'group-hover:stroke-dark/6',
|
'group-hover:text-dark/6',
|
||||||
'dark:group-hover:stroke-light/5',
|
'dark:group-hover:text-light/5',
|
||||||
'lg:w-4',
|
'lg:w-4',
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { DocumentBlockHint } from '@gitbook/api';
|
import { DocumentBlockHint } from '@gitbook/api';
|
||||||
|
import { Icon, IconName } from '@gitbook/icons';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { ClassValue, tcls } from '@/lib/tailwind';
|
import { ClassValue, tcls } from '@/lib/tailwind';
|
||||||
@@ -9,15 +10,14 @@ import { getBlockTextStyle } from './spacing';
|
|||||||
|
|
||||||
export function Hint(props: BlockProps<DocumentBlockHint>) {
|
export function Hint(props: BlockProps<DocumentBlockHint>) {
|
||||||
const { block, style, ancestorBlocks, ...contextProps } = props;
|
const { block, style, ancestorBlocks, ...contextProps } = props;
|
||||||
const hintStyle = HINT_STYLES[block.data.style];
|
const hintStyle = HINT_STYLES[block.data.style] ?? HINT_STYLES.info;
|
||||||
const firstLine = getBlockTextStyle(block.nodes[0]);
|
const firstLine = getBlockTextStyle(block.nodes[0]);
|
||||||
const RenderIcon = HINT_STYLES[block.data.style].icon;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={tcls(
|
className={tcls(
|
||||||
'px-4',
|
'hint',
|
||||||
'py-4',
|
'p-4',
|
||||||
'transition-colors',
|
'transition-colors',
|
||||||
'rounded-md',
|
'rounded-md',
|
||||||
'straight-corners:rounded-none',
|
'straight-corners:rounded-none',
|
||||||
@@ -26,29 +26,26 @@ export function Hint(props: BlockProps<DocumentBlockHint>) {
|
|||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className={tcls('flex', 'flex-row')}>
|
<div className={tcls('flex', 'flex-row')}>
|
||||||
<div
|
<Icon
|
||||||
|
icon={hintStyle.icon}
|
||||||
className={tcls(
|
className={tcls(
|
||||||
'flex',
|
'size-5',
|
||||||
'items-start',
|
'mr-4',
|
||||||
'justify-center',
|
|
||||||
'pr-3',
|
|
||||||
'mt-0.5',
|
'mt-0.5',
|
||||||
firstLine.lineHeight,
|
firstLine.lineHeight,
|
||||||
hintStyle.anchorColor,
|
hintStyle.iconColor,
|
||||||
)}
|
)}
|
||||||
>
|
/>
|
||||||
<RenderIcon />
|
|
||||||
</div>
|
|
||||||
<Blocks
|
<Blocks
|
||||||
{...contextProps}
|
{...contextProps}
|
||||||
ancestorBlocks={[...ancestorBlocks, block]}
|
ancestorBlocks={[...ancestorBlocks, block]}
|
||||||
nodes={block.nodes}
|
nodes={block.nodes}
|
||||||
blockStyle={tcls(
|
blockStyle={tcls(
|
||||||
hintStyle.anchorColor,
|
hintStyle.bodyColor,
|
||||||
// render hash icon on the other side of the heading
|
// render hash icon on the other side of the heading
|
||||||
'flip-heading-hash',
|
'flip-heading-hash',
|
||||||
)}
|
)}
|
||||||
style={['flex-1', 'space-y-4', '[&>p]:text-sm', '[&>p]:leading-relaxed']}
|
style={['flex-1', 'space-y-4', '[&_.hint]:border', '[&_pre]:border']}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -57,273 +54,77 @@ export function Hint(props: BlockProps<DocumentBlockHint>) {
|
|||||||
|
|
||||||
const HINT_STYLES: {
|
const HINT_STYLES: {
|
||||||
[style in DocumentBlockHint['data']['style']]: {
|
[style in DocumentBlockHint['data']['style']]: {
|
||||||
icon: () => React.ReactNode;
|
icon: IconName;
|
||||||
anchorColor: ClassValue;
|
iconColor: ClassValue;
|
||||||
|
bodyColor: ClassValue;
|
||||||
style: ClassValue;
|
style: ClassValue;
|
||||||
};
|
};
|
||||||
} = {
|
} = {
|
||||||
info: {
|
info: {
|
||||||
icon: InfoIcon,
|
icon: 'circle-info',
|
||||||
anchorColor: [
|
iconColor: ['text-primary-500', 'dark:text-primary-400'],
|
||||||
'[&>a]:text-periwinkle-700',
|
bodyColor: [
|
||||||
'[&>a:hover]:text-periwinkle-800',
|
'[&_a]:text-primary-500',
|
||||||
'[&>code]:bg-periwinkle-700/4',
|
'[&_a:hover]:text-primary-600',
|
||||||
'[&>code]:text-inherit',
|
'dark:[&_a]:text-primary-400',
|
||||||
'[&>code]:shadow-none',
|
'dark:[&_a:hover]:text-primary-300',
|
||||||
|
|
||||||
'text-periwinkle-900',
|
|
||||||
'fill-periwinkle-700',
|
|
||||||
'stroke-periwinkle-700',
|
|
||||||
|
|
||||||
'dark:text-periwinkle-200',
|
|
||||||
'dark:[&>a]:text-periwinkle',
|
|
||||||
'dark:[&>a:hover]:text-periwinkle-600',
|
|
||||||
'dark:[&>code]:bg-periwinkle-200/2',
|
|
||||||
'dark:[&>code]:text-inherit',
|
|
||||||
'decoration-periwinkle-700/6',
|
|
||||||
'dark:decoration-periwinkle/6',
|
|
||||||
'dark:fill-periwinkle-400',
|
|
||||||
'dark:stroke-periwinkle-400',
|
|
||||||
],
|
],
|
||||||
style: [
|
style: [
|
||||||
'bg-gradient-to-b',
|
'bg-dark-1/1',
|
||||||
'from-periwinkle/6',
|
'border-dark/3',
|
||||||
'to-periwinkle/5',
|
'dark:bg-light/1',
|
||||||
'ring-1',
|
'dark:border-light/3',
|
||||||
'ring-inset',
|
'[&_.can-override-bg]:bg-dark-1/2',
|
||||||
'ring-dark/1',
|
'[&_.can-override-text]:text-dark',
|
||||||
'dark:ring-periwinkle/1',
|
'dark:[&_.can-override-bg]:bg-light/2',
|
||||||
'dark:from-periwinkle/2',
|
'dark:[&_.can-override-text]:text-light',
|
||||||
'dark:to-periwinkle/[0.1]',
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
warning: {
|
warning: {
|
||||||
icon: WarningIcon,
|
icon: 'circle-exclamation',
|
||||||
anchorColor: [
|
iconColor: ['text-amber-500', 'dark:text-orange-400'], // Darker shades of orange-* mismatch with lighter shades, so in light mode we use amber text on top of orange bg.
|
||||||
'[&>a]:text-yellow-700',
|
bodyColor: [
|
||||||
'[&>a:hover]:text-yellow-800',
|
'[&_a]:text-orange-800',
|
||||||
'[&>code]:bg-yellow-600/5',
|
'[&_a:hover]:text-orange-900',
|
||||||
'[&>code]:text-inherit',
|
'dark:[&_a]:text-orange-400',
|
||||||
'[&>code]:shadow-none',
|
'dark:[&_a:hover]:text-orange-300',
|
||||||
|
'[&_.can-override-bg]:bg-orange-500/3',
|
||||||
'text-yellow-900',
|
'[&_.can-override-text]:text-orange-800',
|
||||||
|
'dark:[&_.can-override-text]:text-orange-400',
|
||||||
'fill-yellow-800',
|
'decoration-orange-800/6',
|
||||||
'dark:text-yellow-200',
|
'dark:decoration-orange-400/6',
|
||||||
'dark:[&>a]:text-yellow',
|
|
||||||
'dark:[&>a:hover]:text-yellow-600',
|
|
||||||
'dark:[&>code]:bg-yellow-200/2',
|
|
||||||
'dark:[&>code]:text-inherit',
|
|
||||||
'decoration-yellow-700/6',
|
|
||||||
'dark:decoration-yellow/6',
|
|
||||||
'dark:fill-yellow',
|
|
||||||
],
|
|
||||||
style: [
|
|
||||||
'bg-gradient-to-b',
|
|
||||||
'from-yellow/6',
|
|
||||||
'to-yellow/5',
|
|
||||||
'ring-1',
|
|
||||||
'ring-inset',
|
|
||||||
'ring-dark/1',
|
|
||||||
'dark:ring-yellow/[0.02]',
|
|
||||||
'dark:from-yellow/[0.06]',
|
|
||||||
'dark:to-yellow/2',
|
|
||||||
],
|
],
|
||||||
|
style: ['bg-orange-500/2', 'border-orange-500/4'],
|
||||||
},
|
},
|
||||||
danger: {
|
danger: {
|
||||||
icon: DangerIcon,
|
icon: 'triangle-exclamation',
|
||||||
anchorColor: [
|
iconColor: ['text-red-500', 'dark:text-red-400'],
|
||||||
'[&>a]:text-pomegranate-600/9',
|
bodyColor: [
|
||||||
'[&>a:hover]:text-pomegranate-800',
|
'[&_a]:text-red-800',
|
||||||
'[&>code]:bg-pomegranate-600/4',
|
'[&_a:hover]:text-red-900',
|
||||||
'[&>code]:text-inherit',
|
'dark:[&_a]:text-red-400',
|
||||||
'[&>code]:shadow-none',
|
'dark:[&_a:hover]:text-red-300',
|
||||||
|
'[&_.can-override-bg]:bg-red-500/3',
|
||||||
'text-pomegranate-900',
|
'[&_.can-override-text]:text-red-400',
|
||||||
|
'decoration-red-800/6',
|
||||||
'fill-pomegranate-700',
|
'dark:decoration-red-400/6',
|
||||||
'dark:text-pomegranate-100',
|
|
||||||
'dark:[&>a]:text-pomegranate',
|
|
||||||
'dark:[&>a:hover]:text-pomegranate-600',
|
|
||||||
'dark:[&>code]:bg-pomegranate-200/2',
|
|
||||||
'dark:[&>code]:text-inherit',
|
|
||||||
'decoration-pomegranate-600/6',
|
|
||||||
'dark:decoration-pomegranate/6',
|
|
||||||
'dark:fill-pomegranate-400',
|
|
||||||
],
|
|
||||||
style: [
|
|
||||||
'bg-gradient-to-b',
|
|
||||||
'from-pomegranate/4',
|
|
||||||
'to-pomegranate/3',
|
|
||||||
'ring-1',
|
|
||||||
'ring-inset',
|
|
||||||
'ring-dark/1',
|
|
||||||
'dark:ring-pomegranate/1',
|
|
||||||
'dark:from-pomegranate/2',
|
|
||||||
'dark:to-pomegranate/3',
|
|
||||||
],
|
],
|
||||||
|
style: ['bg-red-500/2', 'border-red-500/4'],
|
||||||
},
|
},
|
||||||
success: {
|
success: {
|
||||||
icon: SuccessIcon,
|
icon: 'circle-check',
|
||||||
anchorColor: [
|
iconColor: ['text-green-500', 'dark:text-green-400'],
|
||||||
'[&>a]:text-teal-600',
|
bodyColor: [
|
||||||
'[&>a:hover]:text-teal-800',
|
'[&_a]:text-green-800',
|
||||||
'[&>code]:bg-teal-600/4',
|
'[&_a:hover]:text-green-900',
|
||||||
'[&>code]:text-inherit',
|
'dark:[&_a]:text-green-400',
|
||||||
'[&>code]:shadow-none',
|
'dark:[&_a:hover]:text-green-300',
|
||||||
|
'[&_.can-override-bg]:bg-green-500/3',
|
||||||
'text-teal-800',
|
'[&_.can-override-text]:text-green-800',
|
||||||
'fill-teal-700',
|
'dark:[&_.can-override-text]:text-green-400',
|
||||||
'stroke-teal-700',
|
'decoration-green-800/6',
|
||||||
|
'dark:decoration-green-400/6',
|
||||||
'dark:text-teal-100',
|
|
||||||
'dark:[&>a]:text-teal-400',
|
|
||||||
'dark:[&>a:hover]:text-teal-500',
|
|
||||||
'dark:[&>code]:bg-teal-200/2',
|
|
||||||
'dark:[&>code]:text-inherit',
|
|
||||||
'decoration-teal/6',
|
|
||||||
'dark:decoration-teal/6',
|
|
||||||
'dark:fill-teal-400',
|
|
||||||
'dark:stroke-teal-300',
|
|
||||||
],
|
|
||||||
style: [
|
|
||||||
'bg-gradient-to-b',
|
|
||||||
'from-teal/4',
|
|
||||||
'to-teal/3',
|
|
||||||
'ring-1',
|
|
||||||
'ring-inset',
|
|
||||||
'ring-dark/1',
|
|
||||||
'dark:ring-teal/1',
|
|
||||||
'dark:from-teal/2',
|
|
||||||
'dark:to-teal/3',
|
|
||||||
],
|
],
|
||||||
|
style: ['bg-green-500/2', 'border-green-500/4'],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
function InfoIcon() {
|
|
||||||
return (
|
|
||||||
<svg
|
|
||||||
width="16"
|
|
||||||
height="16"
|
|
||||||
viewBox="0 0 16 16"
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
className={tcls('overflow-visible')}
|
|
||||||
>
|
|
||||||
<circle cx="8" cy="4.5" r="1.5" fill="inherit" fillOpacity="1" stroke="none" />
|
|
||||||
<circle
|
|
||||||
cx="8"
|
|
||||||
cy="4.5"
|
|
||||||
r="1.5"
|
|
||||||
fill="inherit"
|
|
||||||
fillOpacity="0.2"
|
|
||||||
stroke="none"
|
|
||||||
className={tcls(
|
|
||||||
'animate-[pingAlt_8s_ease_infinite_forwards]',
|
|
||||||
'origin-[8px_4.5px]',
|
|
||||||
'w-[4px]',
|
|
||||||
'h-[4px]',
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<rect
|
|
||||||
x="7"
|
|
||||||
y="7"
|
|
||||||
width="2"
|
|
||||||
rx="1"
|
|
||||||
height="6"
|
|
||||||
fill="inherit"
|
|
||||||
fillOpacity="1"
|
|
||||||
stroke="none"
|
|
||||||
/>
|
|
||||||
<circle cx="8" cy="8" r="8" fill="inherit" fillOpacity="0.16" stroke="none" />
|
|
||||||
</svg>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function DangerIcon() {
|
|
||||||
return (
|
|
||||||
<svg width="18" height="16" viewBox="0 0 18 16" xmlns="http://www.w3.org/2000/svg">
|
|
||||||
<path
|
|
||||||
d="M7.2546 1C8.03034 -0.333333 9.96967 -0.333333 10.7454 1L17.727 13C18.5027 14.3333 17.533 16 15.9816 16H2.01842C0.466953 16 -0.502711 14.3333 0.27302 13L7.2546 1Z"
|
|
||||||
fill="inherit"
|
|
||||||
fillOpacity="0.16"
|
|
||||||
stroke="none"
|
|
||||||
/>
|
|
||||||
<rect
|
|
||||||
x="8"
|
|
||||||
y="4"
|
|
||||||
width="2"
|
|
||||||
height="6"
|
|
||||||
rx="1"
|
|
||||||
fill="inherit"
|
|
||||||
fillOpacity="0.92"
|
|
||||||
stroke="none"
|
|
||||||
className={tcls(
|
|
||||||
'animate-[wag_4s_ease_infinite_forwards]',
|
|
||||||
'[animation-composition:accumulate]',
|
|
||||||
'origin-[9px_12.5px]',
|
|
||||||
'will-change-transform',
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<circle cx="9" cy="12.5" r="1.5" fill="inherit" fillOpacity="0.92" stroke="none" />
|
|
||||||
</svg>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function WarningIcon() {
|
|
||||||
return (
|
|
||||||
<svg width="16" height="18" viewBox="0 0 16 18" xmlns="http://www.w3.org/2000/svg">
|
|
||||||
<path
|
|
||||||
d="M6.9736 0.277489C7.60874 -0.0924963 8.39126 -0.0924962 9.0264 0.277489L14.9736 3.74189C15.6087 4.11187 16 4.79563 16 5.5356V12.4644C16 13.2044 15.6087 13.8881 14.9736 14.2581L9.0264 17.7225C8.39126 18.0925 7.60874 18.0925 6.9736 17.7225L1.0264 14.2581C0.391261 13.8881 0 13.2044 0 12.4644V5.5356C0 4.79563 0.391262 4.11187 1.0264 3.74189L6.9736 0.277489Z"
|
|
||||||
fill="inherit"
|
|
||||||
fillOpacity="0.16"
|
|
||||||
stroke="none"
|
|
||||||
/>
|
|
||||||
<rect
|
|
||||||
x="7"
|
|
||||||
y="4"
|
|
||||||
width="2"
|
|
||||||
height="6"
|
|
||||||
rx="1"
|
|
||||||
fill="inherit"
|
|
||||||
fillOpacity="0.8"
|
|
||||||
stroke="none"
|
|
||||||
/>
|
|
||||||
<circle
|
|
||||||
cx="8"
|
|
||||||
cy="12.5"
|
|
||||||
r="1.5"
|
|
||||||
fill="inherit"
|
|
||||||
fillOpacity="1"
|
|
||||||
stroke="none"
|
|
||||||
className={tcls('animate-[pulse_1s_ease_infinite_forwards]')}
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function SuccessIcon() {
|
|
||||||
return (
|
|
||||||
<svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
|
|
||||||
<rect width="16" height="16" rx="3" fill="inherit" fillOpacity="0.16" stroke="none" />
|
|
||||||
<path
|
|
||||||
className={tcls('animate-[stroke_8s_ease_infinite_forwards]')}
|
|
||||||
d="M4 8.5L6.5 11L12 5.5"
|
|
||||||
stroke="inherit"
|
|
||||||
fill="none"
|
|
||||||
strokeOpacity="0.8"
|
|
||||||
strokeWidth="2"
|
|
||||||
strokeLinecap="round"
|
|
||||||
pathLength="100"
|
|
||||||
/>
|
|
||||||
<path
|
|
||||||
d="M4 8.5L6.5 11L12 5.5"
|
|
||||||
stroke="inherit"
|
|
||||||
fill="none"
|
|
||||||
strokeOpacity="0.16"
|
|
||||||
strokeWidth="2"
|
|
||||||
strokeLinecap="round"
|
|
||||||
pathLength="100"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -11,12 +11,10 @@ import { ClassValue, tcls } from '@/lib/tailwind';
|
|||||||
import { BlockProps } from './Block';
|
import { BlockProps } from './Block';
|
||||||
import { Caption } from './Caption';
|
import { Caption } from './Caption';
|
||||||
import { DocumentContext } from './DocumentView';
|
import { DocumentContext } from './DocumentView';
|
||||||
import { isBlockOffscreen } from './utils';
|
|
||||||
|
|
||||||
export function Images(props: BlockProps<DocumentBlockImages>) {
|
export function Images(props: BlockProps<DocumentBlockImages>) {
|
||||||
const { document, block, ancestorBlocks, style, context } = props;
|
const { document, block, ancestorBlocks, style, context, isEstimatedOffscreen } = props;
|
||||||
|
|
||||||
const isOffscreen = isBlockOffscreen({ document, block, ancestorBlocks });
|
|
||||||
const isMultipleImages = block.nodes.length > 1;
|
const isMultipleImages = block.nodes.length > 1;
|
||||||
const { align = 'center' } = block.data;
|
const { align = 'center' } = block.data;
|
||||||
|
|
||||||
@@ -41,7 +39,7 @@ export function Images(props: BlockProps<DocumentBlockImages>) {
|
|||||||
style={[]}
|
style={[]}
|
||||||
siblings={block.nodes.length}
|
siblings={block.nodes.length}
|
||||||
context={context}
|
context={context}
|
||||||
isOffscreen={isOffscreen}
|
isEstimatedOffscreen={isEstimatedOffscreen}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
@@ -67,9 +65,9 @@ async function ImageBlock(props: {
|
|||||||
style: ClassValue;
|
style: ClassValue;
|
||||||
context: DocumentContext;
|
context: DocumentContext;
|
||||||
siblings: number;
|
siblings: number;
|
||||||
isOffscreen: boolean;
|
isEstimatedOffscreen: boolean;
|
||||||
}) {
|
}) {
|
||||||
const { block, context, isOffscreen } = props;
|
const { block, context, isEstimatedOffscreen } = props;
|
||||||
|
|
||||||
const [src, darkSrc] = await Promise.all([
|
const [src, darkSrc] = await Promise.all([
|
||||||
context.resolveContentRef(block.data.ref),
|
context.resolveContentRef(block.data.ref),
|
||||||
@@ -97,7 +95,7 @@ async function ImageBlock(props: {
|
|||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
}}
|
}}
|
||||||
priority={isOffscreen ? 'lazy' : 'high'}
|
priority={isEstimatedOffscreen ? 'lazy' : 'high'}
|
||||||
preload
|
preload
|
||||||
zoom
|
zoom
|
||||||
inlineStyle={{
|
inlineStyle={{
|
||||||
|
|||||||
@@ -25,7 +25,11 @@ export async function InlineImage(props: InlineProps<DocumentInlineImage>) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
/* Ensure images dont expand to the size of the container where this Image may be nested in. Now it's always nested in a size-restricted container */
|
/* Ensure images dont expand to the size of the container where this Image may be nested in. Now it's always nested in a size-restricted container */
|
||||||
<span className={tcls(size !== 'line' ? ['inline-flex', 'max-w-[300px]'] : null)}>
|
<span
|
||||||
|
className={tcls(
|
||||||
|
size !== 'line' ? ['inline-flex', 'max-w-[300px]', 'align-middle'] : null,
|
||||||
|
)}
|
||||||
|
>
|
||||||
<Image
|
<Image
|
||||||
alt={inline.data.caption ?? ''}
|
alt={inline.data.caption ?? ''}
|
||||||
sizes={await getImageSizes(size, src)}
|
sizes={await getImageSizes(size, src)}
|
||||||
|
|||||||
@@ -1,23 +1,9 @@
|
|||||||
import {
|
|
||||||
Edit,
|
|
||||||
Github,
|
|
||||||
Gitlab,
|
|
||||||
Maximize,
|
|
||||||
X,
|
|
||||||
Mail,
|
|
||||||
Settings,
|
|
||||||
Search,
|
|
||||||
Delete,
|
|
||||||
Star,
|
|
||||||
AlertTriangle,
|
|
||||||
Link,
|
|
||||||
Eye,
|
|
||||||
Lock,
|
|
||||||
} from '@geist-ui/icons';
|
|
||||||
import { ContentKitContext, DocumentBlockIntegration } from '@gitbook/api';
|
import { ContentKitContext, DocumentBlockIntegration } from '@gitbook/api';
|
||||||
|
import { Icon } from '@gitbook/icons';
|
||||||
import { ContentKit, ContentKitOutput, ContentKitServerContext } from '@gitbook/react-contentkit';
|
import { ContentKit, ContentKitOutput, ContentKitServerContext } from '@gitbook/react-contentkit';
|
||||||
|
|
||||||
import { ignoreAPIError, renderIntegrationUi } from '@/lib/api';
|
import { ignoreAPIError, renderIntegrationUi } from '@/lib/api';
|
||||||
|
import { INTEGRATIONS_HOST } from '@/lib/csp';
|
||||||
import { parseMarkdown } from '@/lib/markdown';
|
import { parseMarkdown } from '@/lib/markdown';
|
||||||
import { tcls } from '@/lib/tailwind';
|
import { tcls } from '@/lib/tailwind';
|
||||||
|
|
||||||
@@ -27,21 +13,21 @@ import { PlainCodeBlock } from '../CodeBlock';
|
|||||||
|
|
||||||
const outputContext: ContentKitServerContext = {
|
const outputContext: ContentKitServerContext = {
|
||||||
icons: {
|
icons: {
|
||||||
maximize: Maximize,
|
maximize: (props) => <Icon icon="maximize" {...props} />,
|
||||||
edit: Edit,
|
edit: (props) => <Icon icon="edit" {...props} />,
|
||||||
github: Github,
|
github: (props) => <Icon icon="github" {...props} />,
|
||||||
gitlab: Gitlab,
|
gitlab: (props) => <Icon icon="gitlab" {...props} />,
|
||||||
close: X,
|
close: (props) => <Icon icon="x" {...props} />,
|
||||||
email: Mail,
|
email: (props) => <Icon icon="envelope" {...props} />,
|
||||||
settings: Settings,
|
settings: (props) => <Icon icon="gear" {...props} />,
|
||||||
search: Search,
|
search: (props) => <Icon icon="magnifying-glass" {...props} />,
|
||||||
delete: Delete,
|
delete: (props) => <Icon icon="trash" {...props} />,
|
||||||
star: Star,
|
star: (props) => <Icon icon="star" {...props} />,
|
||||||
warning: AlertTriangle,
|
warning: (props) => <Icon icon="triangle-exclamation" {...props} />,
|
||||||
link: Link,
|
link: (props) => <Icon icon="link" {...props} />,
|
||||||
'link-external': Link,
|
'link-external': (props) => <Icon icon="arrow-up-right-from-square" {...props} />,
|
||||||
eye: Eye,
|
eye: (props) => <Icon icon="eye" {...props} />,
|
||||||
lock: Lock,
|
lock: (props) => <Icon icon="lock" {...props} />,
|
||||||
},
|
},
|
||||||
codeBlock: (props) => {
|
codeBlock: (props) => {
|
||||||
return <PlainCodeBlock code={props.code} syntax={props.syntax} />;
|
return <PlainCodeBlock code={props.code} syntax={props.syntax} />;
|
||||||
@@ -77,14 +63,14 @@ export async function IntegrationBlock(props: BlockProps<DocumentBlockIntegratio
|
|||||||
renderIntegrationUi(block.data.integration, initialInput),
|
renderIntegrationUi(block.data.integration, initialInput),
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
if (!initialOutput) {
|
if (!initialOutput || initialOutput.type === 'complete') {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={tcls(style)}>
|
<div className={tcls(style)}>
|
||||||
<ContentKit
|
<ContentKit
|
||||||
security={{ firstPartyDomains: ['integrations.gitbook.com'] }}
|
security={{ firstPartyDomains: [INTEGRATIONS_HOST] }}
|
||||||
initialInput={initialInput}
|
initialInput={initialInput}
|
||||||
initialOutput={initialOutput}
|
initialOutput={initialOutput}
|
||||||
render={async (request) => {
|
render={async (request) => {
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
import {
|
||||||
|
DocumentBlockListOrdered,
|
||||||
|
DocumentBlockListTasks,
|
||||||
|
DocumentBlockListUnordered,
|
||||||
|
} from '@gitbook/api';
|
||||||
|
import assertNever from 'assert-never';
|
||||||
|
|
||||||
|
import { BlockProps } from './Block';
|
||||||
|
import { Blocks } from './Blocks';
|
||||||
|
|
||||||
|
export function List(
|
||||||
|
props: BlockProps<
|
||||||
|
DocumentBlockListUnordered | DocumentBlockListOrdered | DocumentBlockListTasks
|
||||||
|
>,
|
||||||
|
) {
|
||||||
|
const { block, style, ancestorBlocks, ...contextProps } = props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Blocks
|
||||||
|
{...contextProps}
|
||||||
|
tag={getListTag(block.type)}
|
||||||
|
nodes={block.nodes}
|
||||||
|
ancestorBlocks={[...ancestorBlocks, block]}
|
||||||
|
style={['space-y-2', style]}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getListTag(
|
||||||
|
type:
|
||||||
|
| DocumentBlockListUnordered['type']
|
||||||
|
| DocumentBlockListOrdered['type']
|
||||||
|
| DocumentBlockListTasks['type'],
|
||||||
|
) {
|
||||||
|
switch (type) {
|
||||||
|
case 'list-ordered':
|
||||||
|
return 'ol';
|
||||||
|
case 'list-unordered':
|
||||||
|
case 'list-tasks':
|
||||||
|
return 'ul';
|
||||||
|
default:
|
||||||
|
assertNever(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user