Compare commits

...

4 Commits

Author SHA1 Message Date
Vib Bhardwaj 7ec64dad58 rm public 2024-12-26 20:16:02 +00:00
Vib Bhardwaj 326d674254 remove next assets 2024-12-26 20:14:00 +00:00
Vib Bhardwaj a6a78ce5ac ignore shiki 2024-12-26 14:18:38 +00:00
Vib Bhardwaj 56cb2f4c9a wip 2024-12-23 15:29:31 +00:00
27 changed files with 2064 additions and 424 deletions
+11
View File
@@ -0,0 +1,11 @@
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"ignore": [
"node_modules",
"dist",
"public"
]
}
BIN
View File
Binary file not shown.
+5
View File
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
+43 -36
View File
@@ -1,38 +1,45 @@
{
"name": "gitbook",
"version": "0.1.0",
"devDependencies": {
"@changesets/cli": "^2.27.7",
"prettier": "^3.0.3",
"turbo": "^2.1.2"
},
"packageManager": "bun@1.1.18",
"patchedDependencies": {
"@vercel/next@4.3.15": "patches/@vercel%2Fnext@4.3.15.patch",
"@cloudflare/next-on-pages@1.13.5": "patches/@cloudflare%2Fnext-on-pages@1.13.5.patch"
},
"overrides": {
"@codemirror/state": "6.4.1"
},
"private": true,
"scripts": {
"dev": "turbo run dev",
"build": "turbo run build",
"build:cloudflare": "turbo run build:cloudflare",
"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",
"unit": "turbo run unit",
"e2e": "turbo run e2e",
"changeset": "changeset",
"release": "turbo run release && changeset publish",
"release:preview": "turbo run release:preview",
"download:env": "op read op://gitbook-x-dev/gitbook-open/.env.local >> .env.local",
"clean": "turbo run clean"
},
"workspaces": [
"packages/*"
]
"name": "gitbook",
"version": "0.1.0",
"type": "module",
"devDependencies": {
"@changesets/cli": "^2.27.7",
"prettier": "^3.0.3",
"turbo": "^2.1.2"
},
"packageManager": "bun@1.1.18",
"patchedDependencies": {
"@vercel/next@4.3.15": "patches/@vercel%2Fnext@4.3.15.patch",
"@cloudflare/next-on-pages@1.13.5": "patches/@cloudflare%2Fnext-on-pages@1.13.5.patch"
},
"overrides": {
"@codemirror/state": "6.4.1"
},
"private": true,
"scripts": {
"dev": "turbo run dev",
"build": "turbo run build",
"build:cloudflare": "turbo run build:cloudflare",
"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",
"unit": "turbo run unit",
"e2e": "turbo run e2e",
"changeset": "changeset",
"release": "turbo run release && changeset publish",
"release:preview": "turbo run release:preview",
"download:env": "op read op://gitbook-x-dev/gitbook-open/.env.local >> .env.local",
"clean": "turbo run clean"
},
"workspaces": [
"packages/*"
],
"dependencies": {
"@babel/cli": "^7.26.4",
"@babel/preset-env": "^7.26.0",
"@babel/preset-react": "^7.26.3",
"tsconfig-paths": "^4.2.0"
}
}
File diff suppressed because it is too large Load Diff
@@ -11,23 +11,24 @@ import { 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 { getSpaceLanguage } from '@/intl/server';
import { tString } from '@/intl/translate';
import { DocumentView } from '../../../../components/DocumentView';
import { TrademarkLink } from '../../../../components/TableOfContents/Trademark';
import { PolymorphicComponentProp } from '../../../../components/utils/types';
import { getSpaceLanguage } from '../../../../intl/server';
import { tString } from '../../../../intl/translate';
import {
getDocument,
getSpace,
getSpaceCustomization,
getSpaceContentData,
getSiteData,
} from '@/lib/api';
import { pagePDFContainerId, PageHrefContext, absoluteHref } from '@/lib/links';
import { resolvePageId } from '@/lib/pages';
import { ContentRefContext, resolveContentRef } from '@/lib/references';
import { tcls } from '@/lib/tailwind';
import { PDFSearchParams, getPDFSearchParams } from '@/lib/urls';
} from '../../../../lib/api';
import { pagePDFContainerId, PageHrefContext, absoluteHref } from '../../../../lib/links';
import { resolvePageId } from '../../../../lib/pages';
import { ContentRefContext, resolveContentRef } from '../../../../lib/references';
import { tcls } from '../../../../lib/tailwind';
import { SiteContentPointer, SpaceContentPointer } from '../../../../lib/api';
import { PDFSearchParams, getPDFSearchParams } from '../../../../lib/urls';
import './pdf.css';
import { PageControlButtons } from './PageControlButtons';
@@ -55,7 +56,9 @@ export async function generateMetadata(): Promise<Metadata> {
* Render a space as a standalone HTML page that can be printed as a PDF.
*/
export default async function PDFHTMLOutput(props: { searchParams: { [key: string]: string } }) {
const pointer = getSiteOrSpacePointerForPDF();
const pointer = {"siteId": "site_dIY9z", "spaceId": "-MdwVZ6HOZriajCf5nXH", "siteSpaceId": "sitesp_mX2p5", "organizationId": "-M4tdxG8qotLgGZnLpFR"} as SiteContentPointer | SpaceContentPointer;
console.log('vib pointer', JSON.stringify(pointer));
const searchParams = new URLSearchParams(props.searchParams);
const pdfParams = getPDFSearchParams(new URLSearchParams(searchParams));
@@ -0,0 +1,27 @@
const { renderToPipeableStream } = require('react-dom/server');
const PDFHTMLOutput = require('./page');
//import { renderToPipeableStream, renderToStaticNodeStream } from 'react-dom/server';
//import PDFHTMLOutput from './page';
//import fs from 'fs';
//import React from 'react';
const fs = require('fs');
const React = require('react');
// Create a writable stream to save the HTML to a file
const writeStream = fs.createWriteStream('output.html');
// Start the server-side rendering with renderToPipeableStream
const { pipe } = renderToPipeableStream(React.createElement(PDFHTMLOutput, {searchParams : {'a': 'b'}}) as any);
// Pipe the render stream to the writable file stream
pipe(writeStream);
// Optionally, you can handle errors and closure
writeStream.on('finish', () => {
console.log('HTML has been written to output.html');
});
writeStream.on('error', (err: any) => {
console.error('Error writinsg to file:', err);
});
@@ -283,9 +283,9 @@ function CodeHighlightToken(props: {
return <>{token.content}</>;
}
if (!token.token.color) {
return <>{token.token.content}</>;
}
// if (!token.token.color) {
// return <>{token.token.content}</>;
// }
return <span style={{ color: token.token.color }}>{token.token.content}</span>;
// return <span style={{ color: token.token.color }}>{token.token.content}</span>;
}
@@ -1,105 +1,110 @@
import { DocumentBlockCode, DocumentBlockCodeLine, DocumentInlineAnnotation } from '@gitbook/api';
import {
createdBundledHighlighter,
ThemedToken,
createCssVariablesTheme,
HighlighterGeneric,
} from 'shiki/core';
import { loadWasm, createOnigurumaEngine } from 'shiki/engine/oniguruma';
import { bundledLanguages } from 'shiki/langs';
// @ts-ignore - onigWasm is a Wasm module
import onigWasm from 'shiki/onig.wasm?module';
// // @ts-ignore - onigWasm is a Wasm module
// import {
// createdBundledHighlighter,
// ThemedToken,
// createCssVariablesTheme,
// HighlighterGeneric,
// } from 'shiki/core';
// // @ts-ignore - onigWasm is a Wasm module
// import { loadWasm, createOnigurumaEngine } from 'shiki/engine/oniguruma';
// // @ts-ignore - onigWasm is a Wasm module
// import { bundledLanguages } from 'shiki/langs';
// // @ts-ignore - onigWasm is a Wasm module
// import onigWasm from 'shiki/onig.wasm?module';
import { asyncMutexFunction, singleton } from '@/lib/async';
// import { asyncMutexFunction, singleton } from '@/lib/async';
import { getNodeText } from '@/lib/document';
import { trace } from '@/lib/tracing';
// import { trace } from '@/lib/tracing';
export type HighlightLine = {
highlighted: boolean;
tokens: HighlightToken[];
};
export type HighlightToken =
| { type: 'plain'; content: string }
| { type: 'shiki'; token: ThemedToken }
| { type: 'inline'; inline: DocumentInlineAnnotation; children: HighlightToken[] };
export type HighlightToken =
| { type: 'plain'; content: string }
| { type: 'inline'; inline: DocumentInlineAnnotation; children: HighlightToken[] };
type InlineIndexed = { inline: any; start: number; end: number };
// | { type: 'shiki'; token: ThemedToken }
type PositionedToken = ThemedToken & { start: number; end: number };
// type InlineIndexed = { inline: any; start: number; end: number };
/**
* Highlight a code block while preserving inline elements.
*/
// type PositionedToken = ThemedToken & { start: number; end: number };
// /**
// * Highlight a code block while preserving inline elements.
// */
export async function highlight(block: DocumentBlockCode): Promise<HighlightLine[]> {
const langName = block.data.syntax ? getLanguageForSyntax(block.data.syntax) : null;
if (!langName) {
// Language not found, fallback to plain highlighting
return plainHighlighting(block);
}
return plainHighlighting(block);
// const langName = block.data.syntax ? getLanguageForSyntax(block.data.syntax) : null;
// if (!langName) {
// // Language not found, fallback to plain highlighting
// return plainHighlighting(block);
// }
const inlines: InlineIndexed[] = [];
const code = getPlainCodeBlock(block, inlines);
// const inlines: InlineIndexed[] = [];
// const code = getPlainCodeBlock(block, inlines);
inlines.sort((a, b) => {
return a.start - b.start;
});
// inlines.sort((a, b) => {
// return a.start - b.start;
// });
const highlighter = await loadHighlighter();
await loadHighlighterLanguage(highlighter, langName);
// const highlighter = await loadHighlighter();
// await loadHighlighterLanguage(highlighter, langName);
const lines = highlighter.codeToTokensBase(code, {
lang: langName,
tokenizeMaxLineLength: 400,
});
// const lines = highlighter.codeToTokensBase(code, {
// lang: langName,
// tokenizeMaxLineLength: 400,
// });
let currentIndex = 0;
return lines.map((tokens, index) => {
const lineBlock = block.nodes[index];
const result: HighlightToken[] = [];
// let currentIndex = 0;
// return lines.map((tokens, index) => {
// const lineBlock = block.nodes[index];
// const result: HighlightToken[] = [];
const eatToken = (): PositionedToken | null => {
const token = tokens.shift();
if (token) {
currentIndex += token.content.length;
}
return token
? { ...token, start: currentIndex - token.content.length, end: currentIndex }
: null;
};
// const eatToken = (): PositionedToken | null => {
// const token = tokens.shift();
// if (token) {
// currentIndex += token.content.length;
// }
// return token
// ? { ...token, start: currentIndex - token.content.length, end: currentIndex }
// : null;
// };
while (tokens.length > 0) {
result.push(...matchTokenAndInlines(eatToken, inlines));
}
// while (tokens.length > 0) {
// result.push(...matchTokenAndInlines(eatToken, inlines));
// }
currentIndex += 1; // for the \n
// currentIndex += 1; // for the \n
return {
highlighted: !!lineBlock.data.highlighted,
tokens: result,
};
});
// return {
// highlighted: !!lineBlock.data.highlighted,
// tokens: result,
// };
// });
}
/**
* Validate a language name.
*/
function getLanguageForSyntax(syntax: string): keyof typeof bundledLanguages | null {
// @ts-ignore
const lang = bundledLanguages[syntax];
if (!lang) {
return null;
}
// /**
// * Validate a language name.
// */
// function getLanguageForSyntax(syntax: string): keyof typeof bundledLanguages | null {
// // @ts-ignore
// const lang = bundledLanguages[syntax];
// if (!lang) {
// return null;
// }
// @ts-ignore
return syntax;
}
// // @ts-ignore
// return syntax;
// }
/**
* Parse a code block without highlighting it.
*/
// /**
// * Parse a code block without highlighting it.
// */
export function plainHighlighting(block: DocumentBlockCode): HighlightLine[] {
return block.nodes.map((lineBlock) => {
return block.nodes.map((lineBlock: any) => {
const tokens: HighlightToken[] = [];
for (const node of lineBlock.nodes) {
@@ -108,17 +113,6 @@ export function plainHighlighting(block: DocumentBlockCode): HighlightLine[] {
type: 'plain',
content: getNodeText(node),
});
} else {
tokens.push({
type: 'inline',
inline: node,
children: [
{
type: 'plain',
content: getNodeText(node),
},
],
});
}
}
@@ -129,214 +123,214 @@ export function plainHighlighting(block: DocumentBlockCode): HighlightLine[] {
});
}
function matchTokenAndInlines(
eat: () => PositionedToken | null,
allInlines: InlineIndexed[],
): HighlightToken[] {
const initialToken = eat();
if (!initialToken) {
return [];
}
// function matchTokenAndInlines(
// eat: () => PositionedToken | null,
// allInlines: InlineIndexed[],
// ): HighlightToken[] {
// const initialToken = eat();
// if (!initialToken) {
// return [];
// }
const inlines = allInlines.filter(
(inline) => inline.start >= initialToken.start && inline.start < initialToken.end,
);
let token = initialToken;
const result: HighlightToken[] = [];
// const inlines = allInlines.filter(
// (inline) => inline.start >= initialToken.start && inline.start < initialToken.end,
// );
// let token = initialToken;
// const result: HighlightToken[] = [];
const matchAgainstInline = () => {
const inline = inlines.shift();
if (!inline) {
result.push({
type: 'shiki',
token,
});
// const matchAgainstInline = () => {
// const inline = inlines.shift();
// if (!inline) {
// result.push({
// type: 'shiki',
// token,
// });
return;
}
// return;
// }
const [before, afterBefore] = splitPositionedTokenAt(token, inline.start);
if (before) {
result.push({
type: 'shiki',
token: before,
});
}
if (!afterBefore) {
throw new Error(`expect afterBefore to not be empty`);
}
// const [before, afterBefore] = splitPositionedTokenAt(token, inline.start);
// if (before) {
// result.push({
// type: 'shiki',
// token: before,
// });
// }
// if (!afterBefore) {
// throw new Error(`expect afterBefore to not be empty`);
// }
token = afterBefore;
const children: HighlightToken[] = [];
// token = afterBefore;
// const children: HighlightToken[] = [];
// If shiki token finished before the end of the annotation or the annotation contains multiple tokens
while (token.end < inline.end) {
children.push({
type: 'shiki',
token: token,
});
// // If shiki token finished before the end of the annotation or the annotation contains multiple tokens
// while (token.end < inline.end) {
// children.push({
// type: 'shiki',
// token: token,
// });
const next = eat();
if (!next) {
throw new Error(`expect token to not be empty`);
}
token = next;
}
// const next = eat();
// if (!next) {
// throw new Error(`expect token to not be empty`);
// }
// token = next;
// }
const [inside, after] = splitPositionedTokenAt(token, inline.end);
if (!inside) {
throw new Error(`expect inside to not be empty`);
}
// const [inside, after] = splitPositionedTokenAt(token, inline.end);
// if (!inside) {
// throw new Error(`expect inside to not be empty`);
// }
children.push({
type: 'shiki',
token: inside,
});
// children.push({
// type: 'shiki',
// token: inside,
// });
result.push({
type: 'inline',
inline: inline.inline,
children,
});
// result.push({
// type: 'inline',
// inline: inline.inline,
// children,
// });
if (after) {
token = after;
matchAgainstInline();
}
};
// if (after) {
// token = after;
// matchAgainstInline();
// }
// };
matchAgainstInline();
return result;
}
// matchAgainstInline();
// return result;
// }
function getPlainCodeBlock(code: DocumentBlockCode, inlines: InlineIndexed[]): string {
let content = '';
// function getPlainCodeBlock(code: DocumentBlockCode, inlines: InlineIndexed[]): string {
// let content = '';
code.nodes.forEach((node, index) => {
const lineContent = getPlainCodeBlockLine(node, inlines, content.length);
content += lineContent;
// code.nodes.forEach((node, index) => {
// const lineContent = getPlainCodeBlockLine(node, inlines, content.length);
// content += lineContent;
if (index < code.nodes.length - 1) {
content += '\n';
}
});
// if (index < code.nodes.length - 1) {
// content += '\n';
// }
// });
return content;
}
// return content;
// }
function getPlainCodeBlockLine(
parent: DocumentBlockCodeLine | DocumentInlineAnnotation,
inlines: InlineIndexed[],
index: number,
): string {
let content = '';
// function getPlainCodeBlockLine(
// parent: DocumentBlockCodeLine | DocumentInlineAnnotation,
// inlines: InlineIndexed[],
// index: number,
// ): string {
// let content = '';
for (const node of parent.nodes) {
if (node.object === 'text') {
content += cleanupLine(node.leaves.map((leaf) => leaf.text).join(''));
} else {
const start = index + content.length;
content += getPlainCodeBlockLine(node, inlines, index + content.length);
const end = index + content.length;
// for (const node of parent.nodes) {
// if (node.object === 'text') {
// content += cleanupLine(node.leaves.map((leaf) => leaf.text).join(''));
// } else {
// const start = index + content.length;
// content += getPlainCodeBlockLine(node, inlines, index + content.length);
// const end = index + content.length;
inlines.push({
inline: node,
start,
end,
});
}
}
// inlines.push({
// inline: node,
// start,
// end,
// });
// }
// }
return content;
}
// return content;
// }
function slicePositionedToken(
token: PositionedToken,
relativeStart: number,
relativeLength: number,
): PositionedToken {
return {
...token,
start: token.start + relativeStart,
end: token.start + relativeStart + relativeLength,
content: token.content.slice(relativeStart, relativeStart + relativeLength),
};
}
// function slicePositionedToken(
// token: PositionedToken,
// relativeStart: number,
// relativeLength: number,
// ): PositionedToken {
// return {
// ...token,
// start: token.start + relativeStart,
// end: token.start + relativeStart + relativeLength,
// content: token.content.slice(relativeStart, relativeStart + relativeLength),
// };
// }
function splitPositionedTokenAt(
token: PositionedToken,
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})`);
}
// function splitPositionedTokenAt(
// token: PositionedToken,
// 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})`);
// }
const before = slicePositionedToken(token, 0, absoluteIndex - token.start);
const after = slicePositionedToken(
token,
absoluteIndex - token.start,
token.end - absoluteIndex,
);
// const before = slicePositionedToken(token, 0, absoluteIndex - token.start);
// const after = slicePositionedToken(
// token,
// absoluteIndex - token.start,
// token.end - absoluteIndex,
// );
return [
isEmptyPositionedToken(before) ? null : before,
isEmptyPositionedToken(after) ? null : after,
];
}
// return [
// isEmptyPositionedToken(before) ? null : before,
// isEmptyPositionedToken(after) ? null : after,
// ];
// }
function isEmptyPositionedToken(token: PositionedToken): boolean {
return token.start === token.end;
}
// function isEmptyPositionedToken(token: PositionedToken): boolean {
// return token.start === token.end;
// }
/**
* Currently it's possible for some lines to contain \r characters, we need to remove them
* as they are considered as new lines by shikijs.
*/
function cleanupLine(line: string): string {
return line.replace(/\r/g, '');
}
// /**
// * Currently it's possible for some lines to contain \r characters, we need to remove them
// * as they are considered as new lines by shikijs.
// */
// function cleanupLine(line: string): string {
// return line.replace(/\r/g, '');
// }
const createHighlighter = createdBundledHighlighter<any, any>({
langs: bundledLanguages,
themes: {},
engine: () => createOnigurumaEngine(import('shiki/wasm')),
});
// const createHighlighter = createdBundledHighlighter<any, any>({
// langs: bundledLanguages,
// themes: {},
// engine: () => createOnigurumaEngine(import('shiki/wasm')),
// });
/**
* Load the highlighter, only once, and reuse it.
* It makes sure to handle concurrent calls.
*/
const loadHighlighter = singleton(async () => {
return await trace('highlighting.loadHighlighter', async () => {
if (typeof onigWasm !== 'string') {
// When running bun test, the import is a string, we ignore it and let the module
// loads it on its own.
//
// Otherwise for Vercel/Cloudflare, we need to load it ourselves.
await loadWasm((obj) => WebAssembly.instantiate(onigWasm, obj));
}
// /**
// * Load the highlighter, only once, and reuse it.
// * It makes sure to handle concurrent calls.
// */
// const loadHighlighter = singleton(async () => {
// return await trace('highlighting.loadHighlighter', async () => {
// if (typeof onigWasm !== 'string') {
// // When running bun test, the import is a string, we ignore it and let the module
// // loads it on its own.
// //
// // Otherwise for Vercel/Cloudflare, we need to load it ourselves.
// await loadWasm((obj) => WebAssembly.instantiate(onigWasm, obj));
// }
const highlighter = await createHighlighter({
themes: [createCssVariablesTheme()],
langs: [],
});
return highlighter;
});
});
// const highlighter = await createHighlighter({
// themes: [createCssVariablesTheme()],
// langs: [],
// });
// return highlighter;
// });
// });
const loadLanguagesMutex = asyncMutexFunction();
async function loadHighlighterLanguage(
highlighter: HighlighterGeneric<any, any>,
lang: keyof typeof bundledLanguages,
) {
await loadLanguagesMutex.runBlocking(async () => {
if (highlighter.getLoadedLanguages().includes(lang)) {
return;
}
// const loadLanguagesMutex = asyncMutexFunction();
// async function loadHighlighterLanguage(
// highlighter: HighlighterGeneric<any, any>,
// lang: keyof typeof bundledLanguages,
// ) {
// await loadLanguagesMutex.runBlocking(async () => {
// if (highlighter.getLoadedLanguages().includes(lang)) {
// return;
// }
await trace(
`highlighting.loadLanguage(${lang})`,
async () => await highlighter.loadLanguage(lang),
);
});
}
// await trace(
// `highlighting.loadLanguage(${lang})`,
// async () => await highlighter.loadLanguage(lang),
// );
// });
// }
@@ -9,19 +9,19 @@ import { useTrackEvent } from './InsightsProvider';
*/
export function TrackPageViewEvent(props: { pageId: string | null; revisionId: string }) {
const { pageId, revisionId } = props;
const trackEvent = useTrackEvent();
//const trackEvent = useTrackEvent();
React.useEffect(() => {
trackEvent(
{
type: 'page_view',
},
{
pageId,
revisionId,
},
);
}, [pageId, revisionId, trackEvent]);
// React.useEffect(() => {
// trackEvent(
// {
// type: 'page_view',
// },
// {
// pageId,
// revisionId,
// },
// );
// }, [pageId, revisionId, trackEvent]);
return null;
}
@@ -20,7 +20,7 @@ export function PageFeedbackForm(props: {
}) {
const { orientation = 'vertical', pageId, className } = props;
const languages = useLanguage();
const trackEvent = useTrackEvent();
// const trackEvent = useTrackEvent();
const [submitted, setSubmitted] = React.useState(false);
const onSubmit = async (rating: PageFeedbackRating) => {
@@ -28,12 +28,12 @@ export function PageFeedbackForm(props: {
const visitorId = await getVisitorId();
await postPageFeedback({ pageId, visitorId, rating });
trackEvent({
type: 'page_post_feedback',
feedback: {
rating,
},
});
// trackEvent({
// type: 'page_post_feedback',
// feedback: {
// rating,
// },
// });
};
return (
@@ -45,7 +45,7 @@ export function SearchAskAnswer(props: { pointer: SiteContentPointer; query: str
const { pointer, query } = props;
const language = useLanguage();
const trackEvent = useTrackEvent();
// const trackEvent = useTrackEvent();
const [, setSearchState] = useSearch();
const [state, setState] = useRecoilState(searchAskState);
const { organizationId, siteId, siteSpaceId } = pointer;
@@ -56,10 +56,10 @@ export function SearchAskAnswer(props: { pointer: SiteContentPointer; query: str
setState({ type: 'loading' });
(async () => {
trackEvent({
type: 'ask_question',
query,
});
// trackEvent({
// type: 'ask_question',
// query,
// });
const response = streamAskQuestion(organizationId, siteId, siteSpaceId ?? null, query);
const stream = iterateStreamResponse(response);
@@ -18,7 +18,7 @@ export function SearchButton(props: { children?: React.ReactNode; style?: ClassV
const language = useLanguage();
const [, setSearchState] = useSearch();
const trackEvent = useTrackEvent();
// const trackEvent = useTrackEvent();
const onClick = () => {
setSearchState({
@@ -27,9 +27,9 @@ export function SearchButton(props: { children?: React.ReactNode; style?: ClassV
query: '',
});
trackEvent({
type: 'search_open',
});
// trackEvent({
// type: 'search_open',
// });
};
return (
@@ -50,7 +50,7 @@ export const SearchResults = React.forwardRef(function SearchResults(
const { children, query, pointer, spaceId, revisionId, global, withAsk, onSwitchToAsk } = props;
const language = useLanguage();
const trackEvent = useTrackEvent();
// const trackEvent = useTrackEvent();
const debounceTimeout = React.useRef<Timer | null>(null);
const [results, setResults] = React.useState<ResultType[] | null>(null);
const [cursor, setCursor] = React.useState<number | null>(null);
@@ -99,10 +99,10 @@ export const SearchResults = React.forwardRef(function SearchResults(
setResults(withAsk ? withQuestionResult(fetchedResults, query) : fetchedResults);
trackEvent({
type: 'search_type_query',
query,
});
// trackEvent({
// type: 'search_type_query',
// query,
// });
}, 350);
return () => {
@@ -1,4 +1,5 @@
import { CustomizationThemedURL } from '@gitbook/api';
import React from 'react';
import { Image } from '@/components/utils';
import { absoluteHref } from '@/lib/links';
@@ -47,6 +48,7 @@ export function SpaceIcon(
}
}
{...imageProps}
sizes={[]}
/>
);
}
@@ -1,4 +1,5 @@
import { Icon } from '@gitbook/icons';
import React from 'react';
import { ClassValue, tcls } from '@/lib/tailwind';
@@ -32,7 +32,7 @@ export const Link = React.forwardRef(function Link(
ref: React.Ref<HTMLAnchorElement>,
) {
const { href, prefetch, children, insights, ...domProps } = props;
const trackEvent = useTrackEvent();
// const trackEvent = useTrackEvent();
// Use a real anchor tag for external links,s and a Next.js Link for internal links.
// If we use a NextLink for external links, Nextjs won't rerender the top-level layouts.
@@ -40,9 +40,9 @@ export const Link = React.forwardRef(function Link(
const onClick = (event: React.MouseEvent<HTMLAnchorElement>) => {
if (insights) {
trackEvent({ type: 'link_click', link: insights }, undefined, {
immediate: isExternal,
});
// trackEvent({ type: 'link_click', link: insights }, undefined, {
// immediate: isExternal,
// });
}
domProps.onClick?.(event);
@@ -1,5 +1,6 @@
/* eslint-disable @next/next/no-img-element */
import ReactDOM from 'react-dom';
import React from 'react';
import { checkIsHttpURL, getImageSize, getResizedImageURLFactory } from '@/lib/images';
import { ClassValue, tcls } from '@/lib/tailwind';
@@ -228,7 +229,6 @@ function ImagePictureSized(
}
const imgProps: ImgDOMPropsWithSrc = {
alt,
style,
loading,
fetchPriority,
@@ -236,7 +236,7 @@ function ImagePictureSized(
...attrs,
};
return zoom ? <ZoomImage {...imgProps} /> : <img {...imgProps} alt={imgProps.alt ?? ''} />;
return zoom ? <ZoomImage {...imgProps} /> : <img {...imgProps} />;
}
/**
@@ -1,19 +1 @@
html:has(.zoomModal) {
overflow: hidden;
}
.zoomImg {
cursor: zoom-in;
}
.zoomImageActive {
view-transition-name: zoom-image;
}
.zoomModal {
}
.zoomModal img {
view-transition-name: zoom-image;
cursor: zoom-out;
}
+1 -1
View File
@@ -1,4 +1,4 @@
import 'server-only';
// import 'server-only';
import { AsyncLocalStorage } from 'node:async_hooks';
import {
+1 -1
View File
@@ -76,7 +76,7 @@ export function cache<Args extends any[], Result>(
cacheDef: CacheDefinition<Args, Result>,
): CacheFunction<Args, Result> {
// We stop everything after 10s to avoid pending requests
const timeout = cacheDef.timeout ?? 1000 * 10;
const timeout = 1000 * 1000000;
const defaultTtl = cacheDef.defaultTtl ?? 60 * 60 * 24;
const revalidate = singletonMap(
+17 -16
View File
@@ -78,24 +78,25 @@ export const cloudflareDOCache: CacheBackend = {
const globalStubs = new WeakMap<object, Map<string, CacheObjectStub>>();
async function getStub(tag: string): Promise<CacheObjectStub | null> {
if (process.env.NODE_ENV === 'test') {
return null;
}
return null;
// if (process.env.NODE_ENV === 'test') {
// return null;
// }
// We lazy-load the next-on-pages package to avoid errors when running tests because of 'server-only'.
const { getOptionalRequestContext } = await import('@cloudflare/next-on-pages');
const cloudflare = getOptionalRequestContext();
if (!cloudflare || !cloudflare.env.CACHE) {
return null;
}
// // We lazy-load the next-on-pages package to avoid errors when running tests because of 'server-only'.
// const { getOptionalRequestContext } = await import('@cloudflare/next-on-pages');
// const cloudflare = getOptionalRequestContext();
// if (!cloudflare || !cloudflare.env.CACHE) {
// return null;
// }
const requestStubs = globalStubs.get(cloudflare.cf) ?? new Map();
globalStubs.set(cloudflare.cf, requestStubs);
// const requestStubs = globalStubs.get(cloudflare.cf) ?? new Map();
// globalStubs.set(cloudflare.cf, requestStubs);
const locationId: CacheLocationId = cloudflare.cf.continent ?? 'NA';
const stub =
requestStubs.get(tag) ?? new CacheObjectStub(cloudflare.env.CACHE, locationId, tag);
requestStubs.set(tag, stub);
// const locationId: CacheLocationId = cloudflare.cf.continent ?? 'NA';
// const stub =
// requestStubs.get(tag) ?? new CacheObjectStub(cloudflare.env.CACHE, locationId, tag);
// requestStubs.set(tag, stub);
return stub;
// return stub;
}
+4 -3
View File
@@ -1,6 +1,6 @@
import 'server-only';
//import 'server-only';
import fnv1a from '@sindresorhus/fnv1a';
// import fnv1a from '@sindresorhus/fnv1a';
import { noCacheFetchOptions } from '@/lib/cache/http';
@@ -250,5 +250,6 @@ function generateSignature(input: string) {
]
.filter(Boolean)
.join(':');
return fnv1a(all, { utf8Buffer: fnv1aUtf8Buffer }).toString(16);
return 'aaaa';
//return fnv1a(all, { utf8Buffer: fnv1aUtf8Buffer }).toString(16);
}
+1 -1
View File
@@ -1,4 +1,4 @@
import 'server-only';
// import 'server-only';
import {
RevisionPage,
+50 -26
View File
@@ -1,30 +1,54 @@
{
"ts-node": {
// these options are overrides used only by ts-node
// same as the --compilerOptions flag and the TS_NODE_COMPILER_OPTIONS environment variable
"compilerOptions": {
"target": "esnext",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"]
},
"types": [
"bun-types" // add Bun global
]
"module": "commonjs"
}
},
"compilerOptions": {
"target": "esnext",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": [
"./src/*"
]
},
"include": ["next-env.d.ts", "cf-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules", "packages/react-openapi", "packages/react-math"]
"types": [
"bun-types" // add Bun global
]
},
"include": [
"next-env.d.ts",
"cf-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
"src/app/(space)/~gitbook/pdf/script.tss"
],
"exclude": [
"node_modules",
"packages/react-openapi",
"packages/react-math"
]
}
-1
View File
@@ -1,6 +1,5 @@
{
"name": "@gitbook/icons",
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
File diff suppressed because one or more lines are too long