diff --git a/src/components/CopyPageDropdown.tsx b/src/components/CopyPageDropdown.tsx index 6a4da6fd..db8bd936 100644 --- a/src/components/CopyPageDropdown.tsx +++ b/src/components/CopyPageDropdown.tsx @@ -10,6 +10,10 @@ import { DropdownContent, DropdownItem, } from './Dropdown' +import { + getPackageManager, + PACKAGE_MANAGERS, +} from '~/utils/markdown/installCommand' // Markdown icon component matching the screenshot function MarkdownIcon({ className }: { className?: string }) { @@ -92,23 +96,40 @@ 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') + const validPm = getPackageManager(pm) + params.set('pm', validPm) + } + 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 ? (