Skip to content

Commit a1ffa12

Browse files
authored
Merge pull request #2654 from ably/web-4440-gpt-link
[WEB-4440] Add Open in ChatGPT button to right sidebar
2 parents 9b3d400 + 14db600 commit a1ffa12

File tree

5 files changed

+36
-31
lines changed

5 files changed

+36
-31
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: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import { componentMaxHeight, HEADER_HEIGHT, HEADER_BOTTOM_MARGIN } from '@ably/u
77

88
import { LanguageSelector } from './LanguageSelector';
99
import { useLayoutContext } from 'src/contexts/layout-context';
10+
import { productData } from 'src/data';
11+
import { LanguageKey } from 'src/data/languages/types';
1012
import { languageInfo } from 'src/data/languages';
1113
import { ActivePage, sidebarAlignmentClasses, sidebarAlignmentStyles } from './utils/nav';
1214
import { INKEEP_ASK_BUTTON_HEIGHT } from './utils/heights';
13-
import { LanguageKey } from 'src/data/languages/types';
1415

1516
type SidebarHeader = {
1617
id: string;
@@ -30,35 +31,36 @@ const externalLinks = (
3031
activePage: ActivePage,
3132
location: WindowLocation,
3233
): { label: string; icon: IconName; link: string; type: string }[] => {
34+
if (!activePage) {
35+
return [];
36+
}
37+
3338
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-
}
39+
const githubPathName = location.pathname.replace('docs/', '');
40+
41+
if (customGithubPaths[githubPathName]) {
42+
githubEditPath = customGithubPaths[githubPathName];
43+
} else if (activePage.template === 'mdx') {
44+
githubEditPath =
45+
githubBasePathMDX + (activePage.page.index ? `${githubPathName}/index.mdx` : `${githubPathName}.mdx`);
46+
} else {
47+
githubEditPath =
48+
githubBasePathTextile + (activePage.page.index ? `${githubPathName}/index.textile` : `${githubPathName}.textile`);
49+
}
4950

50-
const language = new URLSearchParams(location.search).get('lang') as LanguageKey;
51-
const requestTitle = `Change request for: ${activePage.page.link}`;
52-
const requestBody = encodeURIComponent(`
51+
const language = activePage.languages.length > 0 ? activePage.language : null;
52+
const requestTitle = `Change request for: ${activePage.page.link}`;
53+
const requestBody = encodeURIComponent(`
5354
**Page name**: ${activePage.page.name}
5455
**URL**: [${activePage.page.link}](https://ably.com${activePage.page.link})
5556
${language && languageInfo[language] ? `Language: **${languageInfo[language].label}**` : ''}
5657
5758
**Requested change or enhancement**:
5859
`);
5960

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

6365
return [
6466
{
@@ -68,6 +70,7 @@ const externalLinks = (
6870
type: 'github',
6971
},
7072
{ label: 'Request changes', icon: 'icon-gui-hand-raised-outline', link: requestPath, type: 'request' },
73+
{ label: 'Open in ChatGPT', icon: 'icon-tech-openai', link: gptPath, type: 'llm' },
7174
];
7275
};
7376

@@ -253,7 +256,7 @@ const RightSidebar = () => {
253256
<div
254257
className={cn(
255258
'flex items-center p-4',
256-
index === 0 && 'border-b border-neutral-300 dark:border-neutral-1000',
259+
index > 0 && 'border-t border-neutral-300 dark:border-neutral-1000',
257260
)}
258261
>
259262
<div className="flex-1 flex items-center gap-3">

src/components/Layout/utils/nav.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export type ActivePage = {
1414
tree: PageTreeNode[];
1515
page: NavProductPage;
1616
languages: LanguageKey[];
17-
language: LanguageKey;
17+
language: LanguageKey | null;
1818
product: ProductKey | null;
1919
template: PageTemplate;
2020
};

src/contexts/layout-context.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,18 @@ export const LayoutProvider: React.FC<PropsWithChildren<{ pageContext: PageConte
9292
tree: [],
9393
page: { name: '', link: '' },
9494
languages: [],
95-
language: activeLanguage,
95+
language: null,
9696
product: null,
9797
template: null,
9898
};
9999
}
100100

101+
const languages = (activePageData.page.languages as LanguageKey[]) ?? activeLanguages;
102+
101103
return {
102104
...activePageData,
103-
languages: (activePageData.page.languages as LanguageKey[]) ?? activeLanguages,
104-
language: activeLanguage,
105+
languages,
106+
language: languages.includes(activeLanguage) ? activeLanguage : null,
105107
template: (pageContext?.layout?.mdx ? 'mdx' : 'textile') as PageTemplate,
106108
};
107109
}, [location.pathname, location.search, pageContext?.languages, domLanguages, pageContext?.layout?.mdx]);

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)