-
Notifications
You must be signed in to change notification settings - Fork 76
Add Gurubase integration #716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fatihbaltaci
wants to merge
29
commits into
GitbookIO:main
Choose a base branch
from
fatihbaltaci:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 22 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
e8b06b8
Add Gurubase integration
fatihbaltaci 46558ca
Update preview image for gurubase
fatihbaltaci 67d93be
Merge branch 'main' into main
fatihbaltaci 213f74a
Update the organization id
fatihbaltaci 318aadf
Update the script
fatihbaltaci d73bb4d
Get the optional gurubase widget arguments from the UI
aralyekta c8ec5bf
Update default value text
aralyekta c4ab707
Add baseUrl configuration for Gurubase widget
aralyekta f755b38
Merge pull request #1 from fatihbaltaci/task/fix-gurubase-integration
fatihbaltaci d5cf5a3
Expand CSP to include additional CDN domains for Gurubase widget
aralyekta d664909
Merge pull request #2 from fatihbaltaci/task/fix-gurubase-integration
fatihbaltaci f03a272
Merge branch 'GitbookIO:main' into main
fatihbaltaci 9433171
Add changeset
fatihbaltaci 1f5f28d
Merge branch 'main' into main
addisonschultz 118bec8
Merge branch 'main' into main
addisonschultz cb93bac
Update category and retrigger tests
addisonschultz 2f91154
Merge branch 'main' into main
addisonschultz b435128
Merge branch 'GitbookIO:main' into main
fatihbaltaci d5ce155
Fix default bottom margin
aralyekta d2fbf13
Remove light mode as it will be set to auto
aralyekta 7c64a0c
Set light mode of widget to auto
aralyekta 837057f
Merge pull request #3 from fatihbaltaci/task/gitbook-widget-improveme…
fatihbaltaci b96464c
Remove unused variables
aralyekta b01be29
Merge pull request #4 from fatihbaltaci/task/gitbook-widget-improveme…
fatihbaltaci ef6cff3
Merge branch 'main' into main
addisonschultz 1dc29f6
Add overlapContent argument to gitbook
aralyekta 4b0aa13
Merge pull request #5 from fatihbaltaci/task/gitbook-widget-improveme…
fatihbaltaci c6062ed
Rename argument
aralyekta 3df9a27
Merge pull request #6 from fatihbaltaci/task/gitbook-widget-improveme…
fatihbaltaci File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@gitbook/integration-gurubase': major | ||
--- | ||
|
||
Add Gurubase (https://gurubase.io/) integration to Gitbook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# @gitbook/integration-gurubase | ||
|
||
## 0.1.0 | ||
|
||
Initial release of the Gurubase integration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Gurubase | ||
|
||
```bash | ||
curl -fsSL https://bun.sh/install | bash | ||
|
||
cd packages/api | ||
bun run build | ||
|
||
cd ../../integrations/gurubase | ||
bun install | ||
gitbook publish | ||
cd ../../ | ||
bun changeset | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
name: gurubase | ||
title: Gurubase | ||
icon: ./assets/icon.png | ||
previewImages: | ||
- ./assets/gurubase-preview.png | ||
description: Add the Gurubase widget to your published GitBook content. | ||
externalLinks: | ||
- label: Website | ||
url: https://gurubase.io/ | ||
visibility: public | ||
script: ./src/index.ts | ||
# The following scope(s) are available only to GitBook Staff | ||
# See https://developer.gitbook.com/integrations/configurations#scopes | ||
scopes: | ||
- site:script:inject | ||
organization: hY1Io78AJIno02pEZkOX | ||
contentSecurityPolicy: | ||
font-src: | | ||
*.gurubase.io; | ||
script-src: | | ||
*.gurubase.io; | ||
style-src: | | ||
'self' | ||
'unsafe-inline' | ||
fonts.googleapis.com | ||
*.gurubase.io | ||
unpkg.com | ||
cdnjs.cloudflare.com; | ||
frame-src: | | ||
*.gurubase.io; | ||
child-src: | | ||
*.gurubase.io; | ||
img-src: | | ||
*.gurubase.io; | ||
connect-src: | | ||
*.gurubase.io; | ||
media-src: | | ||
*.gurubase.io; | ||
summary: | | ||
# Overview | ||
Add an AI-powered chat widget to your GitBook documentation using Gurubase. This integration enables real-time AI assistance for your readers directly within your documentation pages. | ||
|
||
## Prerequisites | ||
- You need to have a Guru created on Gurubase.io | ||
- You need a Widget ID from your Guru's settings page | ||
1. Go to "My Gurus" page | ||
2. Select your Guru | ||
3. Click "Integrations" then "Web Widget" | ||
4. Create a new widget and copy the Widget ID | ||
|
||
## Features | ||
- Seamless integration with GitBook pages | ||
- Customizable widget appearance | ||
- Light/Dark mode support | ||
- Custom positioning | ||
- Custom branding options | ||
|
||
# Configuration | ||
1. Install the integration on your GitBook site | ||
2. Add your Widget ID from Gurubase dashboard | ||
3. Customize the widget appearance (optional) | ||
|
||
categories: | ||
- support | ||
configurations: | ||
site: | ||
properties: | ||
widgetId: | ||
type: string | ||
title: Gurubase Widget ID | ||
description: "Available in your Guru's settings page under Integrations > Web Widget" | ||
text: | ||
type: string | ||
title: Text (Optional) | ||
description: "Text to display in the widget button. (default: 'Ask AI')" | ||
bottomMargin: | ||
type: string | ||
title: Bottom Margin (Optional) | ||
description: 'Bottom margin of the widget. Examples: 20px, 1rem. (default: 20px)' | ||
rightMargin: | ||
type: string | ||
title: Right Margin (Optional) | ||
description: 'Right margin of the widget. Examples: 20px, 1rem. (default: 20px)' | ||
bgColor: | ||
type: string | ||
title: Main Color (Optional) | ||
description: "Main color of the widget. Examples: #000000, #ffffff. (default: Guru's main color)" | ||
iconUrl: | ||
type: string | ||
title: Icon URL (Optional) | ||
description: "URL of the icon to display in the widget. (default: Guru's avatar)" | ||
name: | ||
type: string | ||
title: Name (Optional) | ||
description: "Name of the widget. (default: Guru's name)" | ||
baseUrl: | ||
type: string | ||
title: Base Backend URL (Optional) | ||
description: 'Base URL for Gurubase backend. (default: https://api.gurubase.io)' | ||
|
||
required: | ||
- widgetId | ||
target: site |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "@gitbook/integration-gurubase", | ||
"version": "0.1.0", | ||
"private": true, | ||
"dependencies": { | ||
"@gitbook/api": "*", | ||
"@gitbook/runtime": "*" | ||
}, | ||
"devDependencies": { | ||
"@gitbook/cli": "workspace:*", | ||
"@gitbook/tsconfig": "workspace:*" | ||
}, | ||
"scripts": { | ||
"typecheck": "tsc --noEmit", | ||
"publish-integrations-staging": "gitbook publish .", | ||
"check": "gitbook check", | ||
"publish-integrations": "gitbook publish ." | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { | ||
createIntegration, | ||
FetchPublishScriptEventCallback, | ||
RuntimeContext, | ||
RuntimeEnvironment, | ||
} from '@gitbook/runtime'; | ||
|
||
import script from './script.raw.js'; | ||
|
||
type GurubaseRuntimeContext = RuntimeContext< | ||
RuntimeEnvironment< | ||
{}, | ||
{ | ||
widgetId?: string; | ||
text?: string; | ||
bottomMargin?: string; | ||
rightMargin?: string; | ||
lightMode?: boolean; | ||
bgColor?: string; | ||
iconUrl?: string; | ||
name?: string; | ||
baseUrl?: string; | ||
} | ||
> | ||
>; | ||
|
||
export const handleFetchEvent: FetchPublishScriptEventCallback = async ( | ||
event, | ||
{ environment }: GurubaseRuntimeContext, | ||
) => { | ||
const config = environment.siteInstallation?.configuration || {}; | ||
const widgetId = config.widgetId; | ||
|
||
if (!widgetId) { | ||
throw new Error( | ||
`The Gurubase Widget ID is missing from the configuration (ID: ${ | ||
'spaceId' in event ? event.spaceId : event.siteId | ||
}).`, | ||
); | ||
} | ||
|
||
const scriptConfig = { | ||
widgetId, | ||
text: config.text, | ||
margins: JSON.stringify({ | ||
bottom: config.bottomMargin || '60px', | ||
right: config.rightMargin || '20px', | ||
}), | ||
lightMode: config.lightMode, | ||
bgColor: config.bgColor, | ||
iconUrl: config.iconUrl, | ||
name: config.name, | ||
baseUrl: config.baseUrl, | ||
}; | ||
|
||
// Properly escape the config JSON for safe insertion into JavaScript | ||
const escapedConfig = JSON.stringify(scriptConfig).replace(/'/g, "\\'").replace(/"/g, '\\"'); | ||
|
||
return new Response((script as string).replace("'<TO_REPLACE>'", `'${escapedConfig}'`), { | ||
headers: { | ||
'Content-Type': 'application/javascript', | ||
'Cache-Control': 'max-age=604800', | ||
}, | ||
}); | ||
}; | ||
|
||
export default createIntegration<GurubaseRuntimeContext>({ | ||
fetch_published_script: handleFetchEvent, | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
(function (d, s) { | ||
const config = JSON.parse('<TO_REPLACE>'); | ||
const widgetId = config.widgetId; | ||
|
||
window.$gurubase = []; | ||
window.GURUBASE_WIDGET_ID = widgetId; | ||
|
||
d = document; | ||
s = d.createElement('script'); | ||
s.src = 'https://widget.gurubase.io/widget.latest.min.js'; | ||
s.async = 1; | ||
s.setAttribute('data-widget-id', widgetId); | ||
|
||
if (config.text) { | ||
s.setAttribute('data-text', config.text); | ||
} | ||
if (config.margins) { | ||
s.setAttribute('data-margins', config.margins); | ||
} | ||
s.setAttribute('data-light-mode', "auto"); | ||
if (config.bgColor) { | ||
s.setAttribute('data-bg-color', config.bgColor); | ||
} | ||
if (config.iconUrl) { | ||
s.setAttribute('data-icon-url', config.iconUrl); | ||
} | ||
if (config.name) { | ||
s.setAttribute('data-name', config.name); | ||
} | ||
if (config.baseUrl) { | ||
s.setAttribute('data-baseUrl', config.baseUrl); | ||
} | ||
|
||
s.id = 'guru-widget-id'; | ||
d.getElementsByTagName('head')[0].appendChild(s); | ||
})(window, document); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "@gitbook/tsconfig/integration.json" | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.