diff --git a/website/docusaurus.config.js b/website/docusaurus.config.js index 3e936273ab..6e554dc429 100644 --- a/website/docusaurus.config.js +++ b/website/docusaurus.config.js @@ -269,7 +269,7 @@ module.exports = { position: 'left', }, { - to: '/api', + type: 'custom-api', label: 'API', position: 'left', activeBaseRegex: 'api/(?!.*/changelog)', diff --git a/website/sidebars.js b/website/sidebars.js index a2115c4ff4..c787814c48 100644 --- a/website/sidebars.js +++ b/website/sidebars.js @@ -4,7 +4,7 @@ module.exports = { { type: 'category', label: 'Introduction', - collapsed: false, + collapsed: true, link: { type: 'doc', id: 'introduction/introduction', diff --git a/website/src/theme/NavbarItem/ComponentTypes.js b/website/src/theme/NavbarItem/ComponentTypes.js index 3d2c998474..90a8f7f808 100644 --- a/website/src/theme/NavbarItem/ComponentTypes.js +++ b/website/src/theme/NavbarItem/ComponentTypes.js @@ -1,4 +1,4 @@ -import { useActiveDocContext, useLayoutDoc } from '@docusaurus/plugin-content-docs/client'; +import { useActiveDocContext, useDocsPreferredVersion, useLayoutDoc } from '@docusaurus/plugin-content-docs/client'; import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem'; import DocSidebarNavbarItem from '@theme/NavbarItem/DocSidebarNavbarItem'; import DocsVersionDropdownNavbarItem from '@theme/NavbarItem/DocsVersionDropdownNavbarItem'; @@ -9,8 +9,7 @@ import LocaleDropdownNavbarItem from '@theme/NavbarItem/LocaleDropdownNavbarItem import SearchNavbarItem from '@theme/NavbarItem/SearchNavbarItem'; import React from 'react'; -// const versions = require('../../../versions.json'); -// const stable = versions[0]; +import { getApiPath } from './apiVersionUtils'; function DocNavbarItem({ docId, @@ -35,46 +34,17 @@ function DocNavbarItem({ ); } -function ApiNavbarItem(ctx) { +function ApiNavbarItem({ to, ...props }) { + const { preferredVersion } = useDocsPreferredVersion(); + const apiPath = preferredVersion ? getApiPath(preferredVersion) : 'api'; + return ( ); - - // let version = {}; - // - // try { - // // eslint-disable-next-line react-hooks/rules-of-hooks - // version = useDocsVersion(); - // } catch { - // version.version = stable; - // } - // - // const { siteConfig } = useDocusaurusContext(); - // - // if (siteConfig.presets[0][1].docs.disableVersioning || version.version === stable) { - // return ( - // - // ); - // } - // - // return ( - // - // ); } const ComponentTypes = { diff --git a/website/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.js b/website/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.js new file mode 100644 index 0000000000..9467b650c7 --- /dev/null +++ b/website/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.js @@ -0,0 +1,186 @@ +/** + * Swizzled DocsVersionDropdownNavbarItem that is aware of API reference pages. + * + * The upstream component only handles docs pages. When the user is browsing + * the API reference (routes under /api), switching versions must navigate to + * the matching API version path, not to a docs page. + */ +import React from 'react'; +import { + useVersions, + useActiveDocContext, + useDocsVersionCandidates, + useDocsPreferredVersion, +} from '@docusaurus/plugin-content-docs/client'; +import { useLocation } from '@docusaurus/router'; +import { translate } from '@docusaurus/Translate'; +import { useHistorySelector } from '@docusaurus/theme-common'; +import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; +import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem'; +import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem'; + +import { getApiVersionPath } from './apiVersionUtils'; + +function getVersionItems(versions, configs) { + if (configs) { + const versionMap = new Map(versions.map((version) => [version.name, version])); + const toVersionItem = (name, config) => { + const version = versionMap.get(name); + if (!version) { + throw new Error( + `No docs version exists for name '${name}', please verify your 'docsVersionDropdown' navbar item versions config.\nAvailable version names:\n- ${versions.map((v) => `${v.name}`).join('\n- ')}`, + ); + } + return { version, label: config?.label ?? version.label }; + }; + if (Array.isArray(configs)) { + return configs.map((name) => toVersionItem(name, undefined)); + } + return Object.entries(configs).map(([name, config]) => toVersionItem(name, config)); + } + return versions.map((version) => ({ version, label: version.label })); +} + +function useVersionItems({ docsPluginId, configs }) { + const versions = useVersions(docsPluginId); + return getVersionItems(versions, configs); +} + +function getVersionMainDoc(version) { + return version.docs.find((doc) => doc.id === version.mainDocId); +} + +function getVersionTargetDoc(version, activeDocContext) { + return activeDocContext.alternateDocVersions[version.name] ?? getVersionMainDoc(version); +} + +function useDisplayedVersionItem({ docsPluginId, versionItems }) { + const candidates = useDocsVersionCandidates(docsPluginId); + const candidateItems = candidates + .map((candidate) => versionItems.find((vi) => vi.version === candidate)) + .filter((vi) => vi !== undefined); + return candidateItems[0] ?? versionItems[0]; +} + +/** Detect whether the user is currently on an API reference page and, if so, + * determine which version they are viewing. */ +function useApiVersionInfo(baseUrl, versions) { + const { pathname } = useLocation(); + const apiPrefix = `${baseUrl}api`; + + if (!pathname.startsWith(apiPrefix)) { + return null; + } + + const afterApi = pathname.slice(apiPrefix.length); + const segments = afterApi.split('/').filter(Boolean); + + if (segments.length > 0 && segments[0] === 'next') { + return { currentVersionName: 'current' }; + } + + if (segments.length > 0) { + const versionNames = new Set(versions.map((v) => v.name)); + if (versionNames.has(segments[0])) { + return { currentVersionName: segments[0] }; + } + } + + const lastVersion = versions.find((v) => v.isLast); + return { currentVersionName: lastVersion?.name }; +} + +export default function DocsVersionDropdownNavbarItem({ + mobile, + docsPluginId, + dropdownActiveClassDisabled, + dropdownItemsBefore, + dropdownItemsAfter, + versions: configs, + ...props +}) { + const { siteConfig } = useDocusaurusContext(); + const { baseUrl } = siteConfig; + const search = useHistorySelector((history) => history.location.search); + const hash = useHistorySelector((history) => history.location.hash); + const activeDocContext = useActiveDocContext(docsPluginId); + const { savePreferredVersionName } = useDocsPreferredVersion(docsPluginId); + const versionItems = useVersionItems({ docsPluginId, configs }); + const displayedVersionItem = useDisplayedVersionItem({ docsPluginId, versionItems }); + + const versions = useVersions(docsPluginId); + const apiInfo = useApiVersionInfo(baseUrl, versions); + const isOnApiPage = apiInfo !== null; + + function versionItemToLink({ version, label }) { + if (isOnApiPage) { + const apiPath = getApiVersionPath(version, baseUrl); + return { + label, + to: `${apiPath}${search}${hash}`, + isActive: () => version.name === apiInfo.currentVersionName, + onClick: () => savePreferredVersionName(version.name), + }; + } + + const targetDoc = getVersionTargetDoc(version, activeDocContext); + return { + label, + to: `${targetDoc.path}${search}${hash}`, + isActive: () => version === activeDocContext.activeVersion, + onClick: () => savePreferredVersionName(version.name), + }; + } + + // When on an API page, show the version matching the current API path. + let effectiveDisplayedItem = displayedVersionItem; + if (isOnApiPage) { + const match = versionItems.find((vi) => vi.version.name === apiInfo.currentVersionName); + if (match) { + effectiveDisplayedItem = match; + } + } + + const items = [...dropdownItemsBefore, ...versionItems.map(versionItemToLink), ...dropdownItemsAfter]; + + const dropdownLabel = + mobile && items.length > 1 + ? translate({ + id: 'theme.navbar.mobileVersionsDropdown.label', + message: 'Versions', + description: 'The label for the navbar versions dropdown on mobile view', + }) + : effectiveDisplayedItem.label; + + let dropdownTo; + if (mobile && items.length > 1) { + dropdownTo = undefined; + } else if (isOnApiPage) { + dropdownTo = getApiVersionPath(effectiveDisplayedItem.version, baseUrl); + } else { + dropdownTo = getVersionTargetDoc(effectiveDisplayedItem.version, activeDocContext).path; + } + + if (items.length <= 1) { + return ( + false : undefined} + /> + ); + } + + return ( + false : undefined} + /> + ); +} diff --git a/website/src/theme/NavbarItem/apiVersionUtils.js b/website/src/theme/NavbarItem/apiVersionUtils.js new file mode 100644 index 0000000000..f25972686b --- /dev/null +++ b/website/src/theme/NavbarItem/apiVersionUtils.js @@ -0,0 +1,17 @@ +const API_ROUTE_BASE = 'api'; + +/** Build the API path for a given version (relative, no baseUrl). */ +export function getApiPath(version) { + if (version.isLast) { + return API_ROUTE_BASE; + } + if (version.name === 'current') { + return `${API_ROUTE_BASE}/next`; + } + return `${API_ROUTE_BASE}/${version.name}`; +} + +/** Build the full API path for a given version (with baseUrl prefix). */ +export function getApiVersionPath(version, baseUrl) { + return `${baseUrl}${getApiPath(version)}`; +} diff --git a/website/versioned_docs/version-1.6/changelog.md b/website/versioned_docs/version-1.6/changelog.md index c6ea47314e..a2b25fb7b3 100644 --- a/website/versioned_docs/version-1.6/changelog.md +++ b/website/versioned_docs/version-1.6/changelog.md @@ -2,15 +2,6 @@ All notable changes to this project will be documented in this file. - -## 1.6.1 - **not yet released** - -### 🐛 Bug Fixes - -- Handle invalid URLs in `RequestList` ([#1803](https://github.com/apify/crawlee-python/pull/1803)) ([0b2e3fc](https://github.com/apify/crawlee-python/commit/0b2e3fc5cbca371131b54085e052a6cda6361b0f)) by [@Mantisus](https://github.com/Mantisus), closes [#1802](https://github.com/apify/crawlee-python/issues/1802) - - - ## [1.6.0](https://github.com/apify/crawlee-python/releases/tag/v1.6.0) (2026-03-20) ### 🚀 Features diff --git a/website/versioned_sidebars/version-0.6-sidebars.json b/website/versioned_sidebars/version-0.6-sidebars.json index 39c3ebdc08..bd7d92cc3a 100644 --- a/website/versioned_sidebars/version-0.6-sidebars.json +++ b/website/versioned_sidebars/version-0.6-sidebars.json @@ -4,7 +4,7 @@ { "type": "category", "label": "Introduction", - "collapsed": false, + "collapsed": true, "link": { "type": "doc", "id": "introduction/introduction" @@ -24,6 +24,7 @@ { "type": "category", "label": "Guides", + "collapsed": true, "link": { "type": "generated-index", "title": "Guides", @@ -42,6 +43,7 @@ { "type": "category", "label": "Deployment", + "collapsed": true, "link": { "type": "generated-index", "title": "Deployment guides", @@ -67,6 +69,7 @@ { "type": "category", "label": "Examples", + "collapsed": true, "link": { "type": "generated-index", "title": "Examples", @@ -85,6 +88,7 @@ { "type": "category", "label": "Upgrading", + "collapsed": true, "link": { "type": "generated-index", "title": "Upgrading", diff --git a/website/versioned_sidebars/version-1.6-sidebars.json b/website/versioned_sidebars/version-1.6-sidebars.json index a1abadd701..2e2bebec8f 100644 --- a/website/versioned_sidebars/version-1.6-sidebars.json +++ b/website/versioned_sidebars/version-1.6-sidebars.json @@ -4,7 +4,7 @@ { "type": "category", "label": "Introduction", - "collapsed": false, + "collapsed": true, "link": { "type": "doc", "id": "introduction/introduction"