Skip to content

Commit fd53a1f

Browse files
B4nanjanbuchar
andauthored
docs: version only major bumps (#736)
Only major versions are now producing docs snapshots. On release, old version is removed and generated from scratch, so it always reflects the latest stable one. <img width="512" height="171" alt="image" src="https://github.com/user-attachments/assets/eee5ac65-8002-4525-8292-ac6fa5583743" /> I am sure this could be done in another way, feels a bit hacky, but it works 🙃 Closes apify/apify-docs#1837 --------- Co-authored-by: Jan Buchar <[email protected]>
1 parent ced704a commit fd53a1f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3961
-205914
lines changed

.github/workflows/release.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,51 @@ jobs:
121121
- name: Publish to NPM
122122
run: npm publish --tag latest
123123

124+
version-docs:
125+
needs: publish_to_npm
126+
runs-on: ubuntu-latest
127+
128+
steps:
129+
- name: Checkout repository
130+
uses: actions/checkout@v5
131+
with:
132+
ref: ${{ github.event.repository.default_branch }}
133+
token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
134+
fetch-depth: 0
135+
136+
- name: Use Node.js 22
137+
uses: actions/setup-node@v4
138+
with:
139+
node-version: 22
140+
cache: 'npm'
141+
142+
- name: Install jq
143+
run: sudo apt-get install jq
144+
145+
- name: Install dependencies
146+
run: |
147+
npm install
148+
cd website
149+
npm install
150+
151+
- name: Snapshot the current version
152+
run: |
153+
cd website
154+
VERSION=$(jq -r '.version' ../package.json)
155+
export MAJOR=$(echo $VERSION | cut -d. -f1)
156+
rm -rf versioned_docs/version-$MAJOR
157+
rm -rf versioned_sidebars/version-$MAJOR-sidebars.json
158+
jq 'map(select(. != env.MAJOR))' versions.json > tmp.json && mv tmp.json versions.json
159+
npx docusaurus docs:version $MAJOR
160+
npx docusaurus api:version $MAJOR
161+
162+
- name: Commit and push the version snapshot
163+
uses: EndBug/add-and-commit@v9
164+
with:
165+
author_name: Apify Release Bot
166+
author_email: [email protected]
167+
message: 'docs: update docs for ${{ inputs.version }} version'
168+
124169
env:
125170
NODE_AUTH_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }}
126171
NPM_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }}

website/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { translate } from '@docusaurus/Translate';
55
import { useLocation } from '@docusaurus/router';
66
import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
77
import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';
8+
import pkg from '../../../../package.json';
89

910
const getVersionMainDoc = (version) => version.docs.find((doc) => doc.id === version.mainDocId);
1011

@@ -35,12 +36,14 @@ export default function DocsVersionDropdownNavbarItem({
3536
const activeDocContext = useActiveDocContext(docsPluginId);
3637
const versions = useVersions(docsPluginId);
3738
const { savePreferredVersionName } = useDocsPreferredVersion(docsPluginId);
39+
const currentMajor = pkg.version.split('.')[0];
3840
const versionLinks = versions.map((version, idx) => {
3941
// We try to link to the same doc, in another version
4042
// When not possible, fallback to the "main doc" of the version
4143
const versionDoc = activeDocContext.alternateDocVersions[version.name] ?? getVersionMainDoc(version);
44+
const label = version.label === currentMajor ? pkg.version : version.label;
4245
return {
43-
label: version.label,
46+
label,
4447
// preserve ?search#hash suffix on version switches
4548
to: `${apiLinks[idx] ?? versionDoc.path}${search}${hash}`,
4649
isActive: () => version === activeDocContext.activeVersion,
@@ -57,7 +60,9 @@ export default function DocsVersionDropdownNavbarItem({
5760
message: 'Versions',
5861
description: 'The label for the navbar versions dropdown on mobile view',
5962
})
60-
: dropdownVersion.label;
63+
: dropdownVersion.label === currentMajor
64+
? pkg.version
65+
: dropdownVersion.label;
6166
let dropdownTo = mobile && items.length > 1 ? undefined : getVersionMainDoc(dropdownVersion).path;
6267

6368
if (dropdownTo && pathname.startsWith('/api/client/js/reference')) {

website/versioned_docs/version-2.10/api-packages.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)