mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-11-09 13:12:14 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b06ad7c241 | |||
| 0c51189ce1 |
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'gitbook': patch
|
||||
---
|
||||
|
||||
Fix expandable block anchore resolution
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'gitbook': patch
|
||||
---
|
||||
|
||||
Fix an issue with the cookie banner buttons being non responsive
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'gitbook': patch
|
||||
---
|
||||
|
||||
Update the site header with new styling, a new search button, and refactored layout
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'gitbook': patch
|
||||
---
|
||||
|
||||
Add support for tint color
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@gitbook/cache-do': patch
|
||||
---
|
||||
|
||||
Disable cloudflare observability in production
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'gitbook': patch
|
||||
---
|
||||
|
||||
Update styling of search+ask modal
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'gitbook': patch
|
||||
---
|
||||
|
||||
Fix a regression in variant drop-down caused by missing z-index.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'gitbook': patch
|
||||
---
|
||||
|
||||
Add breadcrumbs above page title
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'gitbook': patch
|
||||
---
|
||||
|
||||
Add scroll margin to the top when there are sections
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'gitbook': patch
|
||||
---
|
||||
|
||||
Smoother tab transition for sections
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'gitbook': minor
|
||||
---
|
||||
|
||||
GitBook Open now supports Ask AI in sites. When asking a question to Ask AI, GitBook will use context from across your site sections and variants to provide the best answer.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'gitbook': minor
|
||||
---
|
||||
|
||||
Fix an issue where the active site section indicator appeared above any dropdowns.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'gitbook': patch
|
||||
---
|
||||
|
||||
Don't adjust fallback font for mono font.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@gitbook/react-openapi': patch
|
||||
---
|
||||
|
||||
Fixed scalar api client routing
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'gitbook': patch
|
||||
---
|
||||
|
||||
Optimize performances by using new API endpoint for fetching site data.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'gitbook': patch
|
||||
---
|
||||
|
||||
Fix margin and image resolution of header logo
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@gitbook/react-openapi': patch
|
||||
---
|
||||
|
||||
Bump @scalar/api-client-react version
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@gitbook/react-openapi': patch
|
||||
---
|
||||
|
||||
Support Integers in Response example
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'gitbook': patch
|
||||
---
|
||||
|
||||
Restyle hint blocks
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'gitbook': patch
|
||||
---
|
||||
|
||||
Fix security issue with image resizing that could be used for phishing
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@gitbook/react-openapi': patch
|
||||
---
|
||||
|
||||
bumped the scalar api client dependency
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@gitbook/react-openapi': patch
|
||||
---
|
||||
|
||||
Bumped scalar api client pacakge
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'gitbook': minor
|
||||
---
|
||||
|
||||
Fix an issue where the space dropdown was shown under the site sections in Safari.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'gitbook': patch
|
||||
---
|
||||
|
||||
Fix - whitespace added to site section tabs with icons.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'gitbook': minor
|
||||
---
|
||||
|
||||
Fix an issue where Ask AI was erroring due to an object being passed as a param.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'gitbook': patch
|
||||
---
|
||||
|
||||
Increase token max length to fix code not highlighted
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'gitbook': patch
|
||||
---
|
||||
|
||||
Add icons to sections
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'gitbook': patch
|
||||
---
|
||||
|
||||
style: adds missing scalar css variables
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'gitbook': minor
|
||||
---
|
||||
|
||||
Fix an issue where the space dropdown could appear behind the header.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'gitbook': minor
|
||||
---
|
||||
|
||||
Fix the styling of site section tabs on smaller screens.
|
||||
@@ -1,11 +1,5 @@
|
||||
# @gitbook/cache-do
|
||||
|
||||
## 0.1.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- b7a5106: Disable cloudflare observability in production
|
||||
|
||||
## 0.1.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
"default": "./dist/api.js"
|
||||
}
|
||||
},
|
||||
"version": "0.1.1",
|
||||
"version": "0.1.0",
|
||||
"dependencies": {
|
||||
"@msgpack/msgpack": "^3.0.0-beta2",
|
||||
"lru_map": "^0.4.1"
|
||||
|
||||
@@ -1,45 +1,5 @@
|
||||
# gitbook
|
||||
|
||||
## 0.5.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- 57cdd25: GitBook Open now supports Ask AI in sites. When asking a question to Ask AI, GitBook will use context from across your site sections and variants to provide the best answer.
|
||||
- ca134c8: Fix an issue where the active site section indicator appeared above any dropdowns.
|
||||
- d48926e: Fix an issue where the space dropdown was shown under the site sections in Safari.
|
||||
- 9fe8142: Fix an issue where Ask AI was erroring due to an object being passed as a param.
|
||||
- d843e5e: Fix an issue where the space dropdown could appear behind the header.
|
||||
- a2e5647: Fix the styling of site section tabs on smaller screens.
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 076dc48: Fix expandable block anchore resolution
|
||||
- d9bb9f9: Fix an issue with the cookie banner buttons being non responsive
|
||||
- 23584c9: Update the site header with new styling, a new search button, and refactored layout
|
||||
- 664debc: Add support for tint color
|
||||
- 4d56f11: Update styling of search+ask modal
|
||||
- 061c0c1: Fix a regression in variant drop-down caused by missing z-index.
|
||||
- 2f76712: Add breadcrumbs above page title
|
||||
- 07cf835: Add scroll margin to the top when there are sections
|
||||
- 5d72b35: Smoother tab transition for sections
|
||||
- 7c71363: Don't adjust fallback font for mono font.
|
||||
- 7675c2c: Optimize performances by using new API endpoint for fetching site data.
|
||||
- 87eea73: Fix margin and image resolution of header logo
|
||||
- aa2ed0f: Restyle hint blocks
|
||||
- ffd3937: Fix security issue with image resizing that could be used for phishing
|
||||
- 2ce59d7: Fix - whitespace added to site section tabs with icons.
|
||||
- c73e07d: Increase token max length to fix code not highlighted
|
||||
- 3b3d6e2: Add icons to sections
|
||||
- 1ed18c0: style: adds missing scalar css variables
|
||||
- Updated dependencies [b7a5106]
|
||||
- Updated dependencies [4771c78]
|
||||
- Updated dependencies [ff50ac2]
|
||||
- Updated dependencies [867481c]
|
||||
- Updated dependencies [7ba67fd]
|
||||
- Updated dependencies [a78c1ec]
|
||||
- @gitbook/cache-do@0.1.1
|
||||
- @gitbook/react-openapi@0.7.1
|
||||
|
||||
## 0.4.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "gitbook",
|
||||
"version": "0.5.0",
|
||||
"version": "0.4.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "env-cmd --silent -f ../../.env.local next dev",
|
||||
|
||||
@@ -13,7 +13,7 @@ export async function HeaderLinks({ children }: HeaderLinksProps) {
|
||||
<div
|
||||
className={tcls(
|
||||
styles.containerHeaderlinks,
|
||||
'grow shrink flex justify-end items-center gap-x-6 lg:gap-x-8 min-w-9 z-20',
|
||||
'grow shrink flex justify-end items-center gap-x-6 min-w-9 z-20',
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
|
||||
@@ -25,10 +25,6 @@ export function HighlightQuery(props: {
|
||||
'py-0.5',
|
||||
'rounded',
|
||||
'straight-corners:rounded-sm',
|
||||
'group-[.is-active]:bg-primary-200',
|
||||
'group-[.is-active]:text-contrast-primary-200',
|
||||
'dark:group-[.is-active]:bg-primary-700',
|
||||
'dark:group-[.is-active]:text-contrast-primary-700',
|
||||
],
|
||||
} = props;
|
||||
const matches = matchString(text, query);
|
||||
|
||||
@@ -55,6 +55,10 @@ export function SearchModal(props: SearchModalProps) {
|
||||
};
|
||||
}, [isSearchOpened]);
|
||||
|
||||
// if (state === null) {
|
||||
// return null;
|
||||
// }
|
||||
|
||||
const onChangeQuery = (newQuery: SearchState) => {
|
||||
setSearchState(newQuery);
|
||||
};
|
||||
@@ -166,21 +170,10 @@ function SearchModalBody(
|
||||
inputRef.current?.focus();
|
||||
}, []);
|
||||
|
||||
React.useEffect(() => {
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
const onKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
|
||||
if (event.key === 'Escape') {
|
||||
onClose();
|
||||
}
|
||||
};
|
||||
document.addEventListener('keydown', handleKeyDown);
|
||||
|
||||
return () => {
|
||||
document.removeEventListener('keydown', handleKeyDown);
|
||||
};
|
||||
}, [onClose]);
|
||||
|
||||
const onKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
|
||||
if (event.key === 'ArrowUp') {
|
||||
} else if (event.key === 'ArrowUp') {
|
||||
event.preventDefault();
|
||||
resultsRef.current?.moveUp();
|
||||
} else if (event.key === 'ArrowDown') {
|
||||
|
||||
@@ -23,38 +23,26 @@ export const SearchPageResultItem = React.forwardRef(function SearchPageResultIt
|
||||
href={item.href}
|
||||
className={tcls(
|
||||
'flex',
|
||||
'gap-4',
|
||||
'flex-row',
|
||||
'items-center',
|
||||
'p-4',
|
||||
'px-4',
|
||||
'sm:px-12',
|
||||
'py-4',
|
||||
'sm:py-6',
|
||||
'border-t',
|
||||
'first:border-t-0',
|
||||
'border-dark/2',
|
||||
'dark:border-light/1',
|
||||
'first:border-none',
|
||||
'dark:border-light/2',
|
||||
'hover:bg-dark-4/2',
|
||||
'text-base',
|
||||
'text-dark',
|
||||
'font-medium',
|
||||
'hover:bg-dark/1',
|
||||
'dark:hover:bg-light/1',
|
||||
'group',
|
||||
active
|
||||
? [
|
||||
'is-active',
|
||||
'bg-primary-50',
|
||||
'text-contrast-primary-50',
|
||||
'dark:bg-primary-800',
|
||||
'dark:text-contrast-primary-800',
|
||||
'hover:bg-primary-100/8',
|
||||
'dark:hover:bg-primary-700/7',
|
||||
]
|
||||
: null,
|
||||
'first:mt-0',
|
||||
'dark:text-light',
|
||||
'dark:hover:bg-light-4/2',
|
||||
active ? ['bg-dark/1', 'dark:bg-light/1'] : null,
|
||||
)}
|
||||
>
|
||||
<div className="size-4">
|
||||
<Icon
|
||||
icon="file-lines"
|
||||
className={tcls('size-4', active ? 'text-primary' : 'opacity-5')}
|
||||
/>
|
||||
</div>
|
||||
<div className={tcls('flex', 'flex-col', 'w-full')}>
|
||||
{item.spaceTitle ? (
|
||||
<div
|
||||
@@ -72,19 +60,10 @@ export const SearchPageResultItem = React.forwardRef(function SearchPageResultIt
|
||||
) : null}
|
||||
<HighlightQuery query={query} text={item.title} />
|
||||
</div>
|
||||
<div
|
||||
className={tcls(
|
||||
'p-2',
|
||||
'rounded',
|
||||
'straight-corners:rounded-none',
|
||||
active ? ['bg-primary', 'text-contrast-primary'] : ['opacity-6'],
|
||||
)}
|
||||
>
|
||||
<Icon
|
||||
icon={active ? 'arrow-turn-down-left' : 'chevron-right'}
|
||||
className={tcls('size-4')}
|
||||
icon="chevron-right"
|
||||
className={tcls('size-4', 'text-dark', 'dark:text-light', 'opacity-6')}
|
||||
/>
|
||||
</div>
|
||||
</Link>
|
||||
);
|
||||
});
|
||||
|
||||
@@ -26,21 +26,16 @@ export const SearchQuestionResultItem = React.forwardRef(function SearchQuestion
|
||||
onClick={onClick}
|
||||
className={tcls(
|
||||
'flex',
|
||||
'flex-row',
|
||||
'px-4',
|
||||
recommended ? ['py-2', 'text-dark/7', 'dark:text-light/8'] : 'py-4',
|
||||
'hover:bg-dark/1',
|
||||
'dark:hover:bg-light/1',
|
||||
'py-2',
|
||||
'hover:bg-dark-4/2',
|
||||
'text-dark/7',
|
||||
'first:mt-0',
|
||||
'last:pb-3',
|
||||
active && [
|
||||
'is-active',
|
||||
'bg-primary-50',
|
||||
'text-contrast-primary-50',
|
||||
'dark:bg-primary-800',
|
||||
'dark:text-contrast-primary-800',
|
||||
'hover:bg-primary-100/8',
|
||||
'dark:hover:bg-primary-700/7',
|
||||
],
|
||||
'dark:text-light/8',
|
||||
'dark:hover:bg-light-4/2',
|
||||
active ? ['bg-dark/1', 'dark:bg-light/1'] : null,
|
||||
)}
|
||||
{...getLinkProp({
|
||||
ask: true,
|
||||
@@ -48,41 +43,18 @@ export const SearchQuestionResultItem = React.forwardRef(function SearchQuestion
|
||||
})}
|
||||
>
|
||||
<Icon
|
||||
icon={recommended ? 'search' : 'sparkles'}
|
||||
icon="magnifying-glass"
|
||||
className={tcls(
|
||||
'size-4',
|
||||
'shrink-0',
|
||||
'mt-1.5',
|
||||
'mt-0.5',
|
||||
'mr-4',
|
||||
active ? ['text-primary'] : ['text-dark/5', 'dark:text-light/5'],
|
||||
'mt-1',
|
||||
'text-dark/5',
|
||||
'dark:text-light/5',
|
||||
)}
|
||||
/>
|
||||
<div className="w-full">
|
||||
{recommended ? (
|
||||
question
|
||||
) : (
|
||||
<>
|
||||
<div className="font-medium">{t(language, 'search_ask', [question])}</div>
|
||||
<div className={tcls('text-sm', 'text-dark/8', 'dark:text-light/8')}>
|
||||
{t(language, 'search_ask_description')}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<div
|
||||
className={tcls(
|
||||
'p-2',
|
||||
'rounded',
|
||||
'self-center',
|
||||
'straight-corners:rounded-none',
|
||||
active ? ['bg-primary', 'text-contrast-primary'] : ['opacity-6'],
|
||||
)}
|
||||
>
|
||||
<Icon
|
||||
icon={active ? 'arrow-turn-down-left' : 'chevron-right'}
|
||||
className={tcls('size-4')}
|
||||
/>
|
||||
</div>
|
||||
{recommended ? question : t(language, 'search_ask', [question])}
|
||||
</Link>
|
||||
);
|
||||
});
|
||||
|
||||
@@ -5,6 +5,7 @@ import { t, useLanguage } from '@/intl/client';
|
||||
import { SiteContentPointer } from '@/lib/api';
|
||||
import { tcls } from '@/lib/tailwind';
|
||||
|
||||
import { isQuestion } from './isQuestion';
|
||||
import { SearchPageResultItem } from './SearchPageResultItem';
|
||||
import { SearchQuestionResultItem } from './SearchQuestionResultItem';
|
||||
import { SearchSectionResultItem } from './SearchSectionResultItem';
|
||||
@@ -91,6 +92,8 @@ export const SearchResults = React.forwardRef(function SearchResults(
|
||||
}
|
||||
|
||||
debounceTimeout.current = setTimeout(async () => {
|
||||
setCursor(null);
|
||||
|
||||
const fetchedResults = await (global
|
||||
? searchAllSiteContent(query, pointer)
|
||||
: searchSiteSpaceContent(query, pointer, revisionId));
|
||||
@@ -107,16 +110,6 @@ export const SearchResults = React.forwardRef(function SearchResults(
|
||||
}
|
||||
}, [query, global, pointer, spaceId, revisionId, withAsk]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!query) {
|
||||
// Reset the cursor when there's no query
|
||||
setCursor(null);
|
||||
} else if (results && results.length > 0) {
|
||||
// Auto-focus the first result
|
||||
setCursor(0);
|
||||
}
|
||||
}, [results, query]);
|
||||
|
||||
// Scroll to the active result.
|
||||
React.useEffect(() => {
|
||||
if (cursor === null || !refs.current[cursor]) {
|
||||
@@ -263,13 +256,10 @@ export const SearchResults = React.forwardRef(function SearchResults(
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* Add a "Ask <question>" item at the top of the results list.
|
||||
*/
|
||||
function withQuestionResult(results: null | ResultType[], query: string): null | ResultType[] {
|
||||
const without = results ? results.filter((result) => result.type !== 'question') : null;
|
||||
|
||||
if (query.length === 0) {
|
||||
if (!isQuestion(query)) {
|
||||
return without;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Icon } from '@gitbook/icons';
|
||||
import React from 'react';
|
||||
|
||||
import { tcls } from '@/lib/tailwind';
|
||||
@@ -22,39 +21,27 @@ export const SearchSectionResultItem = React.forwardRef(function SearchSectionRe
|
||||
ref={ref}
|
||||
href={item.href}
|
||||
className={tcls(
|
||||
'search-section-result-item',
|
||||
'[&:has(+:not(&))]:mb-6',
|
||||
'flex',
|
||||
'items-center',
|
||||
'pl-6',
|
||||
'sm:pl-12',
|
||||
'pr-4',
|
||||
'flex-col',
|
||||
'mb-2',
|
||||
'px-4',
|
||||
'sm:px-12',
|
||||
'hover:bg-dark-4/2',
|
||||
'dark:hover:bg-light-4/2',
|
||||
'text-dark/8',
|
||||
'dark:text-light/8',
|
||||
'hover:bg-dark/1',
|
||||
'dark:hover:bg-light/1',
|
||||
'font-normal',
|
||||
'py-2',
|
||||
'group',
|
||||
active && [
|
||||
'is-active',
|
||||
'bg-primary-50',
|
||||
'text-contrast-primary-50',
|
||||
'dark:bg-primary-800',
|
||||
'dark:text-contrast-primary-800',
|
||||
'hover:bg-primary-100/8',
|
||||
'dark:hover:bg-primary-700/7',
|
||||
],
|
||||
'transition-colors',
|
||||
active ? ['bg-dark/1', 'dark:bg-light/1'] : null,
|
||||
)}
|
||||
>
|
||||
<div
|
||||
className={tcls(
|
||||
'border-l-2',
|
||||
'px-4',
|
||||
'py-1',
|
||||
'flex',
|
||||
'flex-1',
|
||||
'overflow-hidden',
|
||||
'flex-col',
|
||||
'py-2',
|
||||
'border-dark/2',
|
||||
'dark:border-light/2',
|
||||
)}
|
||||
@@ -70,20 +57,6 @@ export const SearchSectionResultItem = React.forwardRef(function SearchSectionRe
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
<div
|
||||
className={tcls(
|
||||
'p-2',
|
||||
'rounded',
|
||||
'straight-corners:rounded-none',
|
||||
'bg-primary',
|
||||
'text-contrast-primary',
|
||||
'hidden',
|
||||
'sm:block',
|
||||
active ? ['opacity-11', 'block'] : ['opacity-0'],
|
||||
)}
|
||||
>
|
||||
<Icon icon="arrow-turn-down-left" className={tcls('size-4')} />
|
||||
</div>
|
||||
</Link>
|
||||
);
|
||||
});
|
||||
|
||||
@@ -35,7 +35,6 @@ export function Button({
|
||||
]
|
||||
: // SECONDARY
|
||||
[
|
||||
'bg-dark/2',
|
||||
'ring-dark/1',
|
||||
'hover:bg-dark/3',
|
||||
'dark:bg-light/2',
|
||||
|
||||
@@ -13,7 +13,6 @@ export const de = {
|
||||
search_scope_space: '${1}',
|
||||
search_scope_all: 'Alle Inhalte',
|
||||
search_ask: 'Fragen "${1}"',
|
||||
search_ask_description: 'Finden Sie die Antwort mit AI',
|
||||
search_ask_sources: 'Quellen',
|
||||
search_ask_sources_no_answer: 'Verwandte Seiten',
|
||||
search_ask_no_answer:
|
||||
|
||||
@@ -13,7 +13,6 @@ export const en = {
|
||||
search_scope_space: '${1}',
|
||||
search_scope_all: 'All content',
|
||||
search_ask: 'Ask "${1}"',
|
||||
search_ask_description: 'Find the answer with AI',
|
||||
search_ask_sources: 'Sources',
|
||||
search_ask_sources_no_answer: 'Related pages',
|
||||
search_ask_no_answer:
|
||||
|
||||
@@ -15,7 +15,6 @@ export const es: TranslationLanguage = {
|
||||
search_scope_space: '${1}',
|
||||
search_scope_all: 'Todo el contenido',
|
||||
search_ask: 'Preguntar "${1}"',
|
||||
search_ask_description: 'Encuentra la respuesta con IA',
|
||||
search_ask_sources: 'Fuentes',
|
||||
search_ask_sources_no_answer: 'Páginas relacionadas',
|
||||
search_ask_no_answer:
|
||||
|
||||
@@ -15,7 +15,6 @@ export const fr: TranslationLanguage = {
|
||||
search_scope_space: '${1}',
|
||||
search_scope_all: 'Tout le contenu',
|
||||
search_ask: 'Demander "${1}"',
|
||||
search_ask_description: "Trouvez la réponse avec l'IA",
|
||||
search_ask_sources: 'Sources',
|
||||
search_ask_sources_no_answer: 'Pages connexes',
|
||||
search_ask_no_answer:
|
||||
|
||||
@@ -15,7 +15,6 @@ export const ja: TranslationLanguage = {
|
||||
search_scope_space: '${1}',
|
||||
search_scope_all: '全てのコンテンツ',
|
||||
search_ask: '"${1}" を質問する',
|
||||
search_ask_description: 'AIで答えを見つける',
|
||||
search_ask_sources: '情報源',
|
||||
search_ask_sources_no_answer: '関連ページ',
|
||||
search_ask_no_answer:
|
||||
|
||||
@@ -15,7 +15,6 @@ export const nl: TranslationLanguage = {
|
||||
search_scope_space: '${1}',
|
||||
search_scope_all: 'Alle inhoud',
|
||||
search_ask: 'Vraag "${1}"',
|
||||
search_ask_description: 'Vind het antwoord met AI',
|
||||
search_ask_sources: 'Bronnen',
|
||||
search_ask_sources_no_answer: 'Gerelateerde pagina’s',
|
||||
search_ask_no_answer:
|
||||
|
||||
@@ -15,7 +15,6 @@ export const no: TranslationLanguage = {
|
||||
search_scope_space: '${1}',
|
||||
search_scope_all: 'Alt innhold',
|
||||
search_ask: 'Spør "${1}"',
|
||||
search_ask_description: 'Finn svaret med AI',
|
||||
search_ask_sources: 'Kilder',
|
||||
search_ask_sources_no_answer: 'Relaterte sider',
|
||||
search_ask_no_answer:
|
||||
|
||||
@@ -13,7 +13,6 @@ export const pt_br = {
|
||||
search_scope_space: '${1}',
|
||||
search_scope_all: 'Todo o conteúdo',
|
||||
search_ask: 'Perguntar "${1}"',
|
||||
search_ask_description: 'Encontre a resposta com IA',
|
||||
search_ask_sources: 'Fontes',
|
||||
search_ask_sources_no_answer: 'Páginas relacionadas',
|
||||
search_ask_no_answer:
|
||||
|
||||
@@ -15,7 +15,6 @@ export const zh: TranslationLanguage = {
|
||||
search_scope_space: '${1}',
|
||||
search_scope_all: '所有内容',
|
||||
search_ask: '询问"${1}"',
|
||||
search_ask_description: '利用人工智能找到答案',
|
||||
search_ask_sources: '来源',
|
||||
search_ask_sources_no_answer: '相关页面',
|
||||
search_ask_no_answer: '无法找到您的问题的答案。您可以尝试改述问题或提供更具体的信息。',
|
||||
|
||||
@@ -44,12 +44,6 @@ type URLLookupMode =
|
||||
* This mode is useful when self-hosting a single space.
|
||||
*/
|
||||
| 'single'
|
||||
/**
|
||||
* Mode when a site is being proxied on a different base URL.
|
||||
* - x-gitbook-site-url is used to determine the site to serve.
|
||||
* - host / x-forwarded-host / x-gitbook-host + x-gitbook-basepath is used to determine the base URL.
|
||||
*/
|
||||
| 'proxy'
|
||||
/**
|
||||
* Spaces are located using the incoming URL (using forwarded host headers).
|
||||
* This mode is the default one when serving on the GitBook infrastructure.
|
||||
@@ -83,14 +77,11 @@ export type LookupResult = PublishedContentWithCache & {
|
||||
};
|
||||
|
||||
/**
|
||||
* Middleware to lookup the site to render.
|
||||
* Middleware to lookup the space to render.
|
||||
* It takes as input a request with an URL, and a set of headers:
|
||||
* - x-gitbook-api: the API endpoint to use, if undefined, the default one is used
|
||||
* - x-gitbook-basepath: base in the path that should be ignored for routing
|
||||
*
|
||||
* Once the site has been looked-up, the middleware passes the info to the rendering
|
||||
* using a rewrite with a set of headers. This is the only way in next.js to do this (basically similar to AsyncLocalStorage).
|
||||
*
|
||||
* The middleware also takes care of persisting the visitor authentication state.
|
||||
*/
|
||||
export async function middleware(request: NextRequest) {
|
||||
@@ -115,7 +106,7 @@ export async function middleware(request: NextRequest) {
|
||||
let apiEndpoint = request.headers.get('x-gitbook-api') ?? DEFAULT_API_ENDPOINT;
|
||||
const originBasePath = request.headers.get('x-gitbook-basepath') ?? '';
|
||||
|
||||
const inputURL = mode === 'proxy' ? url : stripURLBasePath(url, originBasePath);
|
||||
const inputURL = stripURLBasePath(url, originBasePath);
|
||||
|
||||
const resolved = await withAPI(
|
||||
{
|
||||
@@ -126,7 +117,7 @@ export async function middleware(request: NextRequest) {
|
||||
}),
|
||||
contextId: undefined,
|
||||
},
|
||||
() => lookupSiteForURL(mode, request, inputURL),
|
||||
() => lookupSpaceForURL(mode, request, inputURL),
|
||||
);
|
||||
if ('error' in resolved) {
|
||||
return new NextResponse(resolved.error.message, {
|
||||
@@ -220,10 +211,7 @@ export async function middleware(request: NextRequest) {
|
||||
}
|
||||
headers.set('x-gitbook-mode', mode);
|
||||
headers.set('x-gitbook-origin-basepath', originBasePath);
|
||||
headers.set(
|
||||
'x-gitbook-basepath',
|
||||
mode === 'proxy' ? originBasePath : joinPath(originBasePath, resolved.basePath),
|
||||
);
|
||||
headers.set('x-gitbook-basepath', joinPath(originBasePath, resolved.basePath));
|
||||
headers.set('x-gitbook-content-space', resolved.space);
|
||||
if ('site' in resolved) {
|
||||
headers.set('x-gitbook-content-organization', resolved.organization);
|
||||
@@ -314,10 +302,7 @@ export async function middleware(request: NextRequest) {
|
||||
/**
|
||||
* Compute the input URL the user is trying to access.
|
||||
*/
|
||||
function getInputURL(request: NextRequest): {
|
||||
url: URL;
|
||||
mode: URLLookupMode;
|
||||
} {
|
||||
function getInputURL(request: NextRequest): { url: URL; mode: URLLookupMode } {
|
||||
const url = new URL(request.url);
|
||||
let mode: URLLookupMode =
|
||||
(process.env.GITBOOK_MODE as URLLookupMode | undefined) ?? 'multi-path';
|
||||
@@ -347,36 +332,27 @@ function getInputURL(request: NextRequest): {
|
||||
mode = 'multi-id';
|
||||
}
|
||||
|
||||
// When passing a x-gitbook-site-url header, this URL is used instead of the request URL
|
||||
// to determine the site to serve.
|
||||
const xGitbookSite = request.headers.get('x-gitbook-site-url');
|
||||
if (xGitbookSite) {
|
||||
mode = 'proxy';
|
||||
}
|
||||
|
||||
return { url, mode };
|
||||
}
|
||||
|
||||
async function lookupSiteForURL(
|
||||
async function lookupSpaceForURL(
|
||||
mode: URLLookupMode,
|
||||
request: NextRequest,
|
||||
url: URL,
|
||||
): Promise<LookupResult> {
|
||||
switch (mode) {
|
||||
case 'single': {
|
||||
return await lookupSiteInSingleMode(url);
|
||||
return await lookupSpaceInSingleMode(url);
|
||||
}
|
||||
case 'multi': {
|
||||
return await lookupSiteInMultiMode(request, url);
|
||||
return await lookupSpaceInMultiMode(request, url);
|
||||
}
|
||||
case 'multi-path': {
|
||||
return await lookupSiteInMultiPathMode(request, url);
|
||||
return await lookupSpaceInMultiPathMode(request, url);
|
||||
}
|
||||
case 'multi-id': {
|
||||
return await lookupSiteOrSpaceInMultiIdMode(request, url);
|
||||
}
|
||||
case 'proxy':
|
||||
return await lookupSiteInProxy(request, url);
|
||||
default:
|
||||
assertNever(mode);
|
||||
}
|
||||
@@ -386,7 +362,7 @@ async function lookupSiteForURL(
|
||||
* GITBOOK_MODE=single
|
||||
* When serving a single space, configured using GITBOOK_SPACE_ID and GITBOOK_TOKEN.
|
||||
*/
|
||||
async function lookupSiteInSingleMode(url: URL): Promise<LookupResult> {
|
||||
async function lookupSpaceInSingleMode(url: URL): Promise<LookupResult> {
|
||||
const spaceId = process.env.GITBOOK_SPACE_ID;
|
||||
if (!spaceId) {
|
||||
throw new Error(
|
||||
@@ -410,31 +386,13 @@ async function lookupSiteInSingleMode(url: URL): Promise<LookupResult> {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* GITBOOK_MODE=proxy
|
||||
* When proxying a site on a different base URL.
|
||||
*/
|
||||
async function lookupSiteInProxy(request: NextRequest, url: URL): Promise<LookupResult> {
|
||||
const rawSiteUrl = request.headers.get('x-gitbook-site-url');
|
||||
if (!rawSiteUrl) {
|
||||
throw new Error(
|
||||
`Missing x-gitbook-site-url header. It should be passed when using GITBOOK_MODE=proxy.`,
|
||||
);
|
||||
}
|
||||
|
||||
const siteUrl = new URL(rawSiteUrl);
|
||||
siteUrl.pathname = joinPath(siteUrl.pathname, url.pathname);
|
||||
|
||||
return await lookupSiteInMultiMode(request, siteUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* GITBOOK_MODE=multi
|
||||
* When serving multi spaces based on the current URL.
|
||||
*/
|
||||
async function lookupSiteInMultiMode(request: NextRequest, url: URL): Promise<LookupResult> {
|
||||
async function lookupSpaceInMultiMode(request: NextRequest, url: URL): Promise<LookupResult> {
|
||||
const visitorAuthToken = getVisitorAuthToken(request, url);
|
||||
const lookup = await lookupSiteByAPI(url, visitorAuthToken);
|
||||
const lookup = await lookupSpaceByAPI(url, visitorAuthToken);
|
||||
return {
|
||||
...lookup,
|
||||
...('basePath' in lookup && visitorAuthToken
|
||||
@@ -599,7 +557,7 @@ async function lookupSiteOrSpaceInMultiIdMode(
|
||||
* GITBOOK_MODE=multi-path
|
||||
* When serving multi spaces with the url passed in the path.
|
||||
*/
|
||||
async function lookupSiteInMultiPathMode(request: NextRequest, url: URL): Promise<LookupResult> {
|
||||
async function lookupSpaceInMultiPathMode(request: NextRequest, url: URL): Promise<LookupResult> {
|
||||
// Skip useless requests
|
||||
if (
|
||||
url.pathname === '/favicon.ico' ||
|
||||
@@ -638,7 +596,7 @@ async function lookupSiteInMultiPathMode(request: NextRequest, url: URL): Promis
|
||||
|
||||
const visitorAuthToken = getVisitorAuthToken(request, target);
|
||||
|
||||
const lookup = await lookupSiteByAPI(target, visitorAuthToken);
|
||||
const lookup = await lookupSpaceByAPI(target, visitorAuthToken);
|
||||
if ('error' in lookup) {
|
||||
return lookup;
|
||||
}
|
||||
@@ -674,7 +632,7 @@ async function lookupSiteInMultiPathMode(request: NextRequest, url: URL): Promis
|
||||
* Lookup a space by its URL using the GitBook API.
|
||||
* To optimize caching, we try multiple lookup alternatives and return the first one that matches.
|
||||
*/
|
||||
async function lookupSiteByAPI(
|
||||
async function lookupSpaceByAPI(
|
||||
lookupURL: URL,
|
||||
visitorAuthToken: ReturnType<typeof getVisitorAuthToken>,
|
||||
): Promise<LookupResult> {
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
dist/
|
||||
@@ -1,7 +0,0 @@
|
||||
# @gitbook/proxy
|
||||
|
||||
## 0.1.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- 53b9f10: First version
|
||||
@@ -1,28 +0,0 @@
|
||||
# `@gitbook/proxy`
|
||||
|
||||
Host a GitBook site on your own domain as a subpath.
|
||||
|
||||
## Usage
|
||||
|
||||
```ts
|
||||
import { proxyToGitBook } from '@gitbook/proxy';
|
||||
|
||||
const site = proxyToGitBook(event.request, {
|
||||
site: 'mycompany.gitbook.io/site/',
|
||||
basePath: '/docs',
|
||||
});
|
||||
|
||||
export default {
|
||||
async fetch(request) {
|
||||
// If the requst matches the basePath /docs, we serve from GitBook
|
||||
if (site.match(request)) {
|
||||
return site.fetch(request);
|
||||
}
|
||||
|
||||
// Otherwise we do something else.
|
||||
return new Response('Not found', {
|
||||
statusCode: 404,
|
||||
});
|
||||
},
|
||||
};
|
||||
```
|
||||
@@ -1,28 +0,0 @@
|
||||
{
|
||||
"name": "@gitbook/proxy",
|
||||
"description": "Host a GitBook site on your own domain as a subpath",
|
||||
"version": "0.1.0",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"development": "./src/index.ts",
|
||||
"default": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.5.3"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"clean": "rm -rf ./dist",
|
||||
"unit": "bun test"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"src",
|
||||
"README.md",
|
||||
"CHANGELOG.md"
|
||||
]
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
import { describe, expect, it } from 'bun:test';
|
||||
import { proxyToGitBook } from '.';
|
||||
|
||||
describe('.match', () => {
|
||||
it('should return true if the request is below the base path', () => {
|
||||
const site = proxyToGitBook({ site: 'https://org.gitbook.io/example/', basePath: '/docs' });
|
||||
expect(site.match('/docs')).toBe(true);
|
||||
expect(site.match('/docs/')).toBe(true);
|
||||
expect(site.match('/docs/hello')).toBe(true);
|
||||
expect(site.match('/docs/hello/world')).toBe(true);
|
||||
|
||||
expect(site.match('/hello/world')).toBe(false);
|
||||
expect(site.match('/')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.request', () => {
|
||||
it('should compute a proper request for a sub-path', () => {
|
||||
const site = proxyToGitBook({ site: 'https://org.gitbook.io/example/', basePath: '/docs' });
|
||||
const request = new Request('https://example.com/docs/hello/world');
|
||||
|
||||
const proxiedRequest = site.request(request);
|
||||
expect(proxiedRequest.url).toBe('https://hosting.gitbook.io/docs/hello/world');
|
||||
expect(proxiedRequest.headers.get('Host')).toBe('hosting.gitbook.io');
|
||||
expect(proxiedRequest.headers.get('X-Forwarded-Host')).toBe('example.com');
|
||||
expect(proxiedRequest.headers.get('X-GitBook-BasePath')).toBe('/docs');
|
||||
expect(proxiedRequest.headers.get('X-GitBook-Site-URL')).toBe(
|
||||
'https://org.gitbook.io/example/',
|
||||
);
|
||||
});
|
||||
|
||||
it('should compute a proper request on the root', () => {
|
||||
const site = proxyToGitBook({ site: 'https://org.gitbook.io/example/', basePath: '/docs' });
|
||||
const request = new Request('https://example.com/docs');
|
||||
|
||||
const proxiedRequest = site.request(request);
|
||||
expect(proxiedRequest.url).toBe('https://hosting.gitbook.io/docs');
|
||||
expect(proxiedRequest.headers.get('Host')).toBe('hosting.gitbook.io');
|
||||
expect(proxiedRequest.headers.get('X-Forwarded-Host')).toBe('example.com');
|
||||
expect(proxiedRequest.headers.get('X-GitBook-BasePath')).toBe('/docs');
|
||||
expect(proxiedRequest.headers.get('X-GitBook-Site-URL')).toBe(
|
||||
'https://org.gitbook.io/example/',
|
||||
);
|
||||
});
|
||||
|
||||
it('should normalize the basepath', () => {
|
||||
const site = proxyToGitBook({ site: 'https://org.gitbook.io/example/', basePath: 'docs/' });
|
||||
const request = new Request('https://example.com/docs/hello/world');
|
||||
|
||||
const proxiedRequest = site.request(request);
|
||||
expect(proxiedRequest.url).toBe('https://hosting.gitbook.io/docs/hello/world');
|
||||
expect(proxiedRequest.headers.get('Host')).toBe('hosting.gitbook.io');
|
||||
expect(proxiedRequest.headers.get('X-Forwarded-Host')).toBe('example.com');
|
||||
expect(proxiedRequest.headers.get('X-GitBook-BasePath')).toBe('/docs');
|
||||
expect(proxiedRequest.headers.get('X-GitBook-Site-URL')).toBe(
|
||||
'https://org.gitbook.io/example/',
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,97 +0,0 @@
|
||||
export interface ProxyToGitBookOptions {
|
||||
/**
|
||||
* The URL of the published site.
|
||||
* @example "https://mycompany.gitbook.io/docs"
|
||||
*/
|
||||
site: string;
|
||||
|
||||
/**
|
||||
* Base path to serve the site on.
|
||||
* @example "/docs"
|
||||
*/
|
||||
basePath: string;
|
||||
|
||||
/**
|
||||
* Hostname used by GitBook to serve content.
|
||||
* Do not set this option unless you know what you are doing.
|
||||
*/
|
||||
gitbookHost?: string;
|
||||
}
|
||||
|
||||
export interface ProxySite {
|
||||
/**
|
||||
* Test if the request should be proxied to this site.
|
||||
*/
|
||||
match(request: Request | string): boolean;
|
||||
|
||||
/**
|
||||
* Get the proxied request for a given request.
|
||||
*/
|
||||
request(request: Request): Request;
|
||||
|
||||
/**
|
||||
* Fetch the request from the site.
|
||||
*/
|
||||
fetch(request: Request): Promise<Response>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxies requests to a GitBook site.
|
||||
*/
|
||||
export function proxyToGitBook(options: ProxyToGitBookOptions): ProxySite {
|
||||
const { gitbookHost = 'hosting.gitbook.io' } = options;
|
||||
|
||||
const siteUrl = new URL(options.site);
|
||||
const rawSiteUrl = siteUrl.toString();
|
||||
|
||||
const basePath = normalizeBasePath(options.basePath);
|
||||
|
||||
const site: ProxySite = {
|
||||
match: (request) => {
|
||||
const pathname = typeof request === 'string' ? request : new URL(request.url).pathname;
|
||||
return pathname === basePath || pathname.startsWith(basePath + '/');
|
||||
},
|
||||
|
||||
request: (originRequest) => {
|
||||
const originUrl = new URL(originRequest.url);
|
||||
|
||||
const url = new URL(originUrl);
|
||||
url.hostname = gitbookHost;
|
||||
|
||||
const proxyRequest = new Request(url, originRequest);
|
||||
proxyRequest.headers.set('Host', gitbookHost);
|
||||
|
||||
// Pass the original host and protocol
|
||||
proxyRequest.headers.set('X-Forwarded-Host', originUrl.hostname);
|
||||
proxyRequest.headers.set('X-Forwarded-Proto', 'https');
|
||||
|
||||
// Pass the basepath on the original URL
|
||||
proxyRequest.headers.set('X-GitBook-BasePath', basePath);
|
||||
|
||||
// Pass the site URL
|
||||
proxyRequest.headers.set('X-GitBook-Site-URL', rawSiteUrl);
|
||||
|
||||
return proxyRequest;
|
||||
},
|
||||
|
||||
fetch: async (originRequest) => {
|
||||
return fetch(site.request(originRequest));
|
||||
},
|
||||
};
|
||||
|
||||
return site;
|
||||
}
|
||||
|
||||
function normalizeBasePath(basePath: string): string {
|
||||
let result = withLeadingSlash(basePath);
|
||||
result = withoutTrailingSlash(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
function withLeadingSlash(path: string): string {
|
||||
return path.startsWith('/') ? path : '/' + path;
|
||||
}
|
||||
|
||||
function withoutTrailingSlash(path: string): string {
|
||||
return path.endsWith('/') ? path.slice(0, -1) : path;
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"noEmit": false,
|
||||
"declaration": true,
|
||||
"outDir": "dist",
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"incremental": true,
|
||||
"types": [
|
||||
"bun-types" // add Bun global
|
||||
]
|
||||
},
|
||||
"include": ["src/**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
@@ -1,15 +1,5 @@
|
||||
# @gitbook/react-openapi
|
||||
|
||||
## 0.7.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 4771c78: Fixed scalar api client routing
|
||||
- ff50ac2: Bump @scalar/api-client-react version
|
||||
- 867481c: Support Integers in Response example
|
||||
- 7ba67fd: bumped the scalar api client dependency
|
||||
- a78c1ec: Bumped scalar api client pacakge
|
||||
|
||||
## 0.7.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"default": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"version": "0.7.1",
|
||||
"version": "0.7.0",
|
||||
"dependencies": {
|
||||
"@scalar/api-client-react": "1.0.87",
|
||||
"classnames": "^2.5.1",
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://turbo.build/schema.json",
|
||||
"ui": "tui",
|
||||
"globalEnv": ["NODE_ENV", "CI", "ARGOS_*", "GITHUB_*", "GITBOOK_*", "SENTRY_*"],
|
||||
"globalEnv": ["NODE_ENV", "CI", "ARGOS_*", "GITHUB_*"],
|
||||
"tasks": {
|
||||
// Prepare the package for all other tasks
|
||||
"generate": {
|
||||
|
||||
Reference in New Issue
Block a user