Skip to content

Commit 575ffc7

Browse files
committed
feat: add open in chatgpt button to docs sidebar
1 parent f08e00b commit 575ffc7

File tree

3 files changed

+28
-26
lines changed

3 files changed

+28
-26
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"validate-llms-txt": "ts-node bin/validate-llms.txt.ts"
4141
},
4242
"dependencies": {
43-
"@ably/ui": "17.1.0",
43+
"@ably/ui": "17.2.1",
4444
"@codesandbox/sandpack-react": "^2.20.0",
4545
"@codesandbox/sandpack-themes": "^2.0.21",
4646
"@gfx/zopfli": "^1.0.15",

src/components/Layout/RightSidebar.tsx

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,36 @@ const externalLinks = (
3030
activePage: ActivePage,
3131
location: WindowLocation,
3232
): { label: string; icon: IconName; link: string; type: string }[] => {
33+
if (!activePage) {
34+
return [];
35+
}
36+
3337
let githubEditPath = '#';
34-
let requestPath = '#';
35-
36-
if (activePage) {
37-
const githubPathName = location.pathname.replace('docs/', '');
38-
39-
if (customGithubPaths[githubPathName]) {
40-
githubEditPath = customGithubPaths[githubPathName];
41-
} else if (activePage.template === 'mdx') {
42-
githubEditPath =
43-
githubBasePathMDX + (activePage.page.index ? `${githubPathName}/index.mdx` : `${githubPathName}.mdx`);
44-
} else {
45-
githubEditPath =
46-
githubBasePathTextile +
47-
(activePage.page.index ? `${githubPathName}/index.textile` : `${githubPathName}.textile`);
48-
}
38+
const githubPathName = location.pathname.replace('docs/', '');
39+
40+
if (customGithubPaths[githubPathName]) {
41+
githubEditPath = customGithubPaths[githubPathName];
42+
} else if (activePage.template === 'mdx') {
43+
githubEditPath =
44+
githubBasePathMDX + (activePage.page.index ? `${githubPathName}/index.mdx` : `${githubPathName}.mdx`);
45+
} else {
46+
githubEditPath =
47+
githubBasePathTextile + (activePage.page.index ? `${githubPathName}/index.textile` : `${githubPathName}.textile`);
48+
}
4949

50-
const language = new URLSearchParams(location.search).get('lang') as LanguageKey;
51-
const requestTitle = `Change request for: ${activePage.page.link}`;
52-
const requestBody = encodeURIComponent(`
50+
const language = activePage.languages.length > 0 ? activePage.language : null;
51+
const requestTitle = `Change request for: ${activePage.page.link}`;
52+
const requestBody = encodeURIComponent(`
5353
**Page name**: ${activePage.page.name}
5454
**URL**: [${activePage.page.link}](https://ably.com${activePage.page.link})
5555
${language && languageInfo[language] ? `Language: **${languageInfo[language].label}**` : ''}
5656
5757
**Requested change or enhancement**:
5858
`);
5959

60-
requestPath = `${requestBasePath}?title=${requestTitle}&body=${requestBody}`;
61-
}
60+
const requestPath = `${requestBasePath}?title=${requestTitle}&body=${requestBody}`;
61+
const prompt = `Tell me more about Ably's '${activePage.page.name}' feature from https://ably.com${activePage.page.link}${language ? ` for ${languageInfo[language]?.label}` : ''}`;
62+
const gptPath = `https://chatgpt.com/?q=${encodeURIComponent(prompt)}`;
6263

6364
return [
6465
{
@@ -68,6 +69,7 @@ const externalLinks = (
6869
type: 'github',
6970
},
7071
{ label: 'Request changes', icon: 'icon-gui-hand-raised-outline', link: requestPath, type: 'request' },
72+
{ label: 'Open in ChatGPT', icon: 'icon-tech-openai', link: gptPath, type: 'llm' },
7173
];
7274
};
7375

@@ -253,7 +255,7 @@ const RightSidebar = () => {
253255
<div
254256
className={cn(
255257
'flex items-center p-4',
256-
index === 0 && 'border-b border-neutral-300 dark:border-neutral-1000',
258+
index > 0 && 'border-t border-neutral-300 dark:border-neutral-1000',
257259
)}
258260
>
259261
<div className="flex-1 flex items-center gap-3">

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
resolved "https://registry.yarnpkg.com/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz#bd9154aec9983f77b3a034ecaa015c2e4201f6cf"
88
integrity sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA==
99

10-
"@ably/ui@17.1.0":
11-
version "17.1.0"
12-
resolved "https://registry.yarnpkg.com/@ably/ui/-/ui-17.1.0.tgz#5c3612d37cb75668f2ef3058ad96c0bc17761ed9"
13-
integrity sha512-tRztxGCwzJ9+9yy/1TurefoTXDjWTvTluOzsQzeZIGD6uRaF/JrA0WggtiYnFnw0FKudQN57ENvXpHpfOZunIg==
10+
"@ably/ui@17.2.1":
11+
version "17.2.1"
12+
resolved "https://registry.yarnpkg.com/@ably/ui/-/ui-17.2.1.tgz#4a4442220f6c476b5042a5313f5b8e849ab37007"
13+
integrity sha512-mQTvr0DFqfHQSL16eARwoyj4aSHk8TO4bRUO3FRegUs4kQoZT+EolFxTzfCggsLwPKznBJM1yfIg6EAqCGREfw==
1414
dependencies:
1515
"@radix-ui/react-accordion" "^1.2.1"
1616
"@radix-ui/react-navigation-menu" "^1.2.4"

0 commit comments

Comments
 (0)