mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-12 05:48:57 +00:00
Remove eslint/prettier and switch to biome (#2880)
This commit is contained in:
@@ -1 +0,0 @@
|
||||
1.2.1
|
||||
@@ -15,4 +15,4 @@ runs:
|
||||
- name: Setup bun
|
||||
uses: oven-sh/setup-bun@v2
|
||||
with:
|
||||
bun-version-file: '.bun-version'
|
||||
bun-version-file: 'package.json'
|
||||
|
||||
@@ -311,19 +311,6 @@ jobs:
|
||||
env:
|
||||
PUPPETEER_SKIP_DOWNLOAD: 1
|
||||
- run: bun format:check
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
name: Lint
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Bun
|
||||
uses: ./.github/composite/setup-bun
|
||||
- name: Install dependencies
|
||||
run: bun install --frozen-lockfile
|
||||
env:
|
||||
PUPPETEER_SKIP_DOWNLOAD: 1
|
||||
- run: bun lint --no-cache
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
name: Test
|
||||
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"recommendations": ["biomejs.biome"]
|
||||
}
|
||||
Vendored
+6
-1
@@ -7,5 +7,10 @@
|
||||
["style \\=([^;]*);", "\"([^\"]*)\""],
|
||||
["style \\=([^;]*);", "\\`([^\\`]*)\\`"]
|
||||
],
|
||||
"tailwindCSS.classAttributes": ["class", "className", "style", ".*Style"]
|
||||
"tailwindCSS.classAttributes": ["class", "className", "style", ".*Style"],
|
||||
"prettier.enable": false,
|
||||
"editor.defaultFormatter": "biomejs.biome",
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.organizeImports": "explicit"
|
||||
}
|
||||
}
|
||||
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
{
|
||||
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
|
||||
"vcs": {
|
||||
"enabled": false,
|
||||
"clientKind": "git",
|
||||
"useIgnoreFile": false
|
||||
},
|
||||
"files": {
|
||||
"ignoreUnknown": false,
|
||||
"ignore": [
|
||||
"**/node_modules/**/*",
|
||||
"**/dist/**/*",
|
||||
"**/build/**/*",
|
||||
"**/public/**/*",
|
||||
"**/.next/**/*",
|
||||
"**/.open-next/**/*",
|
||||
"**/.turbo/**/*",
|
||||
"**/.vercel/**/*",
|
||||
"**/.cache/**/*",
|
||||
"**/.wrangler/**/*",
|
||||
"packages/openapi-parser/src/fixtures/**/*"
|
||||
]
|
||||
},
|
||||
"formatter": {
|
||||
"enabled": true,
|
||||
"useEditorconfig": true,
|
||||
"formatWithErrors": false,
|
||||
"indentStyle": "space",
|
||||
"indentWidth": 4,
|
||||
"lineEnding": "lf",
|
||||
"lineWidth": 100,
|
||||
"attributePosition": "auto",
|
||||
"bracketSpacing": true
|
||||
},
|
||||
"organizeImports": {
|
||||
"enabled": true
|
||||
},
|
||||
"linter": {
|
||||
"enabled": true,
|
||||
"rules": {
|
||||
"recommended": true,
|
||||
"performance": {
|
||||
"noDelete": "warn"
|
||||
},
|
||||
"security": {
|
||||
"noDangerouslySetInnerHtml": "off"
|
||||
},
|
||||
"complexity": {
|
||||
"noForEach": "off",
|
||||
"noUselessFragments": "warn",
|
||||
"noBannedTypes": "warn"
|
||||
},
|
||||
"correctness": {
|
||||
"noUndeclaredVariables": "error",
|
||||
"noUnusedVariables": "error",
|
||||
"useArrayLiterals": "error",
|
||||
"useHookAtTopLevel": "error",
|
||||
"noUnusedImports": "error",
|
||||
"noVoidElementsWithChildren": "warn",
|
||||
"useJsxKeyInIterable": "warn",
|
||||
"useExhaustiveDependencies": "warn"
|
||||
},
|
||||
"style": {
|
||||
"noNonNullAssertion": "warn",
|
||||
"noParameterAssign": "off",
|
||||
"useThrowOnlyError": "error"
|
||||
},
|
||||
"suspicious": {
|
||||
"noConsole": "warn",
|
||||
"noExplicitAny": "warn",
|
||||
"noImplicitAnyLet": "warn",
|
||||
"noConfusingVoidType": "warn",
|
||||
"noControlCharactersInRegex": "warn",
|
||||
"noPrototypeBuiltins": "warn",
|
||||
"noAssignInExpressions": "warn",
|
||||
"noArrayIndexKey": "warn"
|
||||
},
|
||||
"a11y": {
|
||||
"useSemanticElements": "warn",
|
||||
"useKeyWithClickEvents": "warn",
|
||||
"noSvgWithoutTitle": "warn",
|
||||
"useButtonType": "warn",
|
||||
"useIframeTitle": "warn",
|
||||
"useAltText": "warn",
|
||||
"noPositiveTabindex": "warn",
|
||||
"useFocusableInteractive": "warn",
|
||||
"useAriaPropsForRole": "warn",
|
||||
"useValidAnchor": "warn",
|
||||
"noLabelWithoutControl": "warn",
|
||||
"noNoninteractiveTabindex": "warn"
|
||||
},
|
||||
"nursery": {
|
||||
"useSortedClasses": {
|
||||
"level": "error",
|
||||
"fix": "safe",
|
||||
"options": {
|
||||
"attributes": ["class", "className", "style"],
|
||||
"functions": ["clsx", "tw"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"javascript": {
|
||||
"formatter": {
|
||||
"jsxQuoteStyle": "double",
|
||||
"quoteProperties": "asNeeded",
|
||||
"trailingCommas": "es5",
|
||||
"semicolons": "always",
|
||||
"arrowParentheses": "always",
|
||||
"bracketSameLine": false,
|
||||
"quoteStyle": "single",
|
||||
"attributePosition": "auto",
|
||||
"bracketSpacing": true
|
||||
}
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"include": [
|
||||
"packages/gitbook/**/*",
|
||||
"packages/gitbook-v2/**/*",
|
||||
"packages/react-openapi/**/*",
|
||||
"packages/react-math/**/*",
|
||||
"packages/react-contentkit/**/*",
|
||||
"packages/icons/**/*"
|
||||
],
|
||||
"javascript": {
|
||||
"globals": ["React"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"include": ["packages/gitbook/**/*"],
|
||||
"javascript": {
|
||||
"globals": ["React", "GitBookIntegrationEvent"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"include": ["*.css"],
|
||||
"javascript": {
|
||||
"globals": ["theme"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"include": ["*.test.ts", "packages/gitbook/tests/**/*"],
|
||||
"javascript": {
|
||||
"globals": ["Bun"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"include": [
|
||||
"packages/cache-do/**/*",
|
||||
"packages/gitbook/cf-env.d.ts",
|
||||
"packages/gitbook/src/cloudflare-entrypoint.ts"
|
||||
],
|
||||
"javascript": {
|
||||
"globals": [
|
||||
"DurableObjectLocationHint",
|
||||
"DurableObjectNamespace",
|
||||
"DurableObjectStub",
|
||||
"ContinentCode",
|
||||
"Fetcher",
|
||||
"ExportedHandler"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
# Caching
|
||||
|
||||
## Revalidating the cache
|
||||
|
||||
Invalidate cache can be done at two levels using tags:
|
||||
|
||||
- Data fetching cache
|
||||
- Rendering cache
|
||||
|
||||
To invalidate and refetch the data cache, you can execute a POST request to `/~/gitbook/revalidate`:
|
||||
|
||||
```bash
|
||||
curl --location --request POST 'https://gitbook/mycompany.com/~gitbook/revalidate' \
|
||||
--header 'Content-Type: application/json' \
|
||||
--data-raw '{"tags": ["space.id"]}'
|
||||
```
|
||||
|
||||
To invalidate the rendering cache, the implementation mainly depends on the infrastructure serving the content, GitBook outputs a `Cache-Tag` header on every requests. The value of the header is a comma separated list of tags.
|
||||
|
||||
## Purging the cache
|
||||
|
||||
Purging the cache, without revalidating, is done by passing `"purge": true` in the request body.
|
||||
+6
-10
@@ -2,12 +2,12 @@
|
||||
"name": "gitbook",
|
||||
"version": "0.1.0",
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "^1.9.4",
|
||||
"@changesets/cli": "^2.27.12",
|
||||
"prettier": "^3.0.3",
|
||||
"turbo": "^2.4.1-canary.2",
|
||||
"turbo": "^2.4.4",
|
||||
"vercel": "^39.3.0"
|
||||
},
|
||||
"packageManager": "bun@1.1.18",
|
||||
"packageManager": "bun@1.2.3",
|
||||
"overrides": {
|
||||
"@codemirror/state": "6.4.1",
|
||||
"react": "18.3.1",
|
||||
@@ -20,11 +20,9 @@
|
||||
"build": "turbo run build",
|
||||
"build:v2": "turbo run build:v2",
|
||||
"clean-deps": "rm -rf node_modules && rm -rf packages/*/node_modules",
|
||||
"lint": "turbo run lint",
|
||||
"lint:fix": "turbo run lint -- --fix",
|
||||
"typecheck": "turbo run typecheck",
|
||||
"format": "prettier ./ --ignore-unknown --write",
|
||||
"format:check": "prettier ./ --ignore-unknown --list-different",
|
||||
"format": "biome check --write ./",
|
||||
"format:check": "biome check --diagnostic-level=error ./",
|
||||
"unit": "turbo run unit",
|
||||
"e2e": "turbo run e2e",
|
||||
"e2e-customers": "turbo run e2e-customers",
|
||||
@@ -34,9 +32,7 @@
|
||||
"download:env": "op read op://gitbook-x-dev/gitbook-open/.env.local >> .env.local",
|
||||
"clean": "turbo run clean"
|
||||
},
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
],
|
||||
"workspaces": ["packages/*"],
|
||||
"patchedDependencies": {
|
||||
"decode-named-character-reference@1.0.2": "patches/decode-named-character-reference@1.0.2.patch",
|
||||
"@vercel/next@4.4.2": "patches/@vercel%2Fnext@4.4.2.patch"
|
||||
|
||||
@@ -31,12 +31,5 @@
|
||||
"release": "wrangler deploy",
|
||||
"release:preview": "wrangler deploy && wrangler deploy --env preview"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"src",
|
||||
"bin",
|
||||
"data",
|
||||
"README.md",
|
||||
"CHANGELOG.md"
|
||||
]
|
||||
"files": ["dist", "src", "bin", "data", "README.md", "CHANGELOG.md"]
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { encode, decode } from '@msgpack/msgpack';
|
||||
import { DurableObject } from 'cloudflare:workers';
|
||||
import { decode, encode } from '@msgpack/msgpack';
|
||||
import { LRUMap } from 'lru_map';
|
||||
|
||||
export interface CacheObjectDescriptor {
|
||||
@@ -137,7 +137,7 @@ export class CacheObject extends DurableObject {
|
||||
*/
|
||||
public async purge() {
|
||||
return this.logOperation({ operation: 'purge' }, async (setLog) => {
|
||||
let result = new Set<string>();
|
||||
const result = new Set<string>();
|
||||
|
||||
try {
|
||||
// List all the keys in the cache object.
|
||||
@@ -149,11 +149,7 @@ export class CacheObject extends DurableObject {
|
||||
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);
|
||||
}
|
||||
} catch (_error) {}
|
||||
|
||||
await this.reset();
|
||||
return Array.from(result);
|
||||
@@ -174,7 +170,7 @@ export class CacheObject extends DurableObject {
|
||||
const toDeleteSet = new Set<string>();
|
||||
|
||||
for (const [key, exp] of entries) {
|
||||
const timestamp = parseInt(key.split('.')[1]);
|
||||
const timestamp = Number.parseInt(key.split('.')[1]);
|
||||
if (timestamp < Date.now()) {
|
||||
toDeleteSet.add(key);
|
||||
for (let i = 0; i < exp.c; i++) {
|
||||
@@ -194,10 +190,7 @@ export class CacheObject extends DurableObject {
|
||||
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);
|
||||
} catch (_error) {
|
||||
await this.reset();
|
||||
}
|
||||
});
|
||||
@@ -218,10 +211,10 @@ export class CacheObject extends DurableObject {
|
||||
*/
|
||||
async logOperation<T>(
|
||||
log: Record<string, unknown>,
|
||||
fn: (update: (log: Record<string, unknown>) => void) => Promise<T>,
|
||||
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 update: Record<string, unknown> = {};
|
||||
const start = performance.now();
|
||||
try {
|
||||
return await fn((arg) => {
|
||||
@@ -265,7 +258,7 @@ function encodeChunks<T>(key: string, value: T): Record<string, Uint8Array> {
|
||||
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()!);
|
||||
const index = Number.parseInt(key.split('.').pop()!);
|
||||
return [index, value] as const;
|
||||
})
|
||||
.sort(([a], [b]) => a - b)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { CacheObject, CacheObjectDescriptor } from './CacheObject';
|
||||
import type { CacheObject } from './CacheObject';
|
||||
|
||||
export type CacheLocationId = ContinentCode;
|
||||
const allLocations: CacheLocationId[] = ['AF', 'AS', 'NA', 'SA', 'AN', 'EU', 'OC'];
|
||||
@@ -30,7 +30,7 @@ export class CacheObjectStub {
|
||||
/** ID of the location to target */
|
||||
private locationId: CacheLocationId,
|
||||
/** Name of the tag */
|
||||
private tag: string,
|
||||
private tag: string
|
||||
) {
|
||||
const groupId = getCacheObjectIdName(this.locationId, this.tag);
|
||||
this.stub = this.doNamespace.get(this.doNamespace.idFromName(groupId), {
|
||||
@@ -85,7 +85,7 @@ export class CacheObjectStub {
|
||||
});
|
||||
const locationkeys = await cacheGroup.purge();
|
||||
locationkeys.forEach((key) => keys.add(key));
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
return keys;
|
||||
|
||||
@@ -17,10 +17,5 @@
|
||||
"typecheck": "tsc --noEmit",
|
||||
"dev": "tsc -w"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"src",
|
||||
"README.md",
|
||||
"CHANGELOG.md"
|
||||
]
|
||||
"files": ["dist", "src", "README.md", "CHANGELOG.md"]
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { DARK_BASE, LIGHT_BASE, DEFAULT_TINT_COLOR } from './colors';
|
||||
import { DARK_BASE, DEFAULT_TINT_COLOR, LIGHT_BASE } from './colors';
|
||||
|
||||
type ColorShades = {
|
||||
[key: string]: string;
|
||||
@@ -178,7 +178,7 @@ export function colorScale(
|
||||
background = darkMode ? DARK_BASE : LIGHT_BASE,
|
||||
foreground = darkMode ? LIGHT_BASE : DARK_BASE,
|
||||
mix,
|
||||
}: ColorScaleOptions = {},
|
||||
}: ColorScaleOptions = {}
|
||||
) {
|
||||
const baseColor = rgbToOklch(hexToRgbArray(hex));
|
||||
const mixColor = mix?.color ? rgbToOklch(hexToRgbArray(mix.color)) : null;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "react",
|
||||
"jsx": "react-jsx",
|
||||
"incremental": true,
|
||||
"types": [
|
||||
"bun-types" // add Bun global
|
||||
|
||||
@@ -17,12 +17,11 @@ Object.entries(emojis).forEach(([key, value]) => {
|
||||
if (emoji && key !== emoji) {
|
||||
output[key] = emoji;
|
||||
} else if (!emoji) {
|
||||
console.log('No emoji for', key);
|
||||
}
|
||||
});
|
||||
|
||||
fs.mkdirSync(path.resolve(__dirname, 'dist'), { recursive: true });
|
||||
fs.writeFileSync(
|
||||
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)};`
|
||||
);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { getDynamicSiteContext, getPagePathFromParams, RouteParams } from '@v2/app/utils';
|
||||
import {
|
||||
SitePage,
|
||||
generateSitePageMetadata,
|
||||
generateSitePageViewport,
|
||||
SitePage,
|
||||
} from '@/components/SitePage';
|
||||
import { Metadata, Viewport } from 'next';
|
||||
import { type RouteParams, getDynamicSiteContext, getPagePathFromParams } from '@v2/app/utils';
|
||||
import type { Metadata, Viewport } from 'next';
|
||||
|
||||
type PageProps = {
|
||||
params: Promise<RouteParams>;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { CustomizationRootLayout } from '@/components/RootLayout';
|
||||
import { SiteLayout } from '@/components/SiteLayout';
|
||||
import { getDynamicSiteContext, RouteLayoutParams } from '@v2/app/utils';
|
||||
import { type RouteLayoutParams, getDynamicSiteContext } from '@v2/app/utils';
|
||||
import { GITBOOK_DISABLE_TRACKING } from '@v2/lib/env';
|
||||
import { getThemeFromMiddleware } from '@v2/lib/middleware';
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { unstable_cacheTag as cacheTag } from 'next/cache';
|
||||
import { getSiteCacheTag } from '@v2/lib/cache';
|
||||
import { getPagePathFromParams, getStaticSiteContext, RouteParams } from '@v2/app/utils';
|
||||
import {
|
||||
SitePage,
|
||||
generateSitePageMetadata,
|
||||
generateSitePageViewport,
|
||||
SitePage,
|
||||
} from '@/components/SitePage';
|
||||
import { Metadata, Viewport } from 'next';
|
||||
import { type RouteParams, getPagePathFromParams, getStaticSiteContext } from '@v2/app/utils';
|
||||
import { getSiteCacheTag } from '@v2/lib/cache';
|
||||
import type { Metadata, Viewport } from 'next';
|
||||
import { unstable_cacheTag as cacheTag } from 'next/cache';
|
||||
|
||||
export const dynamic = 'force-static';
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { unstable_cacheTag as cacheTag } from 'next/cache';
|
||||
import { getSiteCacheTag } from '@v2/lib/cache';
|
||||
import { getStaticSiteContext, RouteLayoutParams } from '@v2/app/utils';
|
||||
import { CustomizationRootLayout } from '@/components/RootLayout';
|
||||
import { SiteLayout } from '@/components/SiteLayout';
|
||||
import { type RouteLayoutParams, getStaticSiteContext } from '@v2/app/utils';
|
||||
import { getSiteCacheTag } from '@v2/lib/cache';
|
||||
import { GITBOOK_DISABLE_TRACKING } from '@v2/lib/env';
|
||||
import { unstable_cacheTag as cacheTag } from 'next/cache';
|
||||
|
||||
export default async function SiteStaticLayout({
|
||||
params,
|
||||
|
||||
@@ -38,7 +38,7 @@ export function getStaticSiteContext(params: RouteLayoutParams) {
|
||||
url: url.toString(),
|
||||
visitorAuthToken: null,
|
||||
redirectOnError: false,
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ export async function getDynamicSiteContext(params: RouteLayoutParams) {
|
||||
|
||||
// TODO: set it only when the token comes from the cookies.
|
||||
redirectOnError: true,
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ function createLinkerFromParams(params: RouteLayoutParams) {
|
||||
|
||||
function getSiteURLFromParams(params: RouteLayoutParams) {
|
||||
const decoded = decodeURIComponent(params.siteURL);
|
||||
const url = new URL('https://' + decoded);
|
||||
const url = new URL(`https://${decoded}`);
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
import { getSiteStructureSections } from '@/lib/sites';
|
||||
import type {
|
||||
ChangeRequest,
|
||||
RevisionPage,
|
||||
RevisionPageDocument,
|
||||
@@ -11,12 +12,11 @@ import {
|
||||
SiteStructure,
|
||||
Space,
|
||||
} from '@gitbook/api';
|
||||
import { type GitBookDataFetcher, createDataFetcher } from '@v2/lib/data';
|
||||
import { redirect } from 'next/navigation';
|
||||
import { assert } from 'ts-essentials';
|
||||
import { getSiteStructureSections } from '@/lib/sites';
|
||||
import { createDataFetcher, GitBookDataFetcher } from '@v2/lib/data';
|
||||
import { GitBookSpaceLinker, appendPrefixToLinker } from './links';
|
||||
import { ImageResizer } from './images';
|
||||
import type { ImageResizer } from './images';
|
||||
import { type GitBookSpaceLinker, appendPrefixToLinker } from './links';
|
||||
|
||||
/**
|
||||
* Generic context when rendering content.
|
||||
@@ -111,7 +111,7 @@ export async function fetchSiteContextByURL(
|
||||
url: string;
|
||||
visitorAuthToken: string | null;
|
||||
redirectOnError: boolean;
|
||||
},
|
||||
}
|
||||
): Promise<GitBookSiteContext> {
|
||||
const { dataFetcher } = baseContext;
|
||||
const data = await dataFetcher.getPublishedContentByUrl({
|
||||
@@ -142,7 +142,7 @@ export async function fetchSiteContextByURL(
|
||||
changeRequest: data.changeRequest,
|
||||
revision: data.revision,
|
||||
visitorAuthToken: input.visitorAuthToken,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const siteContext = {
|
||||
@@ -168,7 +168,7 @@ export async function fetchSiteContextByIds(
|
||||
changeRequest: string | undefined;
|
||||
revision: string | undefined;
|
||||
visitorAuthToken: string | null;
|
||||
},
|
||||
}
|
||||
): Promise<GitBookSiteContext> {
|
||||
const { dataFetcher } = baseContext;
|
||||
|
||||
@@ -211,11 +211,13 @@ export async function fetchSiteContextByIds(
|
||||
if (siteSpaceSettings) {
|
||||
return siteSpaceSettings;
|
||||
}
|
||||
|
||||
// We got the pointer from an API and customizations from another.
|
||||
// It's possible that the two are unsynced leading to not found customizations for the space.
|
||||
// It's better to fallback on customization of the site that displaying an error.
|
||||
console.warn('Customization not found for site space', ids.siteSpace);
|
||||
}
|
||||
|
||||
return customizations.site;
|
||||
})();
|
||||
|
||||
@@ -243,7 +245,7 @@ export async function fetchSpaceContextByIds(
|
||||
shareKey: string | undefined;
|
||||
changeRequest: string | undefined;
|
||||
revision: string | undefined;
|
||||
},
|
||||
}
|
||||
): Promise<GitBookSpaceContext> {
|
||||
const { dataFetcher } = baseContext;
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { unstable_cacheLife as cacheLife, unstable_cacheTag as cacheTag } from 'next/cache';
|
||||
import { ComputedContentSource, GitBookAPI } from '@gitbook/api';
|
||||
import { type ComputedContentSource, GitBookAPI } from '@gitbook/api';
|
||||
import { GITBOOK_API_TOKEN, GITBOOK_API_URL, GITBOOK_USER_AGENT } from '@v2/lib/env';
|
||||
import { GitBookDataFetcher } from './types';
|
||||
import { unstable_cacheTag as cacheTag } from 'next/cache';
|
||||
import {
|
||||
getChangeRequestCacheTag,
|
||||
getHostnameCacheTag,
|
||||
@@ -9,6 +8,7 @@ import {
|
||||
getSiteCacheTag,
|
||||
getSpaceCacheTag,
|
||||
} from '../cache';
|
||||
import type { GitBookDataFetcher } from './types';
|
||||
|
||||
interface DataFetcherInput {
|
||||
/**
|
||||
@@ -156,7 +156,7 @@ async function getSpace(
|
||||
params: {
|
||||
spaceId: string;
|
||||
shareKey: string | undefined;
|
||||
},
|
||||
}
|
||||
) {
|
||||
'use cache';
|
||||
|
||||
@@ -173,14 +173,14 @@ async function getChangeRequest(
|
||||
params: {
|
||||
spaceId: string;
|
||||
changeRequestId: string;
|
||||
},
|
||||
}
|
||||
) {
|
||||
'use cache';
|
||||
|
||||
try {
|
||||
const res = await getAPI(input).spaces.getChangeRequestById(
|
||||
params.spaceId,
|
||||
params.changeRequestId,
|
||||
params.changeRequestId
|
||||
);
|
||||
cacheTag(getChangeRequestCacheTag(params.spaceId, res.data.id));
|
||||
return res.data;
|
||||
@@ -199,7 +199,7 @@ async function getRevision(
|
||||
spaceId: string;
|
||||
revisionId: string;
|
||||
metadata: boolean;
|
||||
},
|
||||
}
|
||||
) {
|
||||
'use cache';
|
||||
|
||||
@@ -215,7 +215,7 @@ async function getRevisionPages(
|
||||
spaceId: string;
|
||||
revisionId: string;
|
||||
metadata: boolean;
|
||||
},
|
||||
}
|
||||
) {
|
||||
'use cache';
|
||||
|
||||
@@ -224,7 +224,7 @@ async function getRevisionPages(
|
||||
params.revisionId,
|
||||
{
|
||||
metadata: params.metadata,
|
||||
},
|
||||
}
|
||||
);
|
||||
return res.data.pages;
|
||||
}
|
||||
@@ -235,7 +235,7 @@ async function getRevisionFile(
|
||||
spaceId: string;
|
||||
revisionId: string;
|
||||
fileId: string;
|
||||
},
|
||||
}
|
||||
) {
|
||||
'use cache';
|
||||
|
||||
@@ -243,7 +243,7 @@ async function getRevisionFile(
|
||||
const res = await getAPI(input).spaces.getFileInRevisionById(
|
||||
params.spaceId,
|
||||
params.revisionId,
|
||||
params.fileId,
|
||||
params.fileId
|
||||
);
|
||||
return res.data;
|
||||
} catch (error) {
|
||||
@@ -261,7 +261,7 @@ async function getRevisionPageByPath(
|
||||
spaceId: string;
|
||||
revisionId: string;
|
||||
path: string;
|
||||
},
|
||||
}
|
||||
) {
|
||||
'use cache';
|
||||
|
||||
@@ -271,7 +271,7 @@ async function getRevisionPageByPath(
|
||||
const res = await getAPI(input).spaces.getPageInRevisionByPath(
|
||||
params.spaceId,
|
||||
params.revisionId,
|
||||
encodedPath,
|
||||
encodedPath
|
||||
);
|
||||
|
||||
return res.data;
|
||||
@@ -289,7 +289,7 @@ async function getDocument(
|
||||
params: {
|
||||
spaceId: string;
|
||||
documentId: string;
|
||||
},
|
||||
}
|
||||
) {
|
||||
'use cache';
|
||||
|
||||
@@ -302,7 +302,7 @@ async function getComputedDocument(
|
||||
params: {
|
||||
spaceId: string;
|
||||
source: ComputedContentSource;
|
||||
},
|
||||
}
|
||||
) {
|
||||
'use cache';
|
||||
|
||||
@@ -318,7 +318,7 @@ async function getReusableContent(
|
||||
spaceId: string;
|
||||
revisionId: string;
|
||||
reusableContentId: string;
|
||||
},
|
||||
}
|
||||
) {
|
||||
'use cache';
|
||||
|
||||
@@ -326,7 +326,7 @@ async function getReusableContent(
|
||||
const res = await getAPI(input).spaces.getReusableContentInRevisionById(
|
||||
params.spaceId,
|
||||
params.revisionId,
|
||||
params.reusableContentId,
|
||||
params.reusableContentId
|
||||
);
|
||||
return res.data;
|
||||
} catch (error) {
|
||||
@@ -343,7 +343,7 @@ async function getLatestOpenAPISpecVersionContent(
|
||||
params: {
|
||||
organizationId: string;
|
||||
slug: string;
|
||||
},
|
||||
}
|
||||
) {
|
||||
'use cache';
|
||||
|
||||
@@ -352,7 +352,7 @@ async function getLatestOpenAPISpecVersionContent(
|
||||
try {
|
||||
const res = await getAPI(input).orgs.getLatestOpenApiSpecVersionContent(
|
||||
params.organizationId,
|
||||
params.slug,
|
||||
params.slug
|
||||
);
|
||||
return res.data;
|
||||
} catch (error) {
|
||||
@@ -370,7 +370,7 @@ async function getPublishedContentByUrl(
|
||||
url: string;
|
||||
visitorAuthToken: string | null;
|
||||
redirectOnError: boolean;
|
||||
},
|
||||
}
|
||||
) {
|
||||
'use cache';
|
||||
|
||||
@@ -398,7 +398,7 @@ async function getPublishedContentSite(
|
||||
organizationId: string;
|
||||
siteId: string;
|
||||
siteShareKey: string | undefined;
|
||||
},
|
||||
}
|
||||
) {
|
||||
'use cache';
|
||||
cacheTag(getSiteCacheTag(params.siteId));
|
||||
@@ -407,7 +407,7 @@ async function getPublishedContentSite(
|
||||
params.siteId,
|
||||
{
|
||||
shareKey: params.siteShareKey,
|
||||
},
|
||||
}
|
||||
);
|
||||
return res.data;
|
||||
}
|
||||
@@ -419,7 +419,7 @@ async function getSiteRedirectBySource(
|
||||
siteId: string;
|
||||
siteShareKey: string | undefined;
|
||||
source: string;
|
||||
},
|
||||
}
|
||||
) {
|
||||
'use cache';
|
||||
|
||||
@@ -430,7 +430,7 @@ async function getSiteRedirectBySource(
|
||||
{
|
||||
shareKey: params.siteShareKey,
|
||||
source: params.source,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
return res.data;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { describe, it, expect } from 'bun:test';
|
||||
import { describe, expect, it } from 'bun:test';
|
||||
|
||||
import { getURLLookupAlternatives, normalizeURL } from './urls';
|
||||
|
||||
@@ -68,7 +68,7 @@ describe('getURLLookupAlternatives', () => {
|
||||
|
||||
it('should not match before the variant for a variant url', () => {
|
||||
expect(
|
||||
getURLLookupAlternatives(new URL('https://test.gitbook.io/v/variant/space')),
|
||||
getURLLookupAlternatives(new URL('https://test.gitbook.io/v/variant/space'))
|
||||
).toEqual({
|
||||
revision: undefined,
|
||||
changeRequest: undefined,
|
||||
@@ -85,7 +85,7 @@ describe('getURLLookupAlternatives', () => {
|
||||
|
||||
it('should not match before the variant for a variant in a share link', () => {
|
||||
expect(
|
||||
getURLLookupAlternatives(new URL('https://test.gitbook.io/sharelink/v/variant/space')),
|
||||
getURLLookupAlternatives(new URL('https://test.gitbook.io/sharelink/v/variant/space'))
|
||||
).toEqual({
|
||||
revision: undefined,
|
||||
changeRequest: undefined,
|
||||
@@ -103,8 +103,8 @@ describe('getURLLookupAlternatives', () => {
|
||||
it('should not match before a revision in a variant', () => {
|
||||
expect(
|
||||
getURLLookupAlternatives(
|
||||
new URL('https://test.gitbook.io/v/variant/~/revisions/id/rest'),
|
||||
),
|
||||
new URL('https://test.gitbook.io/v/variant/~/revisions/id/rest')
|
||||
)
|
||||
).toEqual({
|
||||
revision: 'id',
|
||||
changeRequest: undefined,
|
||||
@@ -121,7 +121,7 @@ describe('getURLLookupAlternatives', () => {
|
||||
|
||||
it('should not match before a revision ID', () => {
|
||||
expect(
|
||||
getURLLookupAlternatives(new URL('https://docs.mycompany.com/~/revisions/id/a/b/c')),
|
||||
getURLLookupAlternatives(new URL('https://docs.mycompany.com/~/revisions/id/a/b/c'))
|
||||
).toEqual({
|
||||
revision: 'id',
|
||||
changeRequest: undefined,
|
||||
@@ -138,7 +138,7 @@ describe('getURLLookupAlternatives', () => {
|
||||
|
||||
it('should not match before a change request ID', () => {
|
||||
expect(
|
||||
getURLLookupAlternatives(new URL('https://docs.mycompany.com/~/changes/id/hello')),
|
||||
getURLLookupAlternatives(new URL('https://docs.mycompany.com/~/changes/id/hello'))
|
||||
).toEqual({
|
||||
revision: undefined,
|
||||
changeRequest: 'id',
|
||||
@@ -195,7 +195,7 @@ describe('getURLLookupAlternatives', () => {
|
||||
|
||||
it('should match a variant in a share-link', () => {
|
||||
expect(
|
||||
getURLLookupAlternatives(new URL('https://test.gitbook.io/sharelink/v/variant/space')),
|
||||
getURLLookupAlternatives(new URL('https://test.gitbook.io/sharelink/v/variant/space'))
|
||||
).toEqual({
|
||||
revision: undefined,
|
||||
changeRequest: undefined,
|
||||
@@ -213,8 +213,8 @@ describe('getURLLookupAlternatives', () => {
|
||||
it('should match a revision in a variant in a share-link', () => {
|
||||
expect(
|
||||
getURLLookupAlternatives(
|
||||
new URL('https://test.gitbook.io/sharelink/v/variant/~/revisions/id/a/b/c'),
|
||||
),
|
||||
new URL('https://test.gitbook.io/sharelink/v/variant/~/revisions/id/a/b/c')
|
||||
)
|
||||
).toEqual({
|
||||
revision: 'id',
|
||||
changeRequest: undefined,
|
||||
@@ -232,8 +232,8 @@ describe('getURLLookupAlternatives', () => {
|
||||
it('should match a change request in a variant in a share-link', () => {
|
||||
expect(
|
||||
getURLLookupAlternatives(
|
||||
new URL('https://test.gitbook.io/sharelink/v/variant/~/changes/id/a/b/c'),
|
||||
),
|
||||
new URL('https://test.gitbook.io/sharelink/v/variant/~/changes/id/a/b/c')
|
||||
)
|
||||
).toEqual({
|
||||
revision: undefined,
|
||||
changeRequest: 'id',
|
||||
@@ -367,13 +367,13 @@ describe('getURLLookupAlternatives', () => {
|
||||
describe('normalizeURL', () => {
|
||||
it('should remove trailing slashes', () => {
|
||||
expect(normalizeURL(new URL('https://docs.mycompany.com/hello/'))).toEqual(
|
||||
new URL('https://docs.mycompany.com/hello'),
|
||||
new URL('https://docs.mycompany.com/hello')
|
||||
);
|
||||
});
|
||||
|
||||
it('should remove duplicate slashes', () => {
|
||||
expect(normalizeURL(new URL('https://docs.mycompany.com//hello//there'))).toEqual(
|
||||
new URL('https://docs.mycompany.com/hello/there'),
|
||||
new URL('https://docs.mycompany.com/hello/there')
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -19,10 +19,6 @@ export async function getPublishedContentByURL(input: {
|
||||
const url = stripURLSearch(lookupURL);
|
||||
const lookup = getURLLookupAlternatives(url);
|
||||
|
||||
console.log(
|
||||
`lookup content for url "${url.toString()}", with ${lookup.urls.length} alternatives`,
|
||||
);
|
||||
|
||||
const result = await race(lookup.urls, async (alternative, { signal }) => {
|
||||
const api = new GitBookAPI({
|
||||
authToken: GITBOOK_API_TOKEN ?? undefined,
|
||||
@@ -43,8 +39,8 @@ export async function getPublishedContentByURL(input: {
|
||||
headers: {
|
||||
'x-gitbook-force-cache': 'true',
|
||||
},
|
||||
},
|
||||
),
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
if (callResult.error) {
|
||||
@@ -76,8 +72,8 @@ export async function getPublishedContentByURL(input: {
|
||||
'location',
|
||||
joinPath(
|
||||
redirect.searchParams.get('location') ?? '',
|
||||
alternative.extraPath,
|
||||
),
|
||||
alternative.extraPath
|
||||
)
|
||||
);
|
||||
data.redirect = redirect.toString();
|
||||
}
|
||||
@@ -155,7 +151,7 @@ export function getURLLookupAlternatives(input: URL) {
|
||||
throw new Error(
|
||||
`Invalid extraPath ${extraPath} for url ${adding.toString()}, already set to ${
|
||||
existing.extraPath
|
||||
}`,
|
||||
}`
|
||||
);
|
||||
}
|
||||
return;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { RevisionPageDocument } from '@gitbook/api';
|
||||
import { GitBookDataFetcher } from './types';
|
||||
import type { RevisionPageDocument } from '@gitbook/api';
|
||||
import type { GitBookDataFetcher } from './types';
|
||||
|
||||
/**
|
||||
* Get the document for a page.
|
||||
@@ -7,11 +7,12 @@ import { GitBookDataFetcher } from './types';
|
||||
export async function getPageDocument(
|
||||
dataFetcher: GitBookDataFetcher,
|
||||
spaceId: string,
|
||||
page: RevisionPageDocument,
|
||||
page: RevisionPageDocument
|
||||
) {
|
||||
if (page.documentId) {
|
||||
return dataFetcher.getDocument({ spaceId, documentId: page.documentId });
|
||||
} else if (page.computed) {
|
||||
}
|
||||
if (page.computed) {
|
||||
return dataFetcher.getComputedDocument({ spaceId, source: page.computed });
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ export const GITBOOK_URL =
|
||||
/**
|
||||
* GitBook app URL.
|
||||
*/
|
||||
export const GITBOOK_APP_URL = process.env.NEXT_PUBLIC_GITBOOK_APP_URL ?? `https://app.gitbook.com`;
|
||||
export const GITBOOK_APP_URL = process.env.NEXT_PUBLIC_GITBOOK_APP_URL ?? 'https://app.gitbook.com';
|
||||
|
||||
/**
|
||||
* Default GitBook API URL endpoint.
|
||||
@@ -34,5 +34,5 @@ export const GITBOOK_USER_AGENT = process.env.GITBOOK_USER_AGENT ?? 'GitBook-Ope
|
||||
* This is used to disable tracking in development mode.
|
||||
*/
|
||||
export const GITBOOK_DISABLE_TRACKING = Boolean(
|
||||
!!process.env.GITBOOK_DISABLE_TRACKING || process.env.NODE_ENV !== 'production',
|
||||
!!process.env.GITBOOK_DISABLE_TRACKING || process.env.NODE_ENV !== 'production'
|
||||
);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import 'server-only';
|
||||
|
||||
import type { GitBookSpaceLinker } from '../links';
|
||||
import { type SignatureVersion, generateImageSignature } from './signatures';
|
||||
import type { ImageResizer } from './types';
|
||||
import { generateImageSignature, SignatureVersion } from './signatures';
|
||||
import { GitBookSpaceLinker } from '../links';
|
||||
|
||||
interface CloudflareImageJsonFormat {
|
||||
width: number;
|
||||
@@ -96,7 +96,7 @@ export function createImageResizer({
|
||||
export function createNoopImageResizer(): ImageResizer {
|
||||
return {
|
||||
resize: () => null,
|
||||
getImageSize: async (input) => null,
|
||||
getImageSize: async (_input) => null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ export function checkIsSizableImageURL(input: string): boolean {
|
||||
*/
|
||||
export async function getImageSize(
|
||||
input: string,
|
||||
defaultSize: Partial<CloudflareImageOptions> = {},
|
||||
defaultSize: Partial<CloudflareImageOptions> = {}
|
||||
): Promise<{ width: number; height: number } | null> {
|
||||
if (!isImageResizingEnabled() || !checkIsSizableImageURL(input)) {
|
||||
return null;
|
||||
@@ -171,12 +171,7 @@ export async function getImageSize(
|
||||
width: json.original.width,
|
||||
height: json.original.height,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(
|
||||
`failed to fetch image size for ${input}: ${
|
||||
(error as Error).stack ?? (error as Error).message ?? error
|
||||
}`,
|
||||
);
|
||||
} catch (_error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -188,7 +183,7 @@ export async function resizeImage(
|
||||
input: string,
|
||||
options: CloudflareImageOptions & {
|
||||
signal?: AbortSignal;
|
||||
},
|
||||
}
|
||||
): Promise<Response> {
|
||||
const { signal, ...resizeOptions } = options;
|
||||
|
||||
@@ -206,7 +201,7 @@ export async function resizeImage(
|
||||
if (process.env.GITBOOK_IMAGE_RESIZE_URL) {
|
||||
const response = await fetch(
|
||||
`${process.env.GITBOOK_IMAGE_RESIZE_URL}${stringifyOptions(
|
||||
resizeOptions,
|
||||
resizeOptions
|
||||
)}/${encodeURIComponent(input)}`,
|
||||
{
|
||||
headers: {
|
||||
@@ -217,7 +212,7 @@ export async function resizeImage(
|
||||
: `image/${resizeOptions.format || 'jpeg'}`,
|
||||
},
|
||||
signal,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
return response;
|
||||
|
||||
@@ -26,7 +26,7 @@ type SignFn = (input: SignFnInput) => MaybePromise<string>;
|
||||
*/
|
||||
export async function verifyImageSignature(
|
||||
input: SignFnInput,
|
||||
{ signature, version }: { signature: string; version: SignatureVersion },
|
||||
{ signature, version }: { signature: string; version: SignatureVersion }
|
||||
): Promise<boolean> {
|
||||
const generator = IMAGE_SIGNATURE_FUNCTIONS[version];
|
||||
const generated = await generator(input);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ImageResizer, ResizeImageOptions } from './types';
|
||||
import type { ImageResizer, ResizeImageOptions } from './types';
|
||||
|
||||
/**
|
||||
* Quick utility to get a resized image URL.
|
||||
@@ -6,7 +6,7 @@ import { ImageResizer, ResizeImageOptions } from './types';
|
||||
export async function getResizedImageURL(
|
||||
resizer: ImageResizer,
|
||||
url: string,
|
||||
options: ResizeImageOptions,
|
||||
options: ResizeImageOptions
|
||||
) {
|
||||
const getURL = resizer.resize(url);
|
||||
if (!getURL) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { RevisionPage, RevisionPageDocument, RevisionPageGroup } from '@gitbook/api';
|
||||
import { getPagePath } from '@/lib/pages';
|
||||
import type { RevisionPage, RevisionPageDocument, RevisionPageGroup } from '@gitbook/api';
|
||||
|
||||
/**
|
||||
* Generic interface to generate links based on a given context.
|
||||
@@ -34,7 +34,7 @@ export function createLinker(
|
||||
protocol?: string;
|
||||
host: string;
|
||||
pathname: string;
|
||||
},
|
||||
}
|
||||
): GitBookSpaceLinker {
|
||||
if (servedOn.host.includes('/')) {
|
||||
throw new Error('Host cannot include a slash');
|
||||
@@ -50,7 +50,7 @@ export function createLinker(
|
||||
},
|
||||
|
||||
toPathForPage({ pages, page, anchor }) {
|
||||
return linker.toPathInSpace(getPagePath(pages, page)) + (anchor ? '#' + anchor : '');
|
||||
return linker.toPathInSpace(getPagePath(pages, page)) + (anchor ? `#${anchor}` : '');
|
||||
},
|
||||
};
|
||||
|
||||
@@ -62,7 +62,7 @@ export function createLinker(
|
||||
*/
|
||||
export function appendPrefixToLinker(
|
||||
linker: GitBookSpaceLinker,
|
||||
prefix: string,
|
||||
prefix: string
|
||||
): GitBookSpaceLinker {
|
||||
const linkerWithPrefix: GitBookSpaceLinker = {
|
||||
toPathInSpace(relativePath: string): string {
|
||||
@@ -76,7 +76,7 @@ export function appendPrefixToLinker(
|
||||
toPathForPage({ pages, page, anchor }) {
|
||||
return (
|
||||
linkerWithPrefix.toPathInSpace(getPagePath(pages, page)) +
|
||||
(anchor ? '#' + anchor : '')
|
||||
(anchor ? `#${anchor}` : '')
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -85,7 +85,7 @@ export function appendPrefixToLinker(
|
||||
}
|
||||
|
||||
function joinPaths(prefix: string, path: string): string {
|
||||
const prefixPath = prefix.endsWith('/') ? prefix : prefix + '/';
|
||||
const prefixPath = prefix.endsWith('/') ? prefix : `${prefix}/`;
|
||||
const suffixPath = path.startsWith('/') ? path.slice(1) : path;
|
||||
return prefixPath + suffixPath;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { GitBookAPIError } from '@gitbook/api';
|
||||
import { NextResponse } from 'next/server';
|
||||
import type { NextRequest } from 'next/server';
|
||||
import { GitBookAPIError } from '@gitbook/api';
|
||||
|
||||
import { removeTrailingSlash } from '@/lib/paths';
|
||||
import { MiddlewareHeaders } from '@v2/lib/middleware';
|
||||
import { getPublishedContentByURL } from '@v2/lib/data';
|
||||
import { MiddlewareHeaders } from '@v2/lib/middleware';
|
||||
|
||||
export const config = {
|
||||
matcher: ['/((?!_next/|_static/|_vercel|[\\w-]+\\.\\w+).*)'],
|
||||
@@ -40,11 +40,10 @@ async function serveSiteByURL(request: NextRequest, urlWithMode: URLWithMode) {
|
||||
{
|
||||
error: result.error.message,
|
||||
},
|
||||
{ status: result.error.code },
|
||||
{ status: result.error.code }
|
||||
);
|
||||
} else {
|
||||
throw result.error;
|
||||
}
|
||||
throw result.error;
|
||||
}
|
||||
|
||||
const { data } = result;
|
||||
@@ -69,7 +68,7 @@ async function serveSiteByURL(request: NextRequest, urlWithMode: URLWithMode) {
|
||||
encodeURIComponent(removeTrailingSlash(data.pathname) || '/'),
|
||||
].join('/');
|
||||
|
||||
return NextResponse.rewrite(new URL('/' + route, request.url), {
|
||||
return NextResponse.rewrite(new URL(`/${route}`, request.url), {
|
||||
headers: requestHeaders,
|
||||
});
|
||||
}
|
||||
@@ -102,7 +101,7 @@ function extractURL(request: NextRequest): URLWithMode | null {
|
||||
/**
|
||||
* Evaluate if a request is dynamic or static.
|
||||
*/
|
||||
function getDynamicHeaders(request: NextRequest): null | Record<string, string> {
|
||||
function getDynamicHeaders(_request: NextRequest): null | Record<string, string> {
|
||||
// TODO:
|
||||
// - check token in query string
|
||||
// - check token in cookies
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
{
|
||||
"extends": "next/core-web-vitals",
|
||||
"plugins": ["import"],
|
||||
"rules": {
|
||||
"import/order": [
|
||||
"error",
|
||||
{
|
||||
"groups": ["builtin", "external", ["internal", "parent", "sibling", "index"]],
|
||||
"newlines-between": "always",
|
||||
"distinctGroup": true,
|
||||
"pathGroups": [
|
||||
{
|
||||
"pattern": "@/**",
|
||||
"group": "external",
|
||||
"position": "after"
|
||||
},
|
||||
{
|
||||
"pattern": "@gitbook/**",
|
||||
"group": "external",
|
||||
"position": "after"
|
||||
}
|
||||
],
|
||||
"alphabetize": {
|
||||
"order": "asc",
|
||||
"caseInsensitive": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"@next/next/no-img-element": ["off"]
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { runTestCases, TestsCase, waitForCookiesDialog } from './util';
|
||||
import { type TestsCase, runTestCases } from './util';
|
||||
|
||||
/** A list of test cases to run on the customers' docs sites. */
|
||||
const testCases: TestsCase[] = [
|
||||
|
||||
@@ -9,12 +9,13 @@ import { expect } from '@playwright/test';
|
||||
import jwt from 'jsonwebtoken';
|
||||
|
||||
import {
|
||||
VISITOR_TOKEN_COOKIE,
|
||||
getVisitorAuthCookieName,
|
||||
getVisitorAuthCookieValue,
|
||||
VISITOR_TOKEN_COOKIE,
|
||||
} from '@/lib/visitor-token';
|
||||
|
||||
import {
|
||||
type TestsCase,
|
||||
allDeprecatedThemePresets,
|
||||
allLocales,
|
||||
allSidebarBackgroundStyles,
|
||||
@@ -24,7 +25,6 @@ import {
|
||||
getCustomizationURL,
|
||||
headerLinks,
|
||||
runTestCases,
|
||||
TestsCase,
|
||||
waitForCookiesDialog,
|
||||
} from './util';
|
||||
|
||||
@@ -43,7 +43,7 @@ const testCases: TestsCase[] = [
|
||||
url: '',
|
||||
run: async (page) => {
|
||||
await expect(page.locator('[data-testid="space-dropdown-button"]')).toHaveCount(
|
||||
0,
|
||||
0
|
||||
);
|
||||
},
|
||||
},
|
||||
@@ -114,20 +114,20 @@ const testCases: TestsCase[] = [
|
||||
await spaceDrowpdown.click();
|
||||
|
||||
const variantSelectionDropdown = page.locator(
|
||||
'css=[data-testid="space-dropdown-button"] + div',
|
||||
'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();
|
||||
},
|
||||
},
|
||||
@@ -156,7 +156,7 @@ const testCases: TestsCase[] = [
|
||||
|
||||
// It should keep the current page path, i.e "reference/api-reference/pets" when navigating to the new variant
|
||||
await page.waitForURL(
|
||||
'https://gitbook-open-e2e-sites.gitbook.io/api-multi-versions/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'
|
||||
);
|
||||
},
|
||||
},
|
||||
@@ -179,7 +179,7 @@ const testCases: TestsCase[] = [
|
||||
|
||||
// It should keep the current page path, i.e "reference/api-reference/pets" when navigating to the new variant
|
||||
await page.waitForURL(
|
||||
'https://gitbook-open-e2e-sites.gitbook.io/api-multi-versions-share-links/8tNo6MeXg7CkFMzSSz81/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'
|
||||
);
|
||||
},
|
||||
},
|
||||
@@ -195,7 +195,7 @@ const testCases: TestsCase[] = [
|
||||
privateKey,
|
||||
{
|
||||
expiresIn: '24h',
|
||||
},
|
||||
}
|
||||
);
|
||||
return `api-multi-versions-va/reference/api-reference/pets?jwt_token=${token}`;
|
||||
})(),
|
||||
@@ -214,7 +214,7 @@ const testCases: TestsCase[] = [
|
||||
|
||||
// It should keep the current page path, i.e "reference/api-reference/pets" when navigating to the new variant
|
||||
await page.waitForURL(
|
||||
'https://gitbook-open-e2e-sites.gitbook.io/api-multi-versions-va/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'
|
||||
);
|
||||
},
|
||||
},
|
||||
@@ -331,7 +331,7 @@ const testCases: TestsCase[] = [
|
||||
for (const p of document.querySelectorAll('p')) {
|
||||
if (
|
||||
p.textContent?.includes(
|
||||
'This image has intrinsic 400px width, but renders as 300px:',
|
||||
'This image has intrinsic 400px width, but renders as 300px:'
|
||||
)
|
||||
) {
|
||||
p.style.color = 'transparent';
|
||||
@@ -413,7 +413,7 @@ const testCases: TestsCase[] = [
|
||||
await page.waitForFunction(() => {
|
||||
const fonts = Array.from(document.fonts.values());
|
||||
const mjxFonts = fonts.filter(
|
||||
(font) => font.family === 'MJXZERO' || font.family === 'MJXTEX',
|
||||
(font) => font.family === 'MJXZERO' || font.family === 'MJXTEX'
|
||||
);
|
||||
return (
|
||||
mjxFonts.length === 2 &&
|
||||
@@ -505,17 +505,15 @@ const testCases: TestsCase[] = [
|
||||
},
|
||||
{
|
||||
name: `With duotone icons - Theme mode ${themeMode}`,
|
||||
url:
|
||||
'page-options/page-with-icon' +
|
||||
getCustomizationURL({
|
||||
styling: {
|
||||
icons: CustomizationIconsStyle.Duotone,
|
||||
},
|
||||
themes: {
|
||||
default: themeMode,
|
||||
toggeable: false,
|
||||
},
|
||||
}),
|
||||
url: `page-options/page-with-icon${getCustomizationURL({
|
||||
styling: {
|
||||
icons: CustomizationIconsStyle.Duotone,
|
||||
},
|
||||
themes: {
|
||||
default: themeMode,
|
||||
toggeable: false,
|
||||
},
|
||||
})}`,
|
||||
run: waitForCookiesDialog,
|
||||
},
|
||||
{
|
||||
@@ -643,7 +641,7 @@ const testCases: TestsCase[] = [
|
||||
const sharedSpaceLink = page.locator('a.underline');
|
||||
await sharedSpaceLink.click();
|
||||
await expect(
|
||||
page.getByRole('heading', { level: 1, name: 'shared' }),
|
||||
page.getByRole('heading', { level: 1, name: 'shared' })
|
||||
).toBeVisible();
|
||||
const url = page.url();
|
||||
expect(url.includes('shared-space-uno')).toBeTruthy(); // same uno site
|
||||
@@ -663,7 +661,7 @@ const testCases: TestsCase[] = [
|
||||
run: async (page) => {
|
||||
await page.locator('a.underline').click();
|
||||
await expect(
|
||||
page.getByRole('heading', { level: 1, name: 'shared' }),
|
||||
page.getByRole('heading', { level: 1, name: 'shared' })
|
||||
).toBeVisible();
|
||||
const url = page.url();
|
||||
expect(url.includes('shared-space-dos')).toBeTruthy(); // same dos site
|
||||
@@ -700,7 +698,7 @@ const testCases: TestsCase[] = [
|
||||
url: 'invalid/',
|
||||
run: async (page) => {
|
||||
await expect(
|
||||
page.getByText('Authentication missing to access this content'),
|
||||
page.getByText('Authentication missing to access this content')
|
||||
).toBeVisible();
|
||||
},
|
||||
screenshot: false,
|
||||
@@ -709,7 +707,7 @@ const testCases: TestsCase[] = [
|
||||
},
|
||||
{
|
||||
name: 'Visitor Auth - Space',
|
||||
baseUrl: `https://gitbook.gitbook.io/gbo-va-space/`,
|
||||
baseUrl: 'https://gitbook.gitbook.io/gbo-va-space/',
|
||||
tests: [
|
||||
{
|
||||
name: 'First',
|
||||
@@ -722,13 +720,13 @@ const testCases: TestsCase[] = [
|
||||
privateKey,
|
||||
{
|
||||
expiresIn: '24h',
|
||||
},
|
||||
}
|
||||
);
|
||||
return `first?jwt_token=${token}`;
|
||||
})(),
|
||||
run: async (page) => {
|
||||
await expect(
|
||||
page.getByRole('heading', { level: 1, name: 'first' }),
|
||||
page.getByRole('heading', { level: 1, name: 'first' })
|
||||
).toBeVisible();
|
||||
},
|
||||
screenshot: false,
|
||||
@@ -744,13 +742,13 @@ const testCases: TestsCase[] = [
|
||||
privateKey,
|
||||
{
|
||||
expiresIn: '24h',
|
||||
},
|
||||
}
|
||||
);
|
||||
return `second?jwt_token=${token}`;
|
||||
})(),
|
||||
run: async (page) => {
|
||||
await expect(
|
||||
page.getByRole('heading', { level: 1, name: 'second' }),
|
||||
page.getByRole('heading', { level: 1, name: 'second' })
|
||||
).toBeVisible();
|
||||
},
|
||||
screenshot: false,
|
||||
@@ -759,7 +757,7 @@ const testCases: TestsCase[] = [
|
||||
},
|
||||
{
|
||||
name: 'Visitor Auth - Collection',
|
||||
baseUrl: `https://gitbook.gitbook.io/gbo-va-collection/`,
|
||||
baseUrl: 'https://gitbook.gitbook.io/gbo-va-collection/',
|
||||
tests: [
|
||||
{
|
||||
name: 'Root',
|
||||
@@ -772,7 +770,7 @@ const testCases: TestsCase[] = [
|
||||
privateKey,
|
||||
{
|
||||
expiresIn: '24h',
|
||||
},
|
||||
}
|
||||
);
|
||||
return `?jwt_token=${token}`;
|
||||
})(),
|
||||
@@ -789,7 +787,7 @@ const testCases: TestsCase[] = [
|
||||
privateKey,
|
||||
{
|
||||
expiresIn: '24h',
|
||||
},
|
||||
}
|
||||
);
|
||||
return `spacea?jwt_token=${token}`;
|
||||
})(),
|
||||
@@ -806,7 +804,7 @@ const testCases: TestsCase[] = [
|
||||
privateKey,
|
||||
{
|
||||
expiresIn: '24h',
|
||||
},
|
||||
}
|
||||
);
|
||||
return `spaceb?jwt_token=${token}`;
|
||||
})(),
|
||||
@@ -823,7 +821,7 @@ const testCases: TestsCase[] = [
|
||||
privateKey,
|
||||
{
|
||||
expiresIn: '24h',
|
||||
},
|
||||
}
|
||||
);
|
||||
return `spacec?jwt_token=${token}`;
|
||||
})(),
|
||||
@@ -833,7 +831,7 @@ const testCases: TestsCase[] = [
|
||||
},
|
||||
{
|
||||
name: 'Visitor Auth - Space (custom domain)',
|
||||
baseUrl: `https://test.gitbook.community/`,
|
||||
baseUrl: 'https://test.gitbook.community/',
|
||||
tests: [
|
||||
{
|
||||
name: 'Root',
|
||||
@@ -846,7 +844,7 @@ const testCases: TestsCase[] = [
|
||||
privateKey,
|
||||
{
|
||||
expiresIn: '24h',
|
||||
},
|
||||
}
|
||||
);
|
||||
return `?jwt_token=${token}`;
|
||||
})(),
|
||||
@@ -863,13 +861,13 @@ const testCases: TestsCase[] = [
|
||||
privateKey,
|
||||
{
|
||||
expiresIn: '24h',
|
||||
},
|
||||
}
|
||||
);
|
||||
return `first?jwt_token=${token}`;
|
||||
})(),
|
||||
run: async (page) => {
|
||||
await expect(
|
||||
page.getByRole('heading', { level: 1, name: 'first' }),
|
||||
page.getByRole('heading', { level: 1, name: 'first' })
|
||||
).toBeVisible();
|
||||
},
|
||||
screenshot: false,
|
||||
@@ -885,7 +883,7 @@ const testCases: TestsCase[] = [
|
||||
privateKey,
|
||||
{
|
||||
expiresIn: '24h',
|
||||
},
|
||||
}
|
||||
);
|
||||
return `custom-page?jwt_token=${token}`;
|
||||
})(),
|
||||
@@ -902,7 +900,7 @@ const testCases: TestsCase[] = [
|
||||
privateKey,
|
||||
{
|
||||
expiresIn: '24h',
|
||||
},
|
||||
}
|
||||
);
|
||||
return `custom-page/inner-page?jwt_token=${token}`;
|
||||
})(),
|
||||
@@ -912,7 +910,7 @@ const testCases: TestsCase[] = [
|
||||
},
|
||||
{
|
||||
name: 'Visitor Auth - Site (redirects to fallback/auth URL)',
|
||||
baseUrl: `https://gitbook-open-e2e-sites.gitbook.io/va-site-redirects-fallback/`,
|
||||
baseUrl: 'https://gitbook-open-e2e-sites.gitbook.io/va-site-redirects-fallback/',
|
||||
tests: [
|
||||
{
|
||||
name: 'Redirect to fallback on invalid token pulled from cookie',
|
||||
@@ -927,7 +925,7 @@ const testCases: TestsCase[] = [
|
||||
'invalidKey',
|
||||
{
|
||||
expiresIn: '24h',
|
||||
},
|
||||
}
|
||||
);
|
||||
return [
|
||||
{
|
||||
@@ -952,13 +950,13 @@ const testCases: TestsCase[] = [
|
||||
'invalidKey',
|
||||
{
|
||||
expiresIn: '24h',
|
||||
},
|
||||
}
|
||||
);
|
||||
return `?jwt_token=${token}`;
|
||||
})(),
|
||||
run: async (page) => {
|
||||
await expect(page.locator('pre')).toContainText(
|
||||
'Error while validating the JWT token. Reason: The token signature is invalid.',
|
||||
'Error while validating the JWT token. Reason: The token signature is invalid.'
|
||||
);
|
||||
},
|
||||
},
|
||||
@@ -985,7 +983,7 @@ const testCases: TestsCase[] = [
|
||||
baseUrl: 'https://gitbook.gitbook.io/test-gitbook-open/',
|
||||
tests: [
|
||||
{
|
||||
name: `Index by default`,
|
||||
name: 'Index by default',
|
||||
url: '?x-gitbook-search-indexation=true',
|
||||
screenshot: false,
|
||||
run: async (page) => {
|
||||
@@ -1033,7 +1031,7 @@ const testCases: TestsCase[] = [
|
||||
},
|
||||
{
|
||||
name: 'Adaptive Content - VA',
|
||||
baseUrl: `https://gitbook-open-e2e-sites.gitbook.io/adaptive-content-va/`,
|
||||
baseUrl: 'https://gitbook-open-e2e-sites.gitbook.io/adaptive-content-va/',
|
||||
tests: [
|
||||
{
|
||||
name: 'isAlphaUser',
|
||||
@@ -1047,7 +1045,7 @@ const testCases: TestsCase[] = [
|
||||
privateKey,
|
||||
{
|
||||
expiresIn: '24h',
|
||||
},
|
||||
}
|
||||
);
|
||||
return `?jwt_token=${token}`;
|
||||
})(),
|
||||
@@ -1074,7 +1072,7 @@ const testCases: TestsCase[] = [
|
||||
privateKey,
|
||||
{
|
||||
expiresIn: '24h',
|
||||
},
|
||||
}
|
||||
);
|
||||
return `?jwt_token=${token}`;
|
||||
})(),
|
||||
@@ -1102,7 +1100,7 @@ const testCases: TestsCase[] = [
|
||||
privateKey,
|
||||
{
|
||||
expiresIn: '24h',
|
||||
},
|
||||
}
|
||||
);
|
||||
return `?jwt_token=${token}`;
|
||||
})(),
|
||||
@@ -1121,7 +1119,7 @@ const testCases: TestsCase[] = [
|
||||
},
|
||||
{
|
||||
name: 'Adaptive Content - Public',
|
||||
baseUrl: `https://gitbook-open-e2e-sites.gitbook.io/adaptive-content-public/`,
|
||||
baseUrl: 'https://gitbook-open-e2e-sites.gitbook.io/adaptive-content-public/',
|
||||
tests: [
|
||||
{
|
||||
name: 'No custom cookie',
|
||||
@@ -1154,7 +1152,7 @@ const testCases: TestsCase[] = [
|
||||
privateKey,
|
||||
{
|
||||
expiresIn: '24h',
|
||||
},
|
||||
}
|
||||
);
|
||||
return [
|
||||
{
|
||||
@@ -1193,7 +1191,7 @@ const testCases: TestsCase[] = [
|
||||
privateKey,
|
||||
{
|
||||
expiresIn: '24h',
|
||||
},
|
||||
}
|
||||
);
|
||||
return [
|
||||
{
|
||||
@@ -1233,7 +1231,7 @@ const testCases: TestsCase[] = [
|
||||
privateKey,
|
||||
{
|
||||
expiresIn: '24h',
|
||||
},
|
||||
}
|
||||
);
|
||||
return [
|
||||
{
|
||||
@@ -1274,25 +1272,21 @@ const testCases: TestsCase[] = [
|
||||
},
|
||||
{
|
||||
name: 'Table with straight corners',
|
||||
url:
|
||||
'blocks/tables' +
|
||||
getCustomizationURL({
|
||||
styling: {
|
||||
corners: CustomizationCorners.Straight,
|
||||
},
|
||||
}),
|
||||
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' } },
|
||||
},
|
||||
}),
|
||||
url: `blocks/tables${getCustomizationURL({
|
||||
styling: {
|
||||
tint: { color: { light: '#346DDB', dark: '#346DDB' } },
|
||||
},
|
||||
})}`,
|
||||
run: waitForCookiesDialog,
|
||||
fullPage: true,
|
||||
},
|
||||
@@ -1300,46 +1294,40 @@ const testCases: TestsCase[] = [
|
||||
...allThemeModes.flatMap((theme) => [
|
||||
{
|
||||
name: `Table in ${theme} mode`,
|
||||
url:
|
||||
'blocks/tables' +
|
||||
getCustomizationURL({
|
||||
themes: {
|
||||
default: theme,
|
||||
toggeable: false,
|
||||
},
|
||||
}),
|
||||
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,
|
||||
},
|
||||
}),
|
||||
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,
|
||||
},
|
||||
}),
|
||||
url: `blocks/tables${getCustomizationURL({
|
||||
styling: {
|
||||
tint: { color: { light: '#346DDB', dark: '#346DDB' } },
|
||||
},
|
||||
themes: {
|
||||
default: theme,
|
||||
toggeable: false,
|
||||
},
|
||||
})}`,
|
||||
run: waitForCookiesDialog,
|
||||
fullPage: true,
|
||||
},
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
CustomizationBackground,
|
||||
CustomizationCorners,
|
||||
CustomizationFont,
|
||||
CustomizationHeaderItem,
|
||||
type CustomizationHeaderItem,
|
||||
CustomizationHeaderPreset,
|
||||
CustomizationIconsStyle,
|
||||
CustomizationLinksStyle,
|
||||
@@ -11,14 +11,14 @@ import {
|
||||
CustomizationSidebarBackgroundStyle,
|
||||
CustomizationSidebarListStyle,
|
||||
CustomizationTheme,
|
||||
CustomizationThemedColor,
|
||||
CustomizationThemeMode,
|
||||
SiteCustomizationSettings,
|
||||
type CustomizationThemedColor,
|
||||
type SiteCustomizationSettings,
|
||||
} from '@gitbook/api';
|
||||
import { BrowserContext, expect, Page, test } from '@playwright/test';
|
||||
import { type BrowserContext, type Page, expect, test } from '@playwright/test';
|
||||
import deepMerge from 'deepmerge';
|
||||
import rison from 'rison';
|
||||
import { DeepPartial } from 'ts-essentials';
|
||||
import type { DeepPartial } from 'ts-essentials';
|
||||
|
||||
import { getContentTestURL } from '../tests/utils';
|
||||
|
||||
@@ -151,7 +151,7 @@ export function runTestCases(testCases: TestsCase[]) {
|
||||
...cookie,
|
||||
domain: new URL(url).host,
|
||||
path: '/',
|
||||
})),
|
||||
}))
|
||||
);
|
||||
}
|
||||
await page.goto(url);
|
||||
@@ -296,7 +296,7 @@ async function waitForIcons(page: Page) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const img = new Image();
|
||||
img.onload = () => resolve(img);
|
||||
img.onerror = (error) => reject(new Error(`Failed to load image: ${src}`));
|
||||
img.onerror = (_error) => reject(new Error(`Failed to load image: ${src}`));
|
||||
img.src = src;
|
||||
});
|
||||
}
|
||||
@@ -312,7 +312,7 @@ async function waitForIcons(page: Page) {
|
||||
throw new Error('No mask-image');
|
||||
}
|
||||
await loadImage(url);
|
||||
}),
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -327,7 +327,7 @@ async function waitForTOCScrolling(page: Page) {
|
||||
await expect(toc).toBeVisible();
|
||||
await page.evaluate(() => {
|
||||
const tocScrollContainer = document.querySelector(
|
||||
'[data-testid="table-of-contents"] [data-testid="toc-scroll-container"]',
|
||||
'[data-testid="table-of-contents"] [data-testid="toc-scroll-container"]'
|
||||
);
|
||||
if (!tocScrollContainer) {
|
||||
throw new Error('TOC scroll container not found');
|
||||
|
||||
@@ -34,7 +34,7 @@ module.exports = withSentryConfig(
|
||||
__RRWEB_EXCLUDE_IFRAME__: true,
|
||||
__RRWEB_EXCLUDE_SHADOW_DOM__: true,
|
||||
__SENTRY_EXCLUDE_REPLAY_WORKER__: true,
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -79,5 +79,5 @@ module.exports = withSentryConfig(
|
||||
// Routes browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers (increases server load)
|
||||
tunnelRoute: '/~gitbook/monitoring',
|
||||
disableLogger: true,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
"build": "next build",
|
||||
"build:cloudflare": "next-on-pages --custom-entrypoint=./src/cloudflare-entrypoint.ts",
|
||||
"start": "next start",
|
||||
"lint": "next lint",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"e2e": "playwright test e2e/internal.spec.ts",
|
||||
"e2e-customers": "playwright test e2e/customers.spec.ts",
|
||||
@@ -86,9 +85,6 @@
|
||||
"autoprefixer": "^10",
|
||||
"deepmerge": "^4.3.1",
|
||||
"env-cmd": "^10.1.0",
|
||||
"eslint": "^8",
|
||||
"eslint-config-next": "^14.2.5",
|
||||
"eslint-plugin-import": "^2.29.1",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"postcss": "^8",
|
||||
"psi": "^4.1.0",
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import {
|
||||
resizeImage,
|
||||
checkIsSizableImageURL,
|
||||
CloudflareImageOptions,
|
||||
CURRENT_SIGNATURE_VERSION,
|
||||
type CloudflareImageOptions,
|
||||
type SignatureVersion,
|
||||
checkIsSizableImageURL,
|
||||
isSignatureVersion,
|
||||
SignatureVersion,
|
||||
verifyImageSignature,
|
||||
parseImageAPIURL,
|
||||
resizeImage,
|
||||
verifyImageSignature,
|
||||
} from '@v2/lib/images';
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { type NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
import { getHost } from '@/lib/links';
|
||||
|
||||
@@ -20,7 +20,7 @@ export const runtime = 'edge';
|
||||
* Fetch and resize an image.
|
||||
*/
|
||||
export async function GET(request: NextRequest) {
|
||||
let urlParam = request.nextUrl.searchParams.get('url');
|
||||
const urlParam = request.nextUrl.searchParams.get('url');
|
||||
const signature = request.nextUrl.searchParams.get('sign');
|
||||
|
||||
if (!urlParam || !signature) {
|
||||
@@ -29,7 +29,7 @@ export async function GET(request: NextRequest) {
|
||||
|
||||
const signatureVersion = parseSignatureVersion(request.nextUrl.searchParams.get('sv'));
|
||||
if (!signatureVersion) {
|
||||
return new Response(`Invalid sv parameter`, { status: 400 });
|
||||
return new Response('Invalid sv parameter', { status: 400 });
|
||||
}
|
||||
|
||||
const url = parseImageAPIURL(urlParam);
|
||||
@@ -47,7 +47,7 @@ export async function GET(request: NextRequest) {
|
||||
url,
|
||||
host: await getHost(),
|
||||
},
|
||||
{ signature, version: signatureVersion },
|
||||
{ signature, version: signatureVersion }
|
||||
);
|
||||
if (!verified) {
|
||||
return new Response(`Invalid signature "${signature ?? ''}" for "${url}"`, { status: 400 });
|
||||
@@ -99,7 +99,7 @@ export async function GET(request: NextRequest) {
|
||||
}
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
// Redirect to the original image if resizing fails
|
||||
return NextResponse.redirect(url, 302);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { type NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
import { revalidateTags } from '@/lib/cache';
|
||||
|
||||
@@ -21,7 +21,7 @@ export async function POST(req: NextRequest) {
|
||||
{
|
||||
error: 'tags must be an array',
|
||||
},
|
||||
{ status: 400 },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import { captureException } from '@sentry/nextjs';
|
||||
import Error from 'next/error';
|
||||
import NextError from 'next/error';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
export default function GlobalError({ error }: { error: Error }) {
|
||||
@@ -10,9 +10,9 @@ export default function GlobalError({ error }: { error: Error }) {
|
||||
}, [error]);
|
||||
|
||||
return (
|
||||
<html>
|
||||
<html lang="en">
|
||||
<body>
|
||||
<Error statusCode={undefined as any} />
|
||||
<NextError statusCode={undefined as any} />
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { Metadata, Viewport } from 'next';
|
||||
import React from 'react';
|
||||
import type { Metadata, Viewport } from 'next';
|
||||
|
||||
import {
|
||||
type PagePathParams,
|
||||
SitePage,
|
||||
generateSitePageMetadata,
|
||||
generateSitePageViewport,
|
||||
SitePage,
|
||||
PagePathParams,
|
||||
} from '@/components/SitePage';
|
||||
import { getSiteContentPointer } from '@/lib/pointer';
|
||||
import { fetchV1ContextForSitePointer } from '@/lib/v1';
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { getThemeFromMiddleware } from '@v2/lib/middleware';
|
||||
import { Metadata, Viewport } from 'next';
|
||||
import React from 'react';
|
||||
import type { Metadata, Viewport } from 'next';
|
||||
import type React from 'react';
|
||||
|
||||
import {
|
||||
SiteLayout,
|
||||
generateSiteLayoutMetadata,
|
||||
generateSiteLayoutViewport,
|
||||
SiteLayout,
|
||||
} from '@/components/SiteLayout';
|
||||
import { getContentSecurityPolicyNonce } from '@/lib/csp';
|
||||
import { getSiteContentPointer } from '@/lib/pointer';
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { SiteSection, SiteSpace, SiteStructure } from '@gitbook/api';
|
||||
import type { SiteSection, SiteSpace, SiteStructure } from '@gitbook/api';
|
||||
import assertNever from 'assert-never';
|
||||
import { ListItem, Paragraph, Root, RootContent } from 'mdast';
|
||||
import type { ListItem, Paragraph, Root, RootContent } from 'mdast';
|
||||
import { toMarkdown } from 'mdast-util-to-markdown';
|
||||
import { NextRequest } from 'next/server';
|
||||
import type { NextRequest } from 'next/server';
|
||||
|
||||
import { getPublishedContentSite, getRevisionPages } from '@/lib/api';
|
||||
import { getAbsoluteHref } from '@/lib/links';
|
||||
@@ -17,7 +17,7 @@ export const runtime = 'edge';
|
||||
/**
|
||||
* Generate a llms.txt file for the site.
|
||||
*/
|
||||
export async function GET(req: NextRequest) {
|
||||
export async function GET(_req: NextRequest) {
|
||||
const pointer = await getSiteContentPointer();
|
||||
|
||||
const { structure: siteStructure, site } = await getPublishedContentSite({
|
||||
@@ -50,7 +50,7 @@ export async function GET(req: NextRequest) {
|
||||
headers: {
|
||||
'Content-Type': 'text/plain; charset=utf-8',
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ async function getNodesFromSections(siteSections: SiteSection[]): Promise<RootCo
|
||||
},
|
||||
...siteSpaceNodes,
|
||||
];
|
||||
}),
|
||||
})
|
||||
);
|
||||
return all.flat();
|
||||
}
|
||||
@@ -100,7 +100,7 @@ async function getNodesFromSiteSpaces(
|
||||
* Includes a heading for each site space.
|
||||
*/
|
||||
heading?: boolean;
|
||||
},
|
||||
}
|
||||
): Promise<RootContent[]> {
|
||||
const all = await Promise.all(
|
||||
siteSpaces.map(async (siteSpace): Promise<RootContent[]> => {
|
||||
@@ -116,7 +116,7 @@ async function getNodesFromSiteSpaces(
|
||||
pages.map(async ({ page }): Promise<ListItem> => {
|
||||
const url = await getAbsoluteHref(
|
||||
joinPath(new URL(siteSpaceUrl).pathname, getPagePath(rootPages, page)),
|
||||
true,
|
||||
true
|
||||
);
|
||||
const children: Paragraph['children'] = [
|
||||
{
|
||||
@@ -132,7 +132,7 @@ async function getNodesFromSiteSpaces(
|
||||
type: 'listItem',
|
||||
children: [{ type: 'paragraph', children }],
|
||||
};
|
||||
}),
|
||||
})
|
||||
);
|
||||
const nodes: RootContent[] = [];
|
||||
if (options.heading) {
|
||||
@@ -148,7 +148,7 @@ async function getNodesFromSiteSpaces(
|
||||
children: listChildren,
|
||||
});
|
||||
return nodes;
|
||||
}),
|
||||
})
|
||||
);
|
||||
return all.flat();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { NextRequest } from 'next/server';
|
||||
import type { NextRequest } from 'next/server';
|
||||
|
||||
import { getSite } from '@/lib/api';
|
||||
import { getAbsoluteHref } from '@/lib/links';
|
||||
@@ -10,16 +10,16 @@ export const runtime = 'edge';
|
||||
/**
|
||||
* Generate a robots.txt for the current space.
|
||||
*/
|
||||
export async function GET(req: NextRequest) {
|
||||
export async function GET(_req: NextRequest) {
|
||||
const pointer = await getSiteContentPointer();
|
||||
const site = await getSite(pointer.organizationId, pointer.siteId);
|
||||
|
||||
const lines = [
|
||||
`User-agent: *`,
|
||||
'User-agent: *',
|
||||
'Disallow: /~gitbook/',
|
||||
...((await isSiteIndexable(site))
|
||||
? [`Allow: /`, `Sitemap: ${await getAbsoluteHref(`/sitemap.xml`, true)}`]
|
||||
: [`Disallow: /`]),
|
||||
? ['Allow: /', `Sitemap: ${await getAbsoluteHref('/sitemap.xml', true)}`]
|
||||
: ['Disallow: /']),
|
||||
];
|
||||
const content = lines.join('\n');
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ export async function GET() {
|
||||
const urls = await Promise.all(
|
||||
pages.map(async ({ page, depth }) => {
|
||||
// Decay priority with depth
|
||||
const priority = Math.pow(2, -0.25 * depth);
|
||||
const priority = 2 ** (-0.25 * depth);
|
||||
// Normalize to keep 2 decimals
|
||||
const normalizedPriority = Math.floor(100 * priority) / 100;
|
||||
const lastModified = page.updatedAt || page.createdAt;
|
||||
@@ -39,7 +39,7 @@ export async function GET() {
|
||||
}
|
||||
|
||||
return { url };
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
const xml = jsontoxml(
|
||||
@@ -55,7 +55,7 @@ export async function GET() {
|
||||
{
|
||||
xmlHeader: true,
|
||||
prettyPrint: true,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
return new Response(xml, {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { SiteSection, SiteSpace, SiteStructure } from '@gitbook/api';
|
||||
import type { SiteSection, SiteSpace, SiteStructure } from '@gitbook/api';
|
||||
import assertNever from 'assert-never';
|
||||
import jsontoxml from 'jsontoxml';
|
||||
|
||||
@@ -46,7 +46,7 @@ export async function GET() {
|
||||
{
|
||||
xmlHeader: true,
|
||||
prettyPrint: true,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
return new Response(xml, {
|
||||
@@ -75,7 +75,7 @@ async function getUrlsFromSiteStructure(siteStructure: SiteStructure): Promise<s
|
||||
*/
|
||||
async function getUrlsFromSiteSections(siteSections: SiteSection[]): Promise<string[]> {
|
||||
const urls = await Promise.all(
|
||||
siteSections.map(async (siteSection) => getUrlsFromSiteSpaces(siteSection.siteSpaces), []),
|
||||
siteSections.map(async (siteSection) => getUrlsFromSiteSpaces(siteSection.siteSpaces), [])
|
||||
);
|
||||
return urls.flat();
|
||||
}
|
||||
@@ -92,7 +92,7 @@ async function getUrlsFromSiteSpaces(siteSpaces: SiteSpace[]): Promise<string[]>
|
||||
const url = new URL(siteSpace.urls.published);
|
||||
url.pathname = joinPath(url.pathname, 'sitemap-pages.xml');
|
||||
return url.toString();
|
||||
}, []),
|
||||
}, [])
|
||||
);
|
||||
return urls.filter(filterOutNullable);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { notFound } from 'next/navigation';
|
||||
import { ImageResponse } from 'next/og';
|
||||
import { NextRequest } from 'next/server';
|
||||
import React from 'react';
|
||||
import type { NextRequest } from 'next/server';
|
||||
|
||||
import { getEmojiForCode } from '@/lib/emojis';
|
||||
import { getSiteContentPointer } from '@/lib/pointer';
|
||||
@@ -40,35 +39,33 @@ export async function GET(req: NextRequest) {
|
||||
const contentTitle = site.title;
|
||||
|
||||
return new ImageResponse(
|
||||
(
|
||||
<div
|
||||
tw={tcls(options.theme === 'light' ? 'bg-white' : 'bg-black', size.boxStyle)}
|
||||
style={{
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
}}
|
||||
<div
|
||||
tw={tcls(options.theme === 'light' ? 'bg-white' : 'bg-black', size.boxStyle)}
|
||||
style={{
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
}}
|
||||
>
|
||||
<h2
|
||||
tw={tcls(
|
||||
size.textSize,
|
||||
'font-bold',
|
||||
'tracking-tight',
|
||||
options.theme === 'light' ? 'text-black' : 'text-white'
|
||||
)}
|
||||
>
|
||||
<h2
|
||||
tw={tcls(
|
||||
size.textSize,
|
||||
'font-bold',
|
||||
'tracking-tight',
|
||||
options.theme === 'light' ? 'text-black' : 'text-white',
|
||||
)}
|
||||
>
|
||||
{'emoji' in customization.favicon
|
||||
? getEmojiForCode(customization.favicon.emoji)
|
||||
: contentTitle.slice(0, 1).toUpperCase()}
|
||||
</h2>
|
||||
</div>
|
||||
),
|
||||
{'emoji' in customization.favicon
|
||||
? getEmojiForCode(customization.favicon.emoji)
|
||||
: contentTitle.slice(0, 1).toUpperCase()}
|
||||
</h2>
|
||||
</div>,
|
||||
{
|
||||
width: size.width,
|
||||
height: size.height,
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+52
-55
@@ -2,10 +2,9 @@ import { CustomizationHeaderPreset } from '@gitbook/api';
|
||||
import { colorContrast } from '@gitbook/colors';
|
||||
import { redirect } from 'next/navigation';
|
||||
import { ImageResponse } from 'next/og';
|
||||
import { NextRequest } from 'next/server';
|
||||
import React from 'react';
|
||||
import type { NextRequest } from 'next/server';
|
||||
|
||||
import { PageIdParams, fetchPageData } from '@/components/SitePage';
|
||||
import { type PageIdParams, fetchPageData } from '@/components/SitePage';
|
||||
import { googleFontsMap } from '@/fonts';
|
||||
import { getAbsoluteHref } from '@/lib/links';
|
||||
import { getSiteContentPointer } from '@/lib/pointer';
|
||||
@@ -55,7 +54,7 @@ async function loadGoogleFont(input: { fontFamily: string; text: string; weight:
|
||||
/**
|
||||
* Render the OpenGraph image for a space.
|
||||
*/
|
||||
export async function GET(req: NextRequest, { params }: { params: Promise<PageIdParams> }) {
|
||||
export async function GET(_req: NextRequest, { params }: { params: Promise<PageIdParams> }) {
|
||||
const pointer = await getSiteContentPointer();
|
||||
const baseContext = await fetchV1ContextForSitePointer(pointer);
|
||||
|
||||
@@ -72,13 +71,13 @@ export async function GET(req: NextRequest, { params }: { params: Promise<PageId
|
||||
const contentTitle = customization.header.logo ? '' : site.title;
|
||||
const pageTitle = page
|
||||
? page.title.length > 64
|
||||
? page.title.slice(0, 64) + '...'
|
||||
? `${page.title.slice(0, 64)}...`
|
||||
: page.title
|
||||
: 'Not found';
|
||||
const pageDescription =
|
||||
page?.description && page?.title.length <= 64
|
||||
? page.description.length > 164
|
||||
? page.description.slice(0, 164) + '...'
|
||||
? `${page.description.slice(0, 164)}...`
|
||||
: page.description
|
||||
: '';
|
||||
|
||||
@@ -122,10 +121,10 @@ export async function GET(req: NextRequest, { params }: { params: Promise<PageId
|
||||
title: customization.header.linkColor?.[theme] || colors.title,
|
||||
body: colorContrast(
|
||||
customization.header.backgroundColor?.[theme] || colors.background,
|
||||
[baseColors.light, baseColors.dark],
|
||||
[baseColors.light, baseColors.dark]
|
||||
),
|
||||
};
|
||||
gridAsset = colors.body == baseColors.light ? gridWhite : gridBlack;
|
||||
gridAsset = colors.body === baseColors.light ? gridWhite : gridBlack;
|
||||
break;
|
||||
|
||||
case CustomizationHeaderPreset.Bold:
|
||||
@@ -144,7 +143,7 @@ export async function GET(req: NextRequest, { params }: { params: Promise<PageId
|
||||
baseColors.dark,
|
||||
]),
|
||||
};
|
||||
gridAsset = colors.body == baseColors.light ? gridWhite : gridBlack;
|
||||
gridAsset = colors.body === baseColors.light ? gridWhite : gridBlack;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -162,71 +161,69 @@ export async function GET(req: NextRequest, { params }: { params: Promise<PageId
|
||||
if ('emoji' in customization.favicon)
|
||||
return (
|
||||
<span tw="text-4xl mr-4">
|
||||
{String.fromCodePoint(parseInt('0x' + customization.favicon.emoji))}
|
||||
{String.fromCodePoint(Number.parseInt(`0x${customization.favicon.emoji}`))}
|
||||
</span>
|
||||
);
|
||||
const src = await getAbsoluteHref(
|
||||
`~gitbook/icon?size=medium&theme=${customization.themes.default}`,
|
||||
true,
|
||||
true
|
||||
);
|
||||
return <img src={src} alt="Icon" width={40} height={40} tw="mr-4" />;
|
||||
})();
|
||||
|
||||
return new ImageResponse(
|
||||
(
|
||||
<div
|
||||
tw={`justify-between p-20 relative w-full h-full flex flex-col bg-[${colors.background}] text-[${colors.body}]`}
|
||||
style={{
|
||||
fontFamily,
|
||||
}}
|
||||
>
|
||||
{/* Gradient */}
|
||||
<div
|
||||
tw={`justify-between p-20 relative w-full h-full flex flex-col bg-[${colors.background}] text-[${colors.body}]`}
|
||||
tw="absolute inset-0"
|
||||
style={{
|
||||
fontFamily,
|
||||
backgroundImage: `radial-gradient(ellipse 100% 100% at top right , ${colors.gradient},${colors.gradient}00)`,
|
||||
opacity: 0.5,
|
||||
}}
|
||||
>
|
||||
{/* Gradient */}
|
||||
<div
|
||||
tw="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="absolute inset-0 w-[100vw] h-[100vh]" src={gridAsset} alt="Grid" />
|
||||
{/* Grid */}
|
||||
<img tw="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="flex">
|
||||
{favicon}
|
||||
<h3 tw="text-4xl my-0 font-bold">{contentTitle}</h3>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Title and description */}
|
||||
<div tw="flex flex-col">
|
||||
<h1
|
||||
tw={`text-8xl my-0 tracking-tight leading-none text-left text-[${colors.title}] font-bold`}
|
||||
>
|
||||
{pageTitle}
|
||||
</h1>
|
||||
{pageDescription ? (
|
||||
<h2 tw="text-4xl mb-0 mt-8 w-[75%] font-normal">{pageDescription}</h2>
|
||||
) : null}
|
||||
{/* Logo */}
|
||||
{customization.header.logo ? (
|
||||
<img
|
||||
alt="Logo"
|
||||
height={60}
|
||||
src={
|
||||
useLightTheme
|
||||
? customization.header.logo.light
|
||||
: customization.header.logo.dark
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<div tw="flex">
|
||||
{favicon}
|
||||
<h3 tw="text-4xl my-0 font-bold">{contentTitle}</h3>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Title and description */}
|
||||
<div tw="flex flex-col">
|
||||
<h1
|
||||
tw={`text-8xl my-0 tracking-tight leading-none text-left text-[${colors.title}] font-bold`}
|
||||
>
|
||||
{pageTitle}
|
||||
</h1>
|
||||
{pageDescription ? (
|
||||
<h2 tw="text-4xl mb-0 mt-8 w-[75%] font-normal">{pageDescription}</h2>
|
||||
) : null}
|
||||
</div>
|
||||
),
|
||||
</div>,
|
||||
{
|
||||
width: 1200,
|
||||
height: 630,
|
||||
fonts: fonts.length ? fonts : undefined,
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ export default function ErrorPage(props: {
|
||||
'flex',
|
||||
'items-center',
|
||||
'justify-center',
|
||||
'p-7',
|
||||
'p-7'
|
||||
)}
|
||||
>
|
||||
<div>
|
||||
|
||||
@@ -50,7 +50,7 @@ export function PageControlButtons(props: {
|
||||
'flex-col',
|
||||
'gap-2',
|
||||
'print:hidden',
|
||||
'z-50',
|
||||
'z-50'
|
||||
)}
|
||||
>
|
||||
{singlePageMode ? null : (
|
||||
@@ -84,7 +84,7 @@ export function PageControlButtons(props: {
|
||||
'items-end',
|
||||
'gap-2',
|
||||
'print:hidden',
|
||||
'z-50',
|
||||
'z-50'
|
||||
)}
|
||||
>
|
||||
{total !== pageIds.length ? (
|
||||
@@ -102,7 +102,7 @@ export function PageControlButtons(props: {
|
||||
'border',
|
||||
'rounded-md',
|
||||
'p-4',
|
||||
'max-w-sm',
|
||||
'max-w-sm'
|
||||
)}
|
||||
>
|
||||
<Icon
|
||||
@@ -140,7 +140,7 @@ export function PageControlButtons(props: {
|
||||
'rounded-full',
|
||||
'shadow-sm',
|
||||
'border-slate-300',
|
||||
'border',
|
||||
'border'
|
||||
)}
|
||||
>
|
||||
{t(language, 'pdf_page_of', activeIndex, pageIds.length)}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import * as React from 'react';
|
||||
|
||||
import { PolymorphicComponentProp } from '@/components/utils/types';
|
||||
import type { PolymorphicComponentProp } from '@/components/utils/types';
|
||||
|
||||
export function PrintButton(props: PolymorphicComponentProp<'button'>) {
|
||||
const { className, children, ...rest } = props;
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
import {
|
||||
CustomizationSettings,
|
||||
Revision,
|
||||
RevisionPageDocument,
|
||||
RevisionPageGroup,
|
||||
type CustomizationSettings,
|
||||
type Revision,
|
||||
type RevisionPageDocument,
|
||||
type RevisionPageGroup,
|
||||
RevisionPageType,
|
||||
SiteCustomizationSettings,
|
||||
type SiteCustomizationSettings,
|
||||
SiteInsightsTrademarkPlacement,
|
||||
Space,
|
||||
type Space,
|
||||
} from '@gitbook/api';
|
||||
import { Icon } from '@gitbook/icons';
|
||||
import { GitBookSpaceContext } from '@v2/lib/context';
|
||||
import type { GitBookSpaceContext } from '@v2/lib/context';
|
||||
import { getPageDocument } from '@v2/lib/data';
|
||||
import { GitBookSpaceLinker } from '@v2/lib/links';
|
||||
import { Metadata } from 'next';
|
||||
import type { GitBookSpaceLinker } from '@v2/lib/links';
|
||||
import type { Metadata } from 'next';
|
||||
import { notFound } from 'next/navigation';
|
||||
import * as React from 'react';
|
||||
|
||||
import { DocumentView } from '@/components/DocumentView';
|
||||
import { TrademarkLink } from '@/components/TableOfContents/Trademark';
|
||||
import { PolymorphicComponentProp } from '@/components/utils/types';
|
||||
import type { PolymorphicComponentProp } from '@/components/utils/types';
|
||||
import { getSpaceLanguage } from '@/intl/server';
|
||||
import { tString } from '@/intl/translate';
|
||||
import { getPagePDFContainerId, getAbsoluteHref } from '@/lib/links';
|
||||
import { getAbsoluteHref, getPagePDFContainerId } from '@/lib/links';
|
||||
import { resolvePageId } from '@/lib/pages';
|
||||
import { tcls } from '@/lib/tailwind';
|
||||
import { PDFSearchParams, getPDFSearchParams } from '@/lib/urls';
|
||||
import { type PDFSearchParams, getPDFSearchParams } from '@/lib/urls';
|
||||
import { defaultCustomizationForSpace } from '@/lib/utils';
|
||||
|
||||
import './pdf.css';
|
||||
import { PageControlButtons } from './PageControlButtons';
|
||||
import { getV1ContextForPDF } from './pointer';
|
||||
import { PrintButton } from './PrintButton';
|
||||
import { getV1ContextForPDF } from './pointer';
|
||||
|
||||
const DEFAULT_LIMIT = 100;
|
||||
|
||||
@@ -57,7 +57,7 @@ export default async function PDFHTMLOutput(props: {
|
||||
|
||||
// Build current PDF URL and preserve all search params
|
||||
let currentPDFUrl = await getAbsoluteHref('~gitbook/pdf', true);
|
||||
currentPDFUrl += '?' + searchParams.toString();
|
||||
currentPDFUrl += `?${searchParams.toString()}`;
|
||||
|
||||
// Fetch the context
|
||||
const baseContext = await getV1ContextForPDF();
|
||||
@@ -69,7 +69,7 @@ export default async function PDFHTMLOutput(props: {
|
||||
// Compute the pages to render
|
||||
const { pages, total } = selectPages(baseContext.pages, pdfParams);
|
||||
const pageIds = pages.map(
|
||||
({ page }) => [page.id, getPagePDFContainerId(page)] as [string, string],
|
||||
({ page }) => [page.id, getPagePDFContainerId(page)] as [string, string]
|
||||
);
|
||||
|
||||
// Build a linker that create anchor links for the pages rendered in the PDF page.
|
||||
@@ -77,15 +77,14 @@ export default async function PDFHTMLOutput(props: {
|
||||
...baseContext.linker,
|
||||
toPathForPage(input) {
|
||||
if (pages.some((p) => p.page.id === input.page.id)) {
|
||||
return '#' + getPagePDFContainerId(input.page, input.anchor);
|
||||
} else {
|
||||
if (input.page.type === RevisionPageType.Group) {
|
||||
return '#';
|
||||
}
|
||||
|
||||
// Use an absolute URL to the page
|
||||
return input.page.urls.app;
|
||||
return `#${getPagePDFContainerId(input.page, input.anchor)}`;
|
||||
}
|
||||
if (input.page.type === RevisionPageType.Group) {
|
||||
return '#';
|
||||
}
|
||||
|
||||
// Use an absolute URL to the page
|
||||
return input.page.urls.app;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -115,7 +114,7 @@ export default async function PDFHTMLOutput(props: {
|
||||
'shadow-sm',
|
||||
'hover:shadow-md',
|
||||
'border-slate-300',
|
||||
'border',
|
||||
'border'
|
||||
)}
|
||||
>
|
||||
<Icon icon="arrow-left" className={tcls('size-6')} />
|
||||
@@ -140,7 +139,7 @@ export default async function PDFHTMLOutput(props: {
|
||||
'shadow-sm',
|
||||
'hover:shadow-md',
|
||||
'border-slate-300',
|
||||
'border',
|
||||
'border'
|
||||
)}
|
||||
>
|
||||
<Icon icon="print" className={tcls('size-6')} />
|
||||
@@ -181,7 +180,7 @@ export default async function PDFHTMLOutput(props: {
|
||||
>
|
||||
<PDFPageDocument page={page} context={context} />
|
||||
</React.Suspense>
|
||||
),
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
@@ -217,7 +216,7 @@ async function PDFPageGroup(props: { space: Space; page: RevisionPageGroup }) {
|
||||
'flex',
|
||||
'items-center',
|
||||
'justify-center',
|
||||
'py-12',
|
||||
'py-12'
|
||||
)}
|
||||
>
|
||||
<h1 className={tcls('text-5xl', 'font-bold')}>{page.title}</h1>
|
||||
@@ -266,7 +265,7 @@ function PrintPage(
|
||||
{
|
||||
isFirst?: boolean;
|
||||
}
|
||||
>,
|
||||
>
|
||||
) {
|
||||
const { children, isFirst, className, ...rest } = props;
|
||||
|
||||
@@ -289,7 +288,7 @@ function PrintPage(
|
||||
'min-h-[29.7cm]',
|
||||
'print:min-h-0',
|
||||
isFirst ? null : 'break-before-page',
|
||||
'break-anywhere',
|
||||
'break-anywhere'
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
@@ -304,11 +303,11 @@ type FlatPageEntry = { page: RevisionPageDocument | RevisionPageGroup; depth: nu
|
||||
*/
|
||||
function selectPages(
|
||||
rootPages: Revision['pages'],
|
||||
params: PDFSearchParams,
|
||||
params: PDFSearchParams
|
||||
): { pages: FlatPageEntry[]; total: number } {
|
||||
const flattenPage = (
|
||||
page: RevisionPageDocument | RevisionPageGroup,
|
||||
depth: number,
|
||||
depth: number
|
||||
): FlatPageEntry[] => {
|
||||
return [
|
||||
{ page, depth },
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { GitBookSiteContext, GitBookSpaceContext } from '@v2/lib/context';
|
||||
import type { GitBookSiteContext, GitBookSpaceContext } from '@v2/lib/context';
|
||||
|
||||
import { SiteContentPointer, SpaceContentPointer } from '@/lib/api';
|
||||
import type { SiteContentPointer, SpaceContentPointer } from '@/lib/api';
|
||||
import { getSiteContentPointer, getSpacePointer } from '@/lib/pointer';
|
||||
import { fetchV1ContextForSitePointer, fetchV1ContextForSpacePointer } from '@/lib/v1';
|
||||
|
||||
@@ -16,7 +16,7 @@ export async function getSiteOrSpacePointerForPDF(): Promise<
|
||||
> {
|
||||
try {
|
||||
return await getSiteContentPointer();
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
return getSpacePointer();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { type NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
type ProxyRequest = {
|
||||
url: string;
|
||||
@@ -67,11 +67,7 @@ export async function POST(req: NextRequest) {
|
||||
// TODO: transform cookie data
|
||||
cookies: response.headers.get('cookies'),
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(
|
||||
'Scalar API Client Proxy Error',
|
||||
(error as Error).stack ?? (error as Error).message ?? error,
|
||||
);
|
||||
} catch (_error) {
|
||||
return NextResponse.json({
|
||||
data: 'Scalar API Client Proxy Error',
|
||||
});
|
||||
|
||||
@@ -10,7 +10,7 @@ import { withMiddlewareHeadersStorage } from './lib/middleware';
|
||||
export default {
|
||||
async fetch(request, env, ctx) {
|
||||
const response = await withMiddlewareHeadersStorage(() =>
|
||||
nextOnPagesHandler.fetch(request, env, ctx),
|
||||
nextOnPagesHandler.fetch(request, env, ctx)
|
||||
);
|
||||
|
||||
return response;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { Icon } from '@gitbook/icons';
|
||||
import { GitBookSiteContext } from '@v2/lib/context';
|
||||
import type { GitBookSiteContext } from '@v2/lib/context';
|
||||
import { headers } from 'next/headers';
|
||||
import React from 'react';
|
||||
|
||||
import { tcls } from '@/lib/tailwind';
|
||||
|
||||
import { DateRelative } from '../primitives';
|
||||
import { RefreshChangeRequestButton } from './RefreshChangeRequestButton';
|
||||
import { Toolbar, ToolbarBody, ToolbarButton, ToolbarButtonGroups } from './Toolbar';
|
||||
import { DateRelative } from '../primitives';
|
||||
|
||||
interface AdminToolbarProps {
|
||||
context: GitBookSiteContext;
|
||||
@@ -34,7 +34,7 @@ function ToolbarLayout(props: { children: React.ReactNode }) {
|
||||
'p-2',
|
||||
'max-w-md',
|
||||
'border-tint-12/1',
|
||||
'backdrop-blur-md',
|
||||
'backdrop-blur-md'
|
||||
)}
|
||||
>
|
||||
<React.Suspense fallback={null}>{props.children}</React.Suspense>
|
||||
@@ -83,7 +83,7 @@ async function ChangeRequestToolbar(props: { context: GitBookSiteContext }) {
|
||||
<p>
|
||||
#{changeRequest.number}: {changeRequest.subject ?? 'No subject'}
|
||||
</p>
|
||||
<p className="text-xs text-tint-2 dark:text-tint-11">
|
||||
<p className="text-tint-2 text-xs dark:text-tint-11">
|
||||
Change request updated <DateRelative value={changeRequest.updatedAt} />
|
||||
</p>
|
||||
</ToolbarBody>
|
||||
@@ -124,7 +124,7 @@ async function RevisionToolbar(props: { context: GitBookSiteContext }) {
|
||||
Revision created <DateRelative value={revision.createdAt} />
|
||||
</p>
|
||||
{revision.git ? (
|
||||
<p className="text-xs text-tint-2 dark:text-tint-11">
|
||||
<p className="text-tint-2 text-xs dark:text-tint-11">
|
||||
{revision.git.message}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import * as React from 'react';
|
||||
import type * as React from 'react';
|
||||
|
||||
import { tcls } from '@/lib/tailwind';
|
||||
|
||||
@@ -20,7 +20,7 @@ export function Toolbar(props: { children: React.ReactNode }) {
|
||||
'rounded-full',
|
||||
'truncate',
|
||||
'text-tint-1',
|
||||
'dark:text-tint-12',
|
||||
'dark:text-tint-12'
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
@@ -56,7 +56,7 @@ export function ToolbarButton(props: React.HTMLProps<HTMLAnchorElement>) {
|
||||
'hover:bg-tint-12',
|
||||
'dark:hover:bg-tint-1',
|
||||
'hover:shadow-lg',
|
||||
'cursor-pointer',
|
||||
'cursor-pointer'
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
'use client';
|
||||
|
||||
import {
|
||||
SiteAds,
|
||||
type SiteAds,
|
||||
SiteAdsStatus,
|
||||
SiteInsightsAdPlacement,
|
||||
SiteInsightsAd,
|
||||
type SiteInsightsAd,
|
||||
type SiteInsightsAdPlacement,
|
||||
SiteInsightsTrademarkPlacement,
|
||||
} from '@gitbook/api';
|
||||
import * as React from 'react';
|
||||
|
||||
import { t, useLanguage } from '@/intl/client';
|
||||
import { ClassValue, tcls } from '@/lib/tailwind';
|
||||
import { type ClassValue, tcls } from '@/lib/tailwind';
|
||||
|
||||
import { renderAd } from './renderAd';
|
||||
import { useHasBeenInViewport } from '../hooks/useHasBeenInViewport';
|
||||
import { useTrackEvent } from '../Insights';
|
||||
import { useHasBeenInViewport } from '../hooks/useHasBeenInViewport';
|
||||
import { Link } from '../primitives';
|
||||
import { renderAd } from './renderAd';
|
||||
|
||||
/**
|
||||
* Zone ID provided by BuySellAds for the preview.
|
||||
@@ -125,7 +125,6 @@ export function Ad({
|
||||
function AdSponsoredLink(props: { spaceId: string }) {
|
||||
const { spaceId } = props;
|
||||
const language = useLanguage();
|
||||
const trackEvent = useTrackEvent();
|
||||
|
||||
const viaUrl = new URL('https://www.gitbook.com');
|
||||
viaUrl.searchParams.set('utm_source', 'content');
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { SiteInsightsAd } from '@gitbook/api';
|
||||
import { GitBookBaseContext } from '@v2/lib/context';
|
||||
import type { SiteInsightsAd } from '@gitbook/api';
|
||||
import type { GitBookBaseContext } from '@v2/lib/context';
|
||||
import { getResizedImageURL } from '@v2/lib/images';
|
||||
import * as React from 'react';
|
||||
|
||||
import { tcls } from '@/lib/tailwind';
|
||||
|
||||
import { AdItem } from './types';
|
||||
import { Link } from '../primitives';
|
||||
import type { AdItem } from './types';
|
||||
|
||||
/**
|
||||
* Classic rendering for an ad.
|
||||
@@ -48,7 +47,7 @@ export async function AdClassicRendering({
|
||||
'text-tint',
|
||||
'hover:text-tint-strong',
|
||||
'rounded-lg',
|
||||
'p-4',
|
||||
'p-4'
|
||||
)}
|
||||
href={ad.statlink}
|
||||
>
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import { SiteInsightsAd } from '@gitbook/api';
|
||||
import type { SiteInsightsAd } from '@gitbook/api';
|
||||
import { hexToRgba } from '@gitbook/colors';
|
||||
import { GitBookBaseContext } from '@v2/lib/context';
|
||||
import type { GitBookBaseContext } from '@v2/lib/context';
|
||||
import { getResizedImageURL } from '@v2/lib/images';
|
||||
import * as React from 'react';
|
||||
|
||||
import { tcls } from '@/lib/tailwind';
|
||||
|
||||
import { AdCover } from './types';
|
||||
import { Link } from '../primitives';
|
||||
import type { AdCover } from './types';
|
||||
|
||||
/**
|
||||
* Cover rendering for an ad.
|
||||
@@ -50,7 +49,7 @@ export async function AdCoverRendering({
|
||||
'rounded-lg',
|
||||
'p-4',
|
||||
'overflow-hidden',
|
||||
'shadow-sm',
|
||||
'shadow-sm'
|
||||
)}
|
||||
style={{ backgroundColor: ad.backgroundColor, color: ad.textColor ?? '#ffffff' }}
|
||||
href={ad.statlink}
|
||||
@@ -62,7 +61,7 @@ export async function AdCoverRendering({
|
||||
'bg-center',
|
||||
'bg-cover',
|
||||
'bg-no-repeat',
|
||||
'z-0',
|
||||
'z-0'
|
||||
)}
|
||||
style={{
|
||||
backgroundImage: `url(${largeImage})`,
|
||||
@@ -71,14 +70,14 @@ export async function AdCoverRendering({
|
||||
|
||||
<div className={tcls('z-[2]')}>
|
||||
<img
|
||||
alt="Large image"
|
||||
alt="Large cover"
|
||||
src={largeImage}
|
||||
className={tcls(
|
||||
'rounded-md',
|
||||
'shadow-md',
|
||||
'max-h-32',
|
||||
'group-hover/ad:max-h-16',
|
||||
'transition-all',
|
||||
'transition-all'
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
@@ -94,7 +93,7 @@ export async function AdCoverRendering({
|
||||
'opacity-0',
|
||||
'group-hover/ad:h-16',
|
||||
'group-hover/ad:opacity-10',
|
||||
'transition-all',
|
||||
'transition-all'
|
||||
)}
|
||||
>
|
||||
{ad.description}
|
||||
@@ -109,7 +108,7 @@ export async function AdCoverRendering({
|
||||
'rounded-md',
|
||||
'bg-white',
|
||||
'py-2',
|
||||
'px-4',
|
||||
'px-4'
|
||||
)}
|
||||
style={{
|
||||
backgroundColor: ad.ctaBackgroundColor,
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import * as React from 'react';
|
||||
|
||||
import { tcls } from '@/lib/tailwind';
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use server';
|
||||
|
||||
import { SiteInsightsAd, SiteInsightsAdPlacement } from '@gitbook/api';
|
||||
import type { SiteInsightsAd, SiteInsightsAdPlacement } from '@gitbook/api';
|
||||
import { headers } from 'next/headers';
|
||||
|
||||
import { getV1BaseContext } from '@/lib/v1';
|
||||
@@ -9,7 +9,7 @@ import { AdClassicRendering } from './AdClassicRendering';
|
||||
import { AdCoverRendering } from './AdCoverRendering';
|
||||
import { AdPixels } from './AdPixels';
|
||||
import adRainbow from './assets/ad-rainbow.svg';
|
||||
import { AdItem, AdsResponse } from './types';
|
||||
import type { AdItem, AdsResponse } from './types';
|
||||
|
||||
type FetchAdOptions = FetchLiveAdOptions | FetchPlaceholderAdOptions;
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ export function CookiesToast(props: { privacyPolicy?: string }) {
|
||||
'left-16',
|
||||
'max-w-md',
|
||||
'text-balance',
|
||||
'sm:left-auto',
|
||||
'sm:left-auto'
|
||||
)}
|
||||
>
|
||||
<p id={describedById} className={tcls('text-sm')}>
|
||||
@@ -66,7 +66,7 @@ export function CookiesToast(props: { privacyPolicy?: string }) {
|
||||
'cookies_prompt',
|
||||
<StyledLink href={privacyPolicy}>
|
||||
{t(language, 'cookies_prompt_privacy')}
|
||||
</StyledLink>,
|
||||
</StyledLink>
|
||||
)}
|
||||
</p>
|
||||
<button
|
||||
@@ -83,7 +83,7 @@ export function CookiesToast(props: { privacyPolicy?: string }) {
|
||||
'justify-center',
|
||||
'items-center',
|
||||
'rounded-sm',
|
||||
'hover:bg-tint-hover',
|
||||
'hover:bg-tint-hover'
|
||||
)}
|
||||
title={tString(language, 'cookies_close')}
|
||||
>
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { DocumentInlineAnnotation } from '@gitbook/api';
|
||||
import type { DocumentInlineAnnotation } from '@gitbook/api';
|
||||
|
||||
import { getNodeFragmentByType } from '@/lib/document';
|
||||
|
||||
import { AnnotationPopover } from './AnnotationPopover';
|
||||
import { Blocks } from '../Blocks';
|
||||
import { InlineProps } from '../Inline';
|
||||
import type { InlineProps } from '../Inline';
|
||||
import { Inlines } from '../Inlines';
|
||||
import { AnnotationPopover } from './AnnotationPopover';
|
||||
|
||||
export function Annotation(props: InlineProps<DocumentInlineAnnotation>) {
|
||||
const { inline, context, document, children } = props;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
'use client';
|
||||
|
||||
import * as Popover from '@radix-ui/react-popover';
|
||||
import React from 'react';
|
||||
import type React from 'react';
|
||||
|
||||
import { useLanguage, tString } from '@/intl/client';
|
||||
import { tString, useLanguage } from '@/intl/client';
|
||||
import { tcls } from '@/lib/tailwind';
|
||||
|
||||
export function AnnotationPopover(props: { children: React.ReactNode; body: React.ReactNode }) {
|
||||
@@ -20,7 +20,7 @@ export function AnnotationPopover(props: { children: React.ReactNode; body: Reac
|
||||
'decoration-dotted',
|
||||
'decoration-1',
|
||||
'underline',
|
||||
'underline-offset-2',
|
||||
'underline-offset-2'
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
@@ -43,7 +43,7 @@ export function AnnotationPopover(props: { children: React.ReactNode; body: Reac
|
||||
'-outline-offset-2',
|
||||
'outline-2',
|
||||
'outline-primary/8',
|
||||
'z-20',
|
||||
'z-20'
|
||||
)}
|
||||
sideOffset={4}
|
||||
>
|
||||
@@ -56,7 +56,7 @@ export function AnnotationPopover(props: { children: React.ReactNode; body: Reac
|
||||
'z-[2]',
|
||||
'fill-tint-3', // Same as bg-tint
|
||||
'stroke-tint-7', // Same as ring-tint
|
||||
'[paint-order:stroke_fill]',
|
||||
'[paint-order:stroke_fill]'
|
||||
)}
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import { DocumentBlock, JSONDocument } from '@gitbook/api';
|
||||
import type { DocumentBlock, JSONDocument } from '@gitbook/api';
|
||||
import React from 'react';
|
||||
|
||||
import {
|
||||
SkeletonParagraph,
|
||||
SkeletonHeading,
|
||||
SkeletonCard,
|
||||
SkeletonHeading,
|
||||
SkeletonImage,
|
||||
SkeletonParagraph,
|
||||
SkeletonSmall,
|
||||
} from '@/components/primitives';
|
||||
import { ClassValue } from '@/lib/tailwind';
|
||||
import type { ClassValue } from '@/lib/tailwind';
|
||||
|
||||
import { BlockContentRef } from './BlockContentRef';
|
||||
import { CodeBlock } from './CodeBlock';
|
||||
import { Divider } from './Divider';
|
||||
import { DocumentContextProps } from './DocumentView';
|
||||
import type { DocumentContextProps } from './DocumentView';
|
||||
import { Drawing } from './Drawing';
|
||||
import { Embed } from './Embed';
|
||||
import { Expandable } from './Expandable';
|
||||
@@ -47,7 +47,7 @@ export interface BlockProps<Block extends DocumentBlock> extends DocumentContext
|
||||
/**
|
||||
* Alternative to `assertNever` that returns `null` instead of throwing an error.
|
||||
*/
|
||||
function nullIfNever(value: never): null {
|
||||
function nullIfNever(_value: never): null {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { DocumentBlockContentRef, SiteInsightsLinkPosition } from '@gitbook/api';
|
||||
import { type DocumentBlockContentRef, SiteInsightsLinkPosition } from '@gitbook/api';
|
||||
|
||||
import { Card } from '@/components/primitives';
|
||||
import { resolveContentRef, ResolvedContentRef } from '@/lib/references';
|
||||
import { type ResolvedContentRef, resolveContentRef } from '@/lib/references';
|
||||
|
||||
import { BlockProps } from './Block';
|
||||
import type { BlockProps } from './Block';
|
||||
|
||||
export async function BlockContentRef(props: BlockProps<DocumentBlockContentRef>) {
|
||||
const { block, context, style } = props;
|
||||
@@ -46,7 +46,7 @@ export async function BlockContentRef(props: BlockProps<DocumentBlockContentRef>
|
||||
}
|
||||
|
||||
async function SpaceRefCard(
|
||||
props: { resolved: ResolvedContentRef } & BlockProps<DocumentBlockContentRef>,
|
||||
props: { resolved: ResolvedContentRef } & BlockProps<DocumentBlockContentRef>
|
||||
) {
|
||||
const { context, style, resolved } = props;
|
||||
const spaceId = context.contentContext?.space.id;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { DocumentBlock, JSONDocument } from '@gitbook/api';
|
||||
import type { DocumentBlock, JSONDocument } from '@gitbook/api';
|
||||
|
||||
import { tcls, ClassValue } from '@/lib/tailwind';
|
||||
import { type ClassValue, tcls } from '@/lib/tailwind';
|
||||
|
||||
import { Block } from './Block';
|
||||
import { DocumentContextProps } from './DocumentView';
|
||||
import type { DocumentContextProps } from './DocumentView';
|
||||
import { isBlockOffscreen } from './utils';
|
||||
|
||||
/**
|
||||
@@ -19,7 +19,7 @@ export function Blocks<TBlock extends DocumentBlock, Tag extends React.ElementTy
|
||||
|
||||
/** Props to pass to the wrapper element */
|
||||
wrapperProps?: React.ComponentProps<Tag>;
|
||||
},
|
||||
}
|
||||
) {
|
||||
const { tag: Tag = 'div', style, wrapperProps, ...blocksProps } = props;
|
||||
|
||||
@@ -68,7 +68,7 @@ export function UnwrappedBlocks<TBlock extends DocumentBlock>(props: UnwrappedBl
|
||||
key={node.key}
|
||||
block={node}
|
||||
style={[
|
||||
'w-full mx-auto decoration-primary/6',
|
||||
'mx-auto w-full decoration-primary/6',
|
||||
node.data && 'fullWidth' in node.data && node.data.fullWidth
|
||||
? 'max-w-screen-xl'
|
||||
: 'max-w-3xl',
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {
|
||||
import type {
|
||||
DocumentBlockDrawing,
|
||||
DocumentBlockEmbed,
|
||||
DocumentBlockFile,
|
||||
@@ -7,9 +7,9 @@ import {
|
||||
} from '@gitbook/api';
|
||||
|
||||
import { getNodeFragmentByName, isNodeEmpty } from '@/lib/document';
|
||||
import { ClassValue, tcls } from '@/lib/tailwind';
|
||||
import { type ClassValue, tcls } from '@/lib/tailwind';
|
||||
|
||||
import { DocumentContextProps } from './DocumentView';
|
||||
import type { DocumentContextProps } from './DocumentView';
|
||||
import { Inlines } from './Inlines';
|
||||
|
||||
/**
|
||||
@@ -24,7 +24,7 @@ export function Caption(
|
||||
wrapperStyle?: ClassValue;
|
||||
block: DocumentBlockImage | DocumentBlockDrawing | DocumentBlockEmbed | DocumentBlockFile;
|
||||
withBorder?: boolean;
|
||||
} & DocumentContextProps,
|
||||
} & DocumentContextProps
|
||||
) {
|
||||
const {
|
||||
children,
|
||||
|
||||
@@ -5,9 +5,9 @@ import { useEffect, useRef, useState } from 'react';
|
||||
|
||||
import { useHasBeenInViewport } from '@/components/hooks/useHasBeenInViewport';
|
||||
|
||||
import type { HighlightLine, RenderedInline } from './highlight';
|
||||
import type { BlockProps } from '../Block';
|
||||
import { CodeBlockRenderer } from './CodeBlockRenderer';
|
||||
import type { HighlightLine, RenderedInline } from './highlight';
|
||||
import { plainHighlight } from './plain-highlight';
|
||||
|
||||
type ClientBlockProps = Pick<BlockProps<DocumentBlockCode>, 'block' | 'style'> & {
|
||||
@@ -41,9 +41,19 @@ export function ClientCodeBlock(props: ClientBlockProps) {
|
||||
// We use requestIdleCallback to avoid blocking the main thread
|
||||
// when scrolling.
|
||||
if (typeof requestIdleCallback === 'function') {
|
||||
requestIdleCallback(() => highlight(block, inlines).then(setLines));
|
||||
requestIdleCallback(() =>
|
||||
highlight(block, inlines).then((result) => {
|
||||
if (!canceled) {
|
||||
setLines(result);
|
||||
}
|
||||
})
|
||||
);
|
||||
} else {
|
||||
highlight(block, inlines).then(setLines);
|
||||
highlight(block, inlines).then((result) => {
|
||||
if (!canceled) {
|
||||
setLines(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return () => {
|
||||
|
||||
@@ -2,10 +2,10 @@ import type { DocumentBlockCode } from '@gitbook/api';
|
||||
|
||||
import { getNodeFragmentByType } from '@/lib/document';
|
||||
|
||||
import { BlockProps } from '../Block';
|
||||
import { ClientCodeBlock } from './ClientCodeBlock';
|
||||
import { getInlines, RenderedInline } from './highlight';
|
||||
import type { BlockProps } from '../Block';
|
||||
import { Blocks } from '../Blocks';
|
||||
import { ClientCodeBlock } from './ClientCodeBlock';
|
||||
import { type RenderedInline, getInlines } from './highlight';
|
||||
|
||||
/**
|
||||
* Render a code block, can be client-side or server-side.
|
||||
|
||||
@@ -4,10 +4,10 @@ import { forwardRef, useId } from 'react';
|
||||
|
||||
import { tcls } from '@/lib/tailwind';
|
||||
|
||||
import { CopyCodeButton } from './CopyCodeButton';
|
||||
import type { HighlightLine, HighlightToken } from './highlight';
|
||||
import { AnnotationPopover } from '../Annotation/AnnotationPopover';
|
||||
import type { BlockProps } from '../Block';
|
||||
import { CopyCodeButton } from './CopyCodeButton';
|
||||
import type { HighlightLine, HighlightToken } from './highlight';
|
||||
|
||||
import './theme.css';
|
||||
import './CodeBlockRenderer.css';
|
||||
@@ -21,7 +21,7 @@ type CodeBlockRendererProps = Pick<BlockProps<DocumentBlockCode>, 'block' | 'sty
|
||||
*/
|
||||
export const CodeBlockRenderer = forwardRef(function CodeBlockRenderer(
|
||||
props: CodeBlockRendererProps,
|
||||
ref: React.ForwardedRef<HTMLDivElement>,
|
||||
ref: React.ForwardedRef<HTMLDivElement>
|
||||
) {
|
||||
const { block, style, lines } = props;
|
||||
|
||||
@@ -32,29 +32,29 @@ export const CodeBlockRenderer = forwardRef(function CodeBlockRenderer(
|
||||
|
||||
return (
|
||||
<div ref={ref} className={tcls('group/codeblock grid grid-flow-col', style)}>
|
||||
<div className="flex items-center justify-start [grid-area:1/1] text-sm gap-2">
|
||||
<div className="flex items-center justify-start gap-2 text-sm [grid-area:1/1]">
|
||||
{title ? (
|
||||
<div className="text-xs tracking-wide text-tint leading-none inline-flex items-center justify-center bg-tint rounded-t straight-corners:rounded-t-s px-3 py-2">
|
||||
<div className="inline-flex items-center justify-center rounded-t straight-corners:rounded-t-s bg-tint px-3 py-2 text-tint text-xs leading-none tracking-wide">
|
||||
{title}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
<CopyCodeButton
|
||||
codeId={id}
|
||||
style="group-hover/codeblock:opacity-[1] transition-opacity duration-75 opacity-0 text-xs [grid-area:2/1] z-[2] justify-self-end backdrop-blur-md leading-none self-start ring-1 ring-tint text-tint bg-transparent rounded-md mr-2 mt-2 p-1 hover:ring-tint-hover"
|
||||
style="z-[2] mt-2 mr-2 self-start justify-self-end rounded-md bg-transparent p-1 text-tint text-xs leading-none opacity-0 ring-1 ring-tint backdrop-blur-md transition-opacity duration-75 [grid-area:2/1] hover:ring-tint-hover group-hover/codeblock:opacity-[1]"
|
||||
/>
|
||||
<pre
|
||||
className={tcls(
|
||||
'[grid-area:2/1] relative overflow-auto bg-tint theme-gradient:bg-tint-12/1 ring-tint-subtle hide-scroll',
|
||||
'hide-scroll relative overflow-auto bg-tint theme-gradient:bg-tint-12/1 ring-tint-subtle [grid-area:2/1]',
|
||||
'rounded-md straight-corners:rounded-sm',
|
||||
title && 'rounded-ss-none',
|
||||
title && 'rounded-ss-none'
|
||||
)}
|
||||
>
|
||||
<code
|
||||
id={id}
|
||||
className={tcls(
|
||||
'min-w-full inline-grid grid-cols-[auto_1fr] p-2 [count-reset:line]',
|
||||
withWrap && 'whitespace-pre-wrap',
|
||||
'inline-grid min-w-full grid-cols-[auto_1fr] p-2 [count-reset:line]',
|
||||
withWrap && 'whitespace-pre-wrap'
|
||||
)}
|
||||
>
|
||||
{lines.map((line, index) => (
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import React from 'react';
|
||||
|
||||
import { t, useLanguage } from '@/intl/client';
|
||||
import { ClassValue, tcls } from '@/lib/tailwind';
|
||||
import { type ClassValue, tcls } from '@/lib/tailwind';
|
||||
|
||||
/**
|
||||
* Client component to copy the code of a code block.
|
||||
@@ -52,7 +52,7 @@ export function CopyCodeButton(props: { codeId: string; style: ClassValue }) {
|
||||
* ignoring the empty white space we use for empty lines (represented with a class "ew").
|
||||
*/
|
||||
function getCodeText(code: HTMLElement): string {
|
||||
let text: string = '';
|
||||
let text = '';
|
||||
|
||||
const iterate = (node: Node) => {
|
||||
if (node instanceof HTMLBRElement) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { DocumentBlockCode, JSONDocument } from '@gitbook/api';
|
||||
import type { DocumentBlockCode, JSONDocument } from '@gitbook/api';
|
||||
import { useId } from 'react';
|
||||
|
||||
import { CodeBlock } from './CodeBlock';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { expect, it } from 'bun:test';
|
||||
import type { DocumentBlockCode } from '@gitbook/api';
|
||||
import { it, expect } from 'bun:test';
|
||||
|
||||
import { getInlines, highlight, RenderedInline } from './highlight';
|
||||
import { type RenderedInline, getInlines, highlight } from './highlight';
|
||||
|
||||
async function highlightWithInlines(block: DocumentBlockCode) {
|
||||
const inlines: RenderedInline[] = getInlines(block).map((inline) => ({
|
||||
@@ -68,9 +68,9 @@ it('should parse different code in parallel', async () => {
|
||||
},
|
||||
],
|
||||
},
|
||||
[],
|
||||
),
|
||||
),
|
||||
[]
|
||||
)
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
import { DocumentBlockCode, DocumentBlockCodeLine, DocumentInlineAnnotation } from '@gitbook/api';
|
||||
import type {
|
||||
DocumentBlockCode,
|
||||
DocumentBlockCodeLine,
|
||||
DocumentInlineAnnotation,
|
||||
} from '@gitbook/api';
|
||||
import {
|
||||
createdBundledHighlighter,
|
||||
ThemedToken,
|
||||
type ThemedToken,
|
||||
createCssVariablesTheme,
|
||||
createSingletonShorthands,
|
||||
createdBundledHighlighter,
|
||||
} from 'shiki/core';
|
||||
import { createJavaScriptRegexEngine } from 'shiki/engine/javascript';
|
||||
import { BundledLanguage, bundledLanguages } from 'shiki/langs';
|
||||
import { type BundledLanguage, bundledLanguages } from 'shiki/langs';
|
||||
|
||||
import { plainHighlight } from './plain-highlight';
|
||||
|
||||
@@ -39,7 +43,7 @@ const highlighter = createSingletonShorthands(
|
||||
createJavaScriptRegexEngine({
|
||||
forgiving: true,
|
||||
}),
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -60,7 +64,7 @@ export async function preloadHighlight(block: DocumentBlockCode) {
|
||||
*/
|
||||
export async function highlight(
|
||||
block: DocumentBlockCode,
|
||||
inlines: RenderedInline[],
|
||||
inlines: RenderedInline[]
|
||||
): Promise<HighlightLine[]> {
|
||||
const langName = getBlockLang(block);
|
||||
if (!langName) {
|
||||
@@ -159,7 +163,7 @@ export function getInlines(block: DocumentBlockCode) {
|
||||
|
||||
function matchTokenAndInlines(
|
||||
eat: () => PositionedToken | null,
|
||||
allInlines: RenderedInline[],
|
||||
allInlines: RenderedInline[]
|
||||
): HighlightToken[] {
|
||||
const initialToken = eat();
|
||||
if (!initialToken) {
|
||||
@@ -167,7 +171,7 @@ function matchTokenAndInlines(
|
||||
}
|
||||
|
||||
const inlines = allInlines.filter(
|
||||
({ inline }) => inline.start >= initialToken.start && inline.start < initialToken.end,
|
||||
({ inline }) => inline.start >= initialToken.start && inline.start < initialToken.end
|
||||
);
|
||||
let token = initialToken;
|
||||
const result: HighlightToken[] = [];
|
||||
@@ -191,7 +195,7 @@ function matchTokenAndInlines(
|
||||
});
|
||||
}
|
||||
if (!afterBefore) {
|
||||
throw new Error(`expect afterBefore to not be empty`);
|
||||
throw new Error('expect afterBefore to not be empty');
|
||||
}
|
||||
|
||||
token = afterBefore;
|
||||
@@ -206,14 +210,14 @@ function matchTokenAndInlines(
|
||||
|
||||
const next = eat();
|
||||
if (!next) {
|
||||
throw new Error(`expect token to not be empty`);
|
||||
throw new Error('expect token to not be empty');
|
||||
}
|
||||
token = next;
|
||||
}
|
||||
|
||||
const [inside, after] = splitPositionedTokenAt(token, inline.inline.end);
|
||||
if (!inside) {
|
||||
throw new Error(`expect inside to not be empty`);
|
||||
throw new Error('expect inside to not be empty');
|
||||
}
|
||||
|
||||
children.push({
|
||||
@@ -255,7 +259,7 @@ function getPlainCodeBlock(code: DocumentBlockCode, inlines?: InlineIndexed[]):
|
||||
function getPlainCodeBlockLine(
|
||||
parent: DocumentBlockCodeLine | DocumentInlineAnnotation,
|
||||
index: number,
|
||||
inlines?: InlineIndexed[],
|
||||
inlines?: InlineIndexed[]
|
||||
): string {
|
||||
let content = '';
|
||||
|
||||
@@ -283,7 +287,7 @@ function getPlainCodeBlockLine(
|
||||
function slicePositionedToken(
|
||||
token: PositionedToken,
|
||||
relativeStart: number,
|
||||
relativeLength: number,
|
||||
relativeLength: number
|
||||
): PositionedToken {
|
||||
return {
|
||||
...token,
|
||||
@@ -295,7 +299,7 @@ function slicePositionedToken(
|
||||
|
||||
function splitPositionedTokenAt(
|
||||
token: PositionedToken,
|
||||
absoluteIndex: number,
|
||||
absoluteIndex: number
|
||||
): [PositionedToken | null, PositionedToken | null] {
|
||||
if (absoluteIndex < token.start || absoluteIndex > token.end) {
|
||||
throw new Error(`index (${absoluteIndex}) out of bound (${token.start}:${token.end})`);
|
||||
@@ -305,7 +309,7 @@ function splitPositionedTokenAt(
|
||||
const after = slicePositionedToken(
|
||||
token,
|
||||
absoluteIndex - token.start,
|
||||
token.end - absoluteIndex,
|
||||
token.end - absoluteIndex
|
||||
);
|
||||
|
||||
return [
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { DocumentBlockCode } from '@gitbook/api';
|
||||
import type { DocumentBlockCode } from '@gitbook/api';
|
||||
|
||||
import { getNodeText } from '@/lib/document';
|
||||
|
||||
@@ -9,7 +9,7 @@ import type { HighlightLine, HighlightToken, RenderedInline } from './highlight'
|
||||
*/
|
||||
export function plainHighlight(
|
||||
block: DocumentBlockCode,
|
||||
inlines: RenderedInline[],
|
||||
inlines: RenderedInline[]
|
||||
): HighlightLine[] {
|
||||
const inlinesCopy = Array.from(inlines);
|
||||
return block.nodes.map((lineBlock) => {
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
:root {
|
||||
--shiki-color-text: theme('colors.tint.11');
|
||||
--shiki-color-text: var(--color-tint-11);
|
||||
--shiki-token-constant: #0a6355;
|
||||
--shiki-token-string: #8b6d32;
|
||||
--shiki-token-comment: theme('colors.teal.700/.64');
|
||||
--shiki-token-keyword: theme('colors.pomegranate.600');
|
||||
--shiki-token-comment: var(--color-teal-700 / 0.64);
|
||||
--shiki-token-keyword: var(--color-pomegranate-600);
|
||||
--shiki-token-parameter: #0a3069;
|
||||
--shiki-token-function: #8250df;
|
||||
--shiki-token-string-expression: #6a4906;
|
||||
--shiki-token-punctuation: theme('colors.pomegranate.700/.92');
|
||||
--shiki-token-link: theme('colors.tint.12');
|
||||
--shiki-token-punctuation: var(--color-pomegranate-700 / 0.92);
|
||||
--shiki-token-link: var(--color-tint-12);
|
||||
--shiki-token-inserted: #22863a;
|
||||
--shiki-token-deleted: #b31d28;
|
||||
--shiki-token-changed: #8250df;
|
||||
}
|
||||
|
||||
html.dark {
|
||||
--shiki-color-text: theme('colors.tint.11');
|
||||
--shiki-color-text: var(--color-tint-11);
|
||||
--shiki-token-constant: #d19a66;
|
||||
--shiki-token-string: theme('colors.pomegranate.300');
|
||||
--shiki-token-comment: theme('colors.teal.300/.64');
|
||||
--shiki-token-keyword: theme('colors.pomegranate.400');
|
||||
--shiki-token-parameter: theme('colors.yellow.500');
|
||||
--shiki-token-string: var(--color-pomegranate-300);
|
||||
--shiki-token-comment: var(--color-teal-300 / 0.64);
|
||||
--shiki-token-keyword: var(--color-pomegranate-400);
|
||||
--shiki-token-parameter: var(--color-yellow-500);
|
||||
--shiki-token-function: #56b6c2;
|
||||
--shiki-token-string-expression: theme('colors.tint.11');
|
||||
--shiki-token-string-expression: var(--color-tint-11);
|
||||
--shiki-token-punctuation: #acc6ee;
|
||||
--shiki-token-link: theme('colors.pomegranate.400');
|
||||
--shiki-token-link: var(--color-pomegranate-400);
|
||||
--shiki-token-inserted: #85e89d;
|
||||
--shiki-token-deleted: #fdaeb7;
|
||||
--shiki-token-changed: #56b6c2;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { DocumentBlockDivider } from '@gitbook/api';
|
||||
import type { DocumentBlockDivider } from '@gitbook/api';
|
||||
|
||||
import { tcls } from '@/lib/tailwind';
|
||||
|
||||
import { BlockProps } from './Block';
|
||||
import type { BlockProps } from './Block';
|
||||
|
||||
export function Divider(props: BlockProps<DocumentBlockDivider>) {
|
||||
const { style } = props;
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { ContentRef, JSONDocument } from '@gitbook/api';
|
||||
import { GitBookAnyContext } from '@v2/lib/context';
|
||||
|
||||
import { ResolveContentRefOptions, ResolvedContentRef } from '@/lib/references';
|
||||
import { ClassValue } from '@/lib/tailwind';
|
||||
import type { ClassValue } from '@/lib/tailwind';
|
||||
import type { JSONDocument } from '@gitbook/api';
|
||||
import type { GitBookAnyContext } from '@v2/lib/context';
|
||||
|
||||
import { BlockSkeleton } from './Block';
|
||||
import { Blocks } from './Blocks';
|
||||
@@ -48,7 +46,7 @@ export function DocumentView(
|
||||
|
||||
/** Style passed to all blocks */
|
||||
blockStyle?: ClassValue;
|
||||
},
|
||||
}
|
||||
) {
|
||||
const { document, style, blockStyle = [], context } = props;
|
||||
|
||||
@@ -76,12 +74,12 @@ export function DocumentViewSkeleton(props: { document: JSONDocument; blockStyle
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
{document.nodes.map((block, index) => (
|
||||
{document.nodes.map((block) => (
|
||||
<BlockSkeleton
|
||||
key={block.key!}
|
||||
block={block}
|
||||
style={[
|
||||
'w-full mx-auto decoration-primary/6',
|
||||
'mx-auto w-full decoration-primary/6',
|
||||
block.data && 'fullWidth' in block.data && block.data.fullWidth
|
||||
? 'max-w-screen-xl'
|
||||
: 'max-w-3xl',
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { DocumentBlockDrawing } from '@gitbook/api';
|
||||
import type { DocumentBlockDrawing } from '@gitbook/api';
|
||||
|
||||
import { resolveContentRef } from '@/lib/references';
|
||||
|
||||
import { BlockProps } from './Block';
|
||||
import { Image } from '../utils';
|
||||
import type { BlockProps } from './Block';
|
||||
import { Caption } from './Caption';
|
||||
import { imageBlockSizes } from './Images';
|
||||
import { Image } from '../utils';
|
||||
|
||||
export async function Drawing(props: BlockProps<DocumentBlockDrawing>) {
|
||||
const { block, context } = props;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import * as gitbookAPI from '@gitbook/api';
|
||||
import type * as gitbookAPI from '@gitbook/api';
|
||||
import Script from 'next/script';
|
||||
import ReactDOM from 'react-dom';
|
||||
|
||||
import { Card } from '@/components/primitives';
|
||||
import { getEmbedByUrlInSpace, getEmbedByUrl } from '@/lib/api';
|
||||
import { getEmbedByUrl, getEmbedByUrlInSpace } from '@/lib/api';
|
||||
import { getContentSecurityPolicyNonce } from '@/lib/csp';
|
||||
import { tcls } from '@/lib/tailwind';
|
||||
|
||||
import { BlockProps } from './Block';
|
||||
import type { BlockProps } from './Block';
|
||||
import { Caption } from './Caption';
|
||||
import { IntegrationBlock } from './Integration';
|
||||
|
||||
@@ -65,7 +65,7 @@ export async function Embed(props: BlockProps<gitbookAPI.DocumentBlockEmbed>) {
|
||||
function createIntegrationBlock(
|
||||
url: string,
|
||||
integration: string,
|
||||
block: gitbookAPI.IntegrationBlock,
|
||||
block: gitbookAPI.IntegrationBlock
|
||||
): gitbookAPI.DocumentBlockIntegration {
|
||||
return {
|
||||
object: 'block',
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { DocumentInlineEmoji } from '@gitbook/api';
|
||||
import type { DocumentInlineEmoji } from '@gitbook/api';
|
||||
|
||||
import { Emoji as EmojiPrimitive } from '@/components/primitives';
|
||||
|
||||
import { InlineProps } from './Inline';
|
||||
import type { InlineProps } from './Inline';
|
||||
|
||||
export async function Emoji(props: InlineProps<DocumentInlineEmoji>) {
|
||||
const { inline } = props;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import React from 'react';
|
||||
|
||||
import { useHash } from '@/components/hooks';
|
||||
import { ClassValue, tcls } from '@/lib/tailwind';
|
||||
import { type ClassValue, tcls } from '@/lib/tailwind';
|
||||
|
||||
/**
|
||||
* Details component rendered on client so it can expand dependent on url hash changes.
|
||||
@@ -60,7 +60,7 @@ export function Details(props: {
|
||||
//select last in group
|
||||
'[&:not(:has(+_&))]:mb-5',
|
||||
'[&:not(:has(+_&))]:rounded-b-lg',
|
||||
'[&:not(:has(+_&))]:border-b',
|
||||
'[&:not(:has(+_&))]:border-b'
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { DocumentBlockExpandable } from '@gitbook/api';
|
||||
import type { DocumentBlockExpandable } from '@gitbook/api';
|
||||
import { Icon } from '@gitbook/icons';
|
||||
|
||||
import { getNodeFragmentByType } from '@/lib/document';
|
||||
import { tcls } from '@/lib/tailwind';
|
||||
|
||||
import { Details } from './Details';
|
||||
import { BlockProps } from '../Block';
|
||||
import type { BlockProps } from '../Block';
|
||||
import { Blocks } from '../Blocks';
|
||||
import { Inlines } from '../Inlines';
|
||||
import { Details } from './Details';
|
||||
|
||||
export function Expandable(props: BlockProps<DocumentBlockExpandable>) {
|
||||
const { block, style, ancestorBlocks, document, context } = props;
|
||||
@@ -39,7 +39,7 @@ export function Expandable(props: BlockProps<DocumentBlockExpandable>) {
|
||||
'text-tint',
|
||||
'group-hover/expandable:text-tint-strong',
|
||||
'group-open/expandable:text-tint-strong',
|
||||
'[&::-webkit-details-marker]:hidden',
|
||||
'[&::-webkit-details-marker]:hidden'
|
||||
)}
|
||||
>
|
||||
<Icon
|
||||
@@ -51,7 +51,7 @@ export function Expandable(props: BlockProps<DocumentBlockExpandable>) {
|
||||
'mb-1',
|
||||
'transition-transform',
|
||||
'shrink-0',
|
||||
'group-open/expandable:rotate-90',
|
||||
'group-open/expandable:rotate-90'
|
||||
)}
|
||||
/>
|
||||
<Inlines
|
||||
@@ -71,7 +71,7 @@ export function Expandable(props: BlockProps<DocumentBlockExpandable>) {
|
||||
'flex',
|
||||
'items-center',
|
||||
'dark:shadow-none',
|
||||
'dark:ring-0',
|
||||
'dark:ring-0'
|
||||
)}
|
||||
>
|
||||
<Icon
|
||||
@@ -82,7 +82,7 @@ export function Expandable(props: BlockProps<DocumentBlockExpandable>) {
|
||||
'transition-colors',
|
||||
'text-transparent',
|
||||
'group-hover/expandable:text-tint-subtle',
|
||||
'contrast-more:group-hover/expandable:text-tint-strong',
|
||||
'contrast-more:group-hover/expandable:text-tint-strong'
|
||||
)}
|
||||
/>
|
||||
</a>
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { DocumentBlockFile, SiteInsightsLinkPosition } from '@gitbook/api';
|
||||
import { type DocumentBlockFile, SiteInsightsLinkPosition } from '@gitbook/api';
|
||||
|
||||
import { getSimplifiedContentType } from '@/lib/files';
|
||||
import { resolveContentRef } from '@/lib/references';
|
||||
import { tcls } from '@/lib/tailwind';
|
||||
|
||||
import { BlockProps } from './Block';
|
||||
import { Link } from '../primitives';
|
||||
import type { BlockProps } from './Block';
|
||||
import { Caption } from './Caption';
|
||||
import { FileIcon } from './FileIcon';
|
||||
import { Link } from '../primitives';
|
||||
|
||||
export async function File(props: BlockProps<DocumentBlockFile>) {
|
||||
const { block, context } = props;
|
||||
@@ -47,7 +47,7 @@ export async function File(props: BlockProps<DocumentBlockFile>) {
|
||||
'items-center',
|
||||
'gap-1',
|
||||
'border-r',
|
||||
'border-tint-subtle',
|
||||
'border-tint-subtle'
|
||||
)}
|
||||
>
|
||||
<div>
|
||||
@@ -60,7 +60,7 @@ export async function File(props: BlockProps<DocumentBlockFile>) {
|
||||
className={tcls(
|
||||
'text-xs',
|
||||
'text-tint',
|
||||
'group-hover/file:text-tint-strong',
|
||||
'group-hover/file:text-tint-strong'
|
||||
)}
|
||||
>
|
||||
{getHumanFileSize(file.size)}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Icon } from '@gitbook/icons';
|
||||
|
||||
import { SimplifiedFileType } from '@/lib/files';
|
||||
import type { SimplifiedFileType } from '@/lib/files';
|
||||
|
||||
/**
|
||||
* Render an appropriate icon for a file.
|
||||
|
||||
@@ -36,7 +36,7 @@ export function Heading(props: BlockProps<DocumentBlockHeading>) {
|
||||
'group-focus:opacity-[0]',
|
||||
'md:group-hover:md:opacity-[1]',
|
||||
'md:group-focus:md:opacity-[1]',
|
||||
textStyle.marginTop,
|
||||
textStyle.marginTop
|
||||
)}
|
||||
>
|
||||
<a
|
||||
@@ -54,7 +54,7 @@ export function Heading(props: BlockProps<DocumentBlockHeading>) {
|
||||
'text-transparent',
|
||||
'group-hover:text-tint-subtle',
|
||||
'contrast-more:group-hover:text-tint-strong',
|
||||
'lg:w-4',
|
||||
'lg:w-4'
|
||||
)}
|
||||
/>
|
||||
</a>
|
||||
@@ -66,7 +66,7 @@ export function Heading(props: BlockProps<DocumentBlockHeading>) {
|
||||
'justify-self-start',
|
||||
'text-left',
|
||||
textStyle.lineHeight,
|
||||
textStyle.marginTop,
|
||||
textStyle.marginTop
|
||||
)}
|
||||
>
|
||||
<Inlines {...rest} context={context} nodes={block.nodes} ancestorInlines={[]} />
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { DocumentBlockHeading, DocumentBlockHint } from '@gitbook/api';
|
||||
import type { DocumentBlockHint } from '@gitbook/api';
|
||||
import { Icon, type IconName } from '@gitbook/icons';
|
||||
import React from 'react';
|
||||
|
||||
import { type ClassValue, tcls } from '@/lib/tailwind';
|
||||
|
||||
@@ -33,7 +32,7 @@ export function Hint(props: BlockProps<DocumentBlockHint>) {
|
||||
'grid-cols-[auto_1fr]',
|
||||
hasHeading ? 'grid-rows-[auto_auto]' : '',
|
||||
|
||||
style,
|
||||
style
|
||||
)}
|
||||
>
|
||||
<div
|
||||
@@ -42,7 +41,7 @@ export function Hint(props: BlockProps<DocumentBlockHint>) {
|
||||
'pl-3',
|
||||
'-mt-px', // Bump icon up 1px for optical alignment with heading
|
||||
hasHeading ? hintStyle.header : null,
|
||||
hintStyle.iconColor,
|
||||
hintStyle.iconColor
|
||||
)}
|
||||
>
|
||||
<Icon
|
||||
@@ -53,8 +52,8 @@ export function Hint(props: BlockProps<DocumentBlockHint>) {
|
||||
{hasHeading ? (
|
||||
<Block
|
||||
style={tcls(
|
||||
'text-[1em] *:mt-0 p-3 flip-heading-hash',
|
||||
hasHeading ? hintStyle.header : null,
|
||||
'flip-heading-hash p-3 text-[1em] *:mt-0',
|
||||
hasHeading ? hintStyle.header : null
|
||||
)}
|
||||
ancestorBlocks={[...ancestorBlocks, block]}
|
||||
{...contextProps}
|
||||
@@ -68,7 +67,7 @@ export function Hint(props: BlockProps<DocumentBlockHint>) {
|
||||
blockStyle={tcls(
|
||||
hintStyle.body,
|
||||
// render hash icon on the other side of the heading
|
||||
'flip-heading-hash',
|
||||
'flip-heading-hash'
|
||||
)}
|
||||
style={[
|
||||
'p-3',
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import {
|
||||
import type {
|
||||
DocumentBlockImage,
|
||||
DocumentBlockImageDimension,
|
||||
DocumentBlockImages,
|
||||
JSONDocument,
|
||||
} from '@gitbook/api';
|
||||
|
||||
import { Image, ImageResponsiveSize } from '@/components/utils';
|
||||
import { Image, type ImageResponsiveSize } from '@/components/utils';
|
||||
import { resolveContentRef } from '@/lib/references';
|
||||
import { ClassValue, tcls } from '@/lib/tailwind';
|
||||
import { type ClassValue, tcls } from '@/lib/tailwind';
|
||||
|
||||
import { BlockProps } from './Block';
|
||||
import type { BlockProps } from './Block';
|
||||
import { Caption } from './Caption';
|
||||
import { DocumentContext } from './DocumentView';
|
||||
import type { DocumentContext } from './DocumentView';
|
||||
|
||||
export function Images(props: BlockProps<DocumentBlockImages>) {
|
||||
const { document, block, ancestorBlocks, style, context, isEstimatedOffscreen } = props;
|
||||
const { document, block, style, context, isEstimatedOffscreen } = props;
|
||||
|
||||
const isMultipleImages = block.nodes.length > 1;
|
||||
const { align = 'center' } = block.data;
|
||||
@@ -29,10 +29,10 @@ export function Images(props: BlockProps<DocumentBlockImages>) {
|
||||
align === 'center' && 'justify-center',
|
||||
align === 'right' && 'justify-end',
|
||||
align === 'left' && 'justify-start',
|
||||
isMultipleImages && ['grid', 'grid-flow-col', 'max-w-none'],
|
||||
isMultipleImages && ['grid', 'grid-flow-col', 'max-w-none']
|
||||
)}
|
||||
>
|
||||
{block.nodes.map((node: any, i: number) => (
|
||||
{block.nodes.map((node: any, _i: number) => (
|
||||
<ImageBlock
|
||||
key={node.key}
|
||||
block={node}
|
||||
@@ -120,13 +120,13 @@ async function ImageBlock(props: {
|
||||
*/
|
||||
function getImageDimension<DefaultValue>(
|
||||
dimension: DocumentBlockImageDimension | undefined,
|
||||
defaultValue: DefaultValue,
|
||||
defaultValue: DefaultValue
|
||||
): string | DefaultValue {
|
||||
if (typeof dimension === 'number') {
|
||||
return `${dimension}px`;
|
||||
} else if (dimension?.unit === 'px') {
|
||||
return `${dimension.value}${dimension.unit}`;
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
if (dimension?.unit === 'px') {
|
||||
return `${dimension.value}${dimension.unit}`;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import {
|
||||
DocumentInlineImage,
|
||||
import type {
|
||||
DocumentInline,
|
||||
DocumentInlineAnnotation,
|
||||
DocumentInlineEmoji,
|
||||
DocumentInlineImage,
|
||||
DocumentInlineLink,
|
||||
DocumentInlineMath,
|
||||
DocumentInlineMention,
|
||||
DocumentInline,
|
||||
JSONDocument,
|
||||
} from '@gitbook/api';
|
||||
import assertNever from 'assert-never';
|
||||
|
||||
import { Annotation } from './Annotation/Annotation';
|
||||
import { DocumentContextProps } from './DocumentView';
|
||||
import type { DocumentContextProps } from './DocumentView';
|
||||
import { Emoji } from './Emoji';
|
||||
import { InlineImage } from './InlineImage';
|
||||
import { InlineLink } from './InlineLink';
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { DocumentInlineImage } from '@gitbook/api';
|
||||
import { GitBookBaseContext } from '@v2/lib/context';
|
||||
import type { DocumentInlineImage } from '@gitbook/api';
|
||||
import type { GitBookBaseContext } from '@v2/lib/context';
|
||||
import assertNever from 'assert-never';
|
||||
|
||||
import { resolveContentRef, ResolvedContentRef } from '@/lib/references';
|
||||
import { type ResolvedContentRef, resolveContentRef } from '@/lib/references';
|
||||
import { tcls } from '@/lib/tailwind';
|
||||
|
||||
import { InlineProps } from './Inline';
|
||||
import { Image } from '../utils';
|
||||
import type { InlineProps } from './Inline';
|
||||
|
||||
export async function InlineImage(props: InlineProps<DocumentInlineImage>) {
|
||||
const { inline, context, ancestorInlines } = props;
|
||||
@@ -30,7 +30,7 @@ export async function InlineImage(props: InlineProps<DocumentInlineImage>) {
|
||||
/* 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]', 'align-middle'] : null,
|
||||
size !== 'line' ? ['inline-flex', 'max-w-[300px]', 'align-middle'] : null
|
||||
)}
|
||||
>
|
||||
<Image
|
||||
@@ -62,7 +62,7 @@ export async function InlineImage(props: InlineProps<DocumentInlineImage>) {
|
||||
async function getImageSizes(
|
||||
context: GitBookBaseContext | undefined,
|
||||
size: 'original' | 'line',
|
||||
src: ResolvedContentRef,
|
||||
src: ResolvedContentRef
|
||||
) {
|
||||
switch (size) {
|
||||
case 'line': {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { DocumentInlineLink, SiteInsightsLinkPosition } from '@gitbook/api';
|
||||
import { type DocumentInlineLink, SiteInsightsLinkPosition } from '@gitbook/api';
|
||||
|
||||
import { resolveContentRef } from '@/lib/references';
|
||||
|
||||
import { InlineProps } from './Inline';
|
||||
import { StyledLink } from '../primitives';
|
||||
import type { InlineProps } from './Inline';
|
||||
import { Inlines } from './Inlines';
|
||||
import { Link, StyledLink } from '../primitives';
|
||||
|
||||
export async function InlineLink(props: InlineProps<DocumentInlineLink>) {
|
||||
const { inline, document, context, ancestorInlines } = props;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { DocumentInline, DocumentText, JSONDocument } from '@gitbook/api';
|
||||
import type { DocumentInline, DocumentText, JSONDocument } from '@gitbook/api';
|
||||
|
||||
import { DocumentContextProps } from './DocumentView';
|
||||
import type { DocumentContextProps } from './DocumentView';
|
||||
import { Inline } from './Inline';
|
||||
import { Text } from './Text';
|
||||
|
||||
@@ -20,13 +20,13 @@ export function Inlines<T extends DocumentInline | DocumentText>(
|
||||
* Nodes to render
|
||||
*/
|
||||
nodes: T[];
|
||||
},
|
||||
}
|
||||
) {
|
||||
const { nodes, document, ancestorInlines, ...contextProps } = props;
|
||||
|
||||
return (
|
||||
<>
|
||||
{nodes.map((node, index) => {
|
||||
{nodes.map((node) => {
|
||||
if (node.object === 'text') {
|
||||
return <Text key={node.key} text={node} />;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { ContentKitContext, DocumentBlockIntegration } from '@gitbook/api';
|
||||
import type { ContentKitContext, DocumentBlockIntegration } from '@gitbook/api';
|
||||
import { Icon } from '@gitbook/icons';
|
||||
import { ContentKit, ContentKitOutput, ContentKitServerContext } from '@gitbook/react-contentkit';
|
||||
import {
|
||||
ContentKit,
|
||||
ContentKitOutput,
|
||||
type ContentKitServerContext,
|
||||
} from '@gitbook/react-contentkit';
|
||||
|
||||
import { ignoreAPIError, renderIntegrationUi } from '@/lib/api';
|
||||
import { INTEGRATIONS_HOST } from '@/lib/csp';
|
||||
@@ -61,7 +65,7 @@ export async function IntegrationBlock(props: BlockProps<DocumentBlockIntegratio
|
||||
|
||||
const initialOutput = await ignoreAPIError(
|
||||
renderIntegrationUi(block.data.integration, initialInput),
|
||||
true,
|
||||
true
|
||||
);
|
||||
if (!initialOutput || initialOutput.type === 'complete') {
|
||||
return null;
|
||||
|
||||
@@ -66,6 +66,7 @@
|
||||
}
|
||||
|
||||
.contentkit-card-icon {
|
||||
/* unstyled */
|
||||
}
|
||||
|
||||
.contentkit-card-buttons {
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import {
|
||||
import type {
|
||||
DocumentBlockListOrdered,
|
||||
DocumentBlockListTasks,
|
||||
DocumentBlockListUnordered,
|
||||
} from '@gitbook/api';
|
||||
import assertNever from 'assert-never';
|
||||
|
||||
import { BlockProps } from './Block';
|
||||
import type { BlockProps } from './Block';
|
||||
import { Blocks } from './Blocks';
|
||||
|
||||
export function List(
|
||||
props: BlockProps<
|
||||
DocumentBlockListUnordered | DocumentBlockListOrdered | DocumentBlockListTasks
|
||||
>,
|
||||
>
|
||||
) {
|
||||
const { block, style, ancestorBlocks, ...contextProps } = props;
|
||||
|
||||
@@ -30,7 +30,7 @@ function getListTag(
|
||||
type:
|
||||
| DocumentBlockListUnordered['type']
|
||||
| DocumentBlockListOrdered['type']
|
||||
| DocumentBlockListTasks['type'],
|
||||
| DocumentBlockListTasks['type']
|
||||
) {
|
||||
switch (type) {
|
||||
case 'list-ordered':
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {
|
||||
import type {
|
||||
DocumentBlock,
|
||||
DocumentBlockListItem,
|
||||
DocumentBlockListOrdered,
|
||||
@@ -10,7 +10,7 @@ import { assert } from 'ts-essentials';
|
||||
import { Checkbox } from '@/components/primitives';
|
||||
import { tcls } from '@/lib/tailwind';
|
||||
|
||||
import { BlockProps } from './Block';
|
||||
import type { BlockProps } from './Block';
|
||||
import { Blocks } from './Blocks';
|
||||
import { getBlockTextStyle } from './spacing';
|
||||
|
||||
@@ -22,7 +22,7 @@ export function ListItem(props: BlockProps<DocumentBlockListItem>) {
|
||||
(parent && parent.type === 'list-ordered') ||
|
||||
parent.type === 'list-unordered' ||
|
||||
parent.type === 'list-tasks',
|
||||
'Invalid parent list type',
|
||||
'Invalid parent list type'
|
||||
);
|
||||
|
||||
const blocksElement = (
|
||||
@@ -39,9 +39,9 @@ export function ListItem(props: BlockProps<DocumentBlockListItem>) {
|
||||
'[&:is(h3)>div]:mt-0',
|
||||
'[&:is(h4)>div]:mt-0',
|
||||
// Override the "mx-auto" class from UnwrappedBlocks
|
||||
'mx-0',
|
||||
'mx-0'
|
||||
)}
|
||||
style="space-y-2 flex flex-col flex-1"
|
||||
style="flex flex-1 flex-col space-y-2"
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -137,7 +137,7 @@ function ListItemPrefix(props: { block: DocumentBlockListItem; children: React.R
|
||||
className={tcls(
|
||||
textStyle.textSize,
|
||||
textStyle.lineHeight,
|
||||
'flex items-center justify-center mr-1 min-h-[1lh] min-w-6 text-tint',
|
||||
'mr-1 flex min-h-[1lh] min-w-6 items-center justify-center text-tint'
|
||||
)}
|
||||
>
|
||||
{props.children}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { DocumentBlockMath, DocumentInlineMath } from '@gitbook/api';
|
||||
import type { DocumentBlockMath, DocumentInlineMath } from '@gitbook/api';
|
||||
import { MathFormula } from '@gitbook/react-math';
|
||||
|
||||
import { getStaticFileURL } from '@/lib/assets';
|
||||
import { tcls } from '@/lib/tailwind';
|
||||
|
||||
import { BlockProps } from './Block';
|
||||
import { InlineProps } from './Inline';
|
||||
import type { BlockProps } from './Block';
|
||||
import type { InlineProps } from './Inline';
|
||||
|
||||
const assetsUrl = getStaticFileURL('math');
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user