From 68b287da7d8e43a6ae740b813b64b735500389ad Mon Sep 17 00:00:00 2001 From: Rohid Date: Mon, 18 Aug 2025 12:33:54 +0600 Subject: [PATCH 1/3] feat: Integrate SiteAssist --- www/src/components/navigation/AskAIButton.tsx | 33 ++++++++ www/src/components/navigation/navbar.astro | 2 + .../navigation/themeToggleButton.astro | 4 + www/src/layouts/docs.astro | 17 +++- www/src/layouts/landingPage.astro | 17 +++- www/src/siteassist.d.ts | 78 +++++++++++++++++++ 6 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 www/src/components/navigation/AskAIButton.tsx create mode 100644 www/src/siteassist.d.ts diff --git a/www/src/components/navigation/AskAIButton.tsx b/www/src/components/navigation/AskAIButton.tsx new file mode 100644 index 0000000000..fa858a6ec3 --- /dev/null +++ b/www/src/components/navigation/AskAIButton.tsx @@ -0,0 +1,33 @@ +export default function AskAIButton() { + const handleClick = () => { + window.SiteAssist?.("toggle"); + }; + + return ( + + ); +} diff --git a/www/src/components/navigation/navbar.astro b/www/src/components/navigation/navbar.astro index f0644e0b09..0e8b4b31b6 100644 --- a/www/src/components/navigation/navbar.astro +++ b/www/src/components/navigation/navbar.astro @@ -1,5 +1,6 @@ --- import { getIsRtlFromUrl, getLanguageFromURL } from "../../languages"; +import AskAIButton from "./AskAIButton"; import GithubIcon from "./githubIcon.astro"; import LanguageSelect from "./LanguageSelect"; import Search from "./Search"; @@ -109,6 +110,7 @@ const navbarLinks: Array<{ href: string; label: string }> = [ + diff --git a/www/src/components/navigation/themeToggleButton.astro b/www/src/components/navigation/themeToggleButton.astro index cfa2898d66..ca70b0c87d 100644 --- a/www/src/components/navigation/themeToggleButton.astro +++ b/www/src/components/navigation/themeToggleButton.astro @@ -47,6 +47,8 @@ html.classList.contains("dark") ? "dark" : "light", ); + window.SiteAssist?.("changeTheme", html.classList.contains("dark") ? "dark" : "light") + const toggleTheme = (t: "light" | "dark") => { localStorage.setItem("theme", t); html.classList.add(t === "dark" ? "dark" : "light"); @@ -54,6 +56,8 @@ themeToggle!.setAttribute("title", getMessage()); themeToggle!.setAttribute("aria-label", getMessage()); themeToggle!.setAttribute("value", t); + + window.SiteAssist?.("changeTheme", t) }; themeToggle!.addEventListener("click", () => { diff --git a/www/src/layouts/docs.astro b/www/src/layouts/docs.astro index e1974083d8..ed98787ceb 100644 --- a/www/src/layouts/docs.astro +++ b/www/src/layouts/docs.astro @@ -65,10 +65,25 @@ const githubEditUrl = `${CONFIG.GITHUB_EDIT_URL}/${currentFile}`; html.classList.remove("light"); } + + + + + +
+ + + + + +
; +} + +export type CommandQueueItem = + | ["init", InitOptions] + | ["identify", IdentifyPayload] + | ["changeTheme", Theme] + | ["open"] + | ["close"] + | ["toggle"] + | ["track", string, any?]; + +export type CommandKey = CommandQueueItem[0]; + +export interface SiteAssistAPI { + (cmd: "init", opts: InitOptions): void; + (cmd: "identify", user: IdentifyPayload): void; + (cmd: "changeTheme", theme: Theme): void; + (cmd: "track", event: string, data?: any): void; + (cmd: "open"): void; + (cmd: "close"): void; + (cmd: "toggle"): void; + /** Temp queue set by the stub; cleared once the real API takes over. */ + _q?: CommandQueueItem[]; +} + +declare global { + interface Window { + SiteAssist?: SiteAssistAPI; + } +} From 1e2600fcee1ea6d9962671343b9f32833ab2dbc6 Mon Sep 17 00:00:00 2001 From: Rohid Date: Mon, 18 Aug 2025 12:46:42 +0600 Subject: [PATCH 2/3] fix: run format --- www/src/components/navigation/navbar.astro | 2 +- .../navigation/themeToggleButton.astro | 7 +++++-- www/src/layouts/docs.astro | 21 ++++++++++++++----- www/src/layouts/landingPage.astro | 21 ++++++++++++++----- 4 files changed, 38 insertions(+), 13 deletions(-) diff --git a/www/src/components/navigation/navbar.astro b/www/src/components/navigation/navbar.astro index 0e8b4b31b6..3848b96e2b 100644 --- a/www/src/components/navigation/navbar.astro +++ b/www/src/components/navigation/navbar.astro @@ -110,7 +110,7 @@ const navbarLinks: Array<{ href: string; label: string }> = [ - +
diff --git a/www/src/components/navigation/themeToggleButton.astro b/www/src/components/navigation/themeToggleButton.astro index ca70b0c87d..51f7232e10 100644 --- a/www/src/components/navigation/themeToggleButton.astro +++ b/www/src/components/navigation/themeToggleButton.astro @@ -47,7 +47,10 @@ html.classList.contains("dark") ? "dark" : "light", ); - window.SiteAssist?.("changeTheme", html.classList.contains("dark") ? "dark" : "light") + window.SiteAssist?.( + "changeTheme", + html.classList.contains("dark") ? "dark" : "light", + ); const toggleTheme = (t: "light" | "dark") => { localStorage.setItem("theme", t); @@ -57,7 +60,7 @@ themeToggle!.setAttribute("aria-label", getMessage()); themeToggle!.setAttribute("value", t); - window.SiteAssist?.("changeTheme", t) + window.SiteAssist?.("changeTheme", t); }; themeToggle!.addEventListener("click", () => { diff --git a/www/src/layouts/docs.astro b/www/src/layouts/docs.astro index ed98787ceb..0e00aa76fe 100644 --- a/www/src/layouts/docs.astro +++ b/www/src/layouts/docs.astro @@ -66,24 +66,35 @@ const githubEditUrl = `${CONFIG.GITHUB_EDIT_URL}/${currentFile}`; } -
-
Date: Mon, 18 Aug 2025 14:35:41 +0600 Subject: [PATCH 3/3] fix: make ask ai button an icon button when on mobile view --- www/src/components/navigation/AskAIButton.tsx | 4 ++-- www/src/components/navigation/navbar.astro | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/www/src/components/navigation/AskAIButton.tsx b/www/src/components/navigation/AskAIButton.tsx index fa858a6ec3..b86ed97b98 100644 --- a/www/src/components/navigation/AskAIButton.tsx +++ b/www/src/components/navigation/AskAIButton.tsx @@ -6,7 +6,7 @@ export default function AskAIButton() { return ( ); diff --git a/www/src/components/navigation/navbar.astro b/www/src/components/navigation/navbar.astro index 3848b96e2b..a907c566e4 100644 --- a/www/src/components/navigation/navbar.astro +++ b/www/src/components/navigation/navbar.astro @@ -104,13 +104,13 @@ const navbarLinks: Array<{ href: string; label: string }> = [ >
-
- -
+
+ +