Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ module.exports = {
position: 'left',
},
{
to: '/api',
type: 'custom-api',
label: 'API',
position: 'left',
activeBaseRegex: 'api/(?!.*/changelog)',
Expand Down
2 changes: 1 addition & 1 deletion website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
{
type: 'category',
label: 'Introduction',
collapsed: false,
collapsed: true,
link: {
type: 'doc',
id: 'introduction/introduction',
Expand Down
46 changes: 8 additions & 38 deletions website/src/theme/NavbarItem/ComponentTypes.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand All @@ -35,46 +34,17 @@ function DocNavbarItem({
);
}

function ApiNavbarItem(ctx) {
function ApiNavbarItem({ to, ...props }) {
const { preferredVersion } = useDocsPreferredVersion();
const apiPath = preferredVersion ? getApiPath(preferredVersion) : 'api';

return (
<DefaultNavbarItem
exact
{...ctx}
label={ctx.label}
to={`api/${ctx.to}`}
{...props}
to={to ? `${apiPath}/${to}` : apiPath}
/>
);

// 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 (
// <DefaultNavbarItem
// exact
// {...ctx}
// label={ctx.label}
// to={`api/${ctx.to}`}
// />
// );
// }
//
// return (
// <DefaultNavbarItem
// exact
// {...ctx}
// label={ctx.label}
// to={`api/${version.version === 'current' ? 'next' : version.version}/${ctx.to}`}
// />
// );
}

const ComponentTypes = {
Expand Down
186 changes: 186 additions & 0 deletions website/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.js
Original file line number Diff line number Diff line change
@@ -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 (
<DefaultNavbarItem
{...props}
mobile={mobile}
label={dropdownLabel}
to={dropdownTo}
isActive={dropdownActiveClassDisabled ? () => false : undefined}
/>
);
}

return (
<DropdownNavbarItem
{...props}
mobile={mobile}
label={dropdownLabel}
to={dropdownTo}
items={items}
isActive={dropdownActiveClassDisabled ? () => false : undefined}
/>
);
}
17 changes: 17 additions & 0 deletions website/src/theme/NavbarItem/apiVersionUtils.js
Original file line number Diff line number Diff line change
@@ -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)}`;
}
9 changes: 0 additions & 9 deletions website/versioned_docs/version-1.6/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@

All notable changes to this project will be documented in this file.

<!-- git-cliff-unreleased-start -->
## 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)


<!-- git-cliff-unreleased-end -->
## [1.6.0](https://github.com/apify/crawlee-python/releases/tag/v1.6.0) (2026-03-20)

### 🚀 Features
Expand Down
6 changes: 5 additions & 1 deletion website/versioned_sidebars/version-0.6-sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"type": "category",
"label": "Introduction",
"collapsed": false,
"collapsed": true,
"link": {
"type": "doc",
"id": "introduction/introduction"
Expand All @@ -24,6 +24,7 @@
{
"type": "category",
"label": "Guides",
"collapsed": true,
"link": {
"type": "generated-index",
"title": "Guides",
Expand All @@ -42,6 +43,7 @@
{
"type": "category",
"label": "Deployment",
"collapsed": true,
"link": {
"type": "generated-index",
"title": "Deployment guides",
Expand All @@ -67,6 +69,7 @@
{
"type": "category",
"label": "Examples",
"collapsed": true,
"link": {
"type": "generated-index",
"title": "Examples",
Expand All @@ -85,6 +88,7 @@
{
"type": "category",
"label": "Upgrading",
"collapsed": true,
"link": {
"type": "generated-index",
"title": "Upgrading",
Expand Down
2 changes: 1 addition & 1 deletion website/versioned_sidebars/version-1.6-sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"type": "category",
"label": "Introduction",
"collapsed": false,
"collapsed": true,
"link": {
"type": "doc",
"id": "introduction/introduction"
Expand Down
Loading