From 8db1b04b5687e433fb06f6f9a49ec5259eb92aff Mon Sep 17 00:00:00 2001 From: SeanCassiere <33615041+SeanCassiere@users.noreply.github.com> Date: Mon, 16 Feb 2026 13:13:07 +1300 Subject: [PATCH 1/3] feat: filter markdown docs by framework and package manager Add shared install command utility for server and client usage. Filter markdown-only docs endpoints to respect framework and package manager query params, with optional marker retention. Propagate current framework into copy links so markdown exports match visible content. --- src/components/CopyPageDropdown.tsx | 22 +- src/components/Doc.tsx | 1 + src/components/markdown/MarkdownContent.tsx | 10 +- .../markdown/PackageManagerTabs.tsx | 124 +--------- ...ion.docs.framework.$framework.{$}[.]md.tsx | 18 +- .../$libraryId/$version.docs.{$}[.]md.tsx | 21 +- src/utils/markdown/filterFrameworkContent.ts | 233 ++++++++++++++++++ src/utils/markdown/installCommand.ts | 129 ++++++++++ 8 files changed, 432 insertions(+), 126 deletions(-) create mode 100644 src/utils/markdown/filterFrameworkContent.ts create mode 100644 src/utils/markdown/installCommand.ts diff --git a/src/components/CopyPageDropdown.tsx b/src/components/CopyPageDropdown.tsx index 6a4da6fd..8e0ce100 100644 --- a/src/components/CopyPageDropdown.tsx +++ b/src/components/CopyPageDropdown.tsx @@ -92,23 +92,41 @@ type CopyPageDropdownProps = { branch?: string /** File path in the repo (e.g., 'src/blog/my-post.md'). Required if repo is provided. */ filePath?: string + /** Current framework for filtering markdown content (appended as ?framework= query param) */ + currentFramework?: string } export function CopyPageDropdown({ repo, branch, filePath, + currentFramework, }: CopyPageDropdownProps = {}) { const [open, setOpen] = React.useState(false) const [copied, setCopied] = React.useState(false) const { notify } = useToast() // Determine if we should fetch from GitHub or use the page URL - const useGitHub = repo && branch && filePath + const useGitHub = repo === 'tanstack/tanstack.com' const gitHubUrl = useGitHub ? `https://raw.githubusercontent.com/${repo}/${branch}/${filePath}` : null - const pageMarkdownUrl = `${typeof window !== 'undefined' ? window.location.origin : ''}${typeof window !== 'undefined' ? window.location.pathname.replace(/\/$/, '') : ''}.md` + const pageMarkdownUrl = (() => { + const base = `${typeof window !== 'undefined' ? window.location.origin : ''}${typeof window !== 'undefined' ? window.location.pathname.replace(/\/$/, '') : ''}.md` + const params = new URLSearchParams() + if (currentFramework) { + params.set('framework', currentFramework) + } + // Read package manager from localStorage (same key as PackageManagerTabs) + if (typeof localStorage !== 'undefined') { + const pm = localStorage.getItem('packageManager') + if (pm && ['npm', 'pnpm', 'yarn', 'bun'].includes(pm)) { + params.set('pm', pm) + } + } + const queryString = params.toString() + return queryString ? `${base}?${queryString}` : base + })() const handleCopyPage = async () => { const urlToFetch = gitHubUrl || pageMarkdownUrl diff --git a/src/components/Doc.tsx b/src/components/Doc.tsx index c32e00b7..d267ceb9 100644 --- a/src/components/Doc.tsx +++ b/src/components/Doc.tsx @@ -164,6 +164,7 @@ export function Doc({ libraryId={libraryId} libraryVersion={libraryVersion} pagePath={pagePath} + currentFramework={currentFramework} titleBarActions={ setIsFullWidth ? (