-
Notifications
You must be signed in to change notification settings - Fork 22
docs: add documentation versioning support #834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vdusek
wants to merge
5
commits into
master
Choose a base branch
from
docs/add-documentation-versioning
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import OriginalComponentTypes from '@theme-original/NavbarItem/ComponentTypes'; | ||
| import VersionedReferenceNavbarItem from './VersionedReferenceNavbarItem'; | ||
|
|
||
| export default { | ||
| ...OriginalComponentTypes, | ||
| 'custom-versioned-reference': VersionedReferenceNavbarItem, | ||
| }; |
91 changes: 91 additions & 0 deletions
91
website/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import React, { useMemo } from 'react'; | ||
| import { useVersions, useActiveDocContext, useDocsVersionCandidates } from '@docusaurus/plugin-content-docs/client'; | ||
| import { useDocsPreferredVersion } from '@docusaurus/theme-common'; | ||
| import { translate } from '@docusaurus/Translate'; | ||
| import { useLocation } from '@docusaurus/router'; | ||
| import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; | ||
| import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem'; | ||
| import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem'; | ||
|
|
||
| const getVersionMainDoc = (version) => version.docs.find((doc) => doc.id === version.mainDocId); | ||
|
|
||
| /* eslint-disable react/prop-types */ | ||
| export default function DocsVersionDropdownNavbarItem({ | ||
| mobile, | ||
| docsPluginId, | ||
| dropdownActiveClassDisabled, | ||
| dropdownItemsBefore, | ||
| dropdownItemsAfter, | ||
| ...props | ||
| }) { | ||
| const { search, hash, pathname } = useLocation(); | ||
| const { siteConfig } = useDocusaurusContext(); | ||
| const baseUrl = siteConfig.baseUrl.endsWith('/') ? siteConfig.baseUrl : `${siteConfig.baseUrl}/`; | ||
| const apiLinks = useMemo(() => { | ||
| if (!pathname.startsWith(`${baseUrl}reference`)) { | ||
| return []; | ||
| } | ||
| try { | ||
| return JSON.parse(props['data-api-links']); | ||
| } catch { | ||
| return []; | ||
| } | ||
| }, [props['data-api-links'], pathname, baseUrl]); | ||
|
|
||
| const activeDocContext = useActiveDocContext(docsPluginId); | ||
| const versions = useVersions(docsPluginId); | ||
| const { savePreferredVersionName } = useDocsPreferredVersion(docsPluginId); | ||
| const versionLinks = versions.map((version, idx) => { | ||
| // We try to link to the same doc, in another version | ||
| // When not possible, fallback to the "main doc" of the version | ||
| const versionDoc = activeDocContext.alternateDocVersions[version.name] ?? getVersionMainDoc(version); | ||
| return { | ||
| label: version.label, | ||
| // preserve ?search#hash suffix on version switches | ||
| to: `${apiLinks[idx] ?? versionDoc.path}${search}${hash}`, | ||
| isActive: () => version === activeDocContext.activeVersion, | ||
| onClick: () => savePreferredVersionName(version.name), | ||
| }; | ||
| }); | ||
| const items = [...dropdownItemsBefore, ...versionLinks, ...dropdownItemsAfter]; | ||
| const dropdownVersion = useDocsVersionCandidates(docsPluginId)[0]; | ||
| // Mobile dropdown is handled a bit differently | ||
| 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', | ||
| }) | ||
| : dropdownVersion.label; | ||
| let dropdownTo = mobile && items.length > 1 ? undefined : getVersionMainDoc(dropdownVersion).path; | ||
|
|
||
| if (dropdownTo && pathname.startsWith(`${baseUrl}reference`)) { | ||
| dropdownTo = versionLinks.find((v) => v.label === dropdownVersion.label)?.to; | ||
| } | ||
|
|
||
| // We don't want to render a version dropdown with 0 or 1 item. If we build | ||
| // the site with a single docs version (onlyIncludeVersions: ['1.0.0']), | ||
| // We'd rather render a button instead of a dropdown | ||
| 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} | ||
| /> | ||
| ); | ||
| } |
16 changes: 16 additions & 0 deletions
16
website/src/theme/NavbarItem/VersionedReferenceNavbarItem.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import React from 'react'; | ||
| import { useDocsVersionCandidates } from '@docusaurus/plugin-content-docs/client'; | ||
| import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem'; | ||
|
|
||
| /* eslint-disable react/prop-types */ | ||
| export default function VersionedReferenceNavbarItem({ docsPluginId, ...props }) { | ||
| const [version] = useDocsVersionCandidates(docsPluginId); | ||
|
|
||
| // Latest version → /reference, "current" (next) → /reference/next, others → /reference/{name} | ||
| let to = '/reference'; | ||
| if (!version.isLast) { | ||
| to = `/reference/${version.name === 'current' ? 'next' : version.name}`; | ||
| } | ||
|
|
||
| return <DefaultNavbarItem {...props} to={to} />; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| changelog.md |
50 changes: 50 additions & 0 deletions
50
website/versioned_docs/version-1.7/01-introduction/index.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| --- | ||
| id: introduction | ||
| title: Overview | ||
| sidebar_label: Overview | ||
| slug: /overview | ||
| description: 'The official library for creating Apify Actors in Python, providing tools for web scraping, automation, and data storage integration.' | ||
| --- | ||
|
|
||
| The Apify SDK for Python is the official library for creating [Apify Actors](https://docs.apify.com/platform/actors) in Python. | ||
|
|
||
| ```python | ||
| from apify import Actor | ||
| from bs4 import BeautifulSoup | ||
| import requests | ||
|
|
||
| async def main(): | ||
| async with Actor: | ||
| actor_input = await Actor.get_input() | ||
| response = requests.get(actor_input['url']) | ||
| soup = BeautifulSoup(response.content, 'html.parser') | ||
| await Actor.push_data({ 'url': actor_input['url'], 'title': soup.title.string }) | ||
| ``` | ||
|
|
||
| ## What are Actors? | ||
|
|
||
| Actors are serverless cloud programs that can do almost anything a human can do in a web browser. They can do anything from small tasks such as filling in forms or unsubscribing from online services, all the way up to scraping and processing vast numbers of web pages. | ||
|
|
||
| Actors can be run either locally, or on the [Apify platform](https://docs.apify.com/platform/), where you can run them at scale, monitor them, schedule them, and even publish and monetize them. | ||
|
|
||
| If you're new to Apify, learn [what is Apify](https://docs.apify.com/platform/about) in the Apify platform documentation. | ||
|
|
||
| ## Quick start | ||
|
|
||
| To create and run Actors through Apify Console, see the [Console documentation](https://docs.apify.com/academy/getting-started/creating-actors#choose-your-template). For creating and running Python Actors locally, refer to the [quick start guide](./quick-start). | ||
|
|
||
| Explore the Guides section in the sidebar for a deeper understanding of the SDK's features and best practices. | ||
|
|
||
| ## Installation | ||
|
|
||
| The Apify SDK for Python requires Python version 3.8 or above. It is typically installed when you create a new Actor project using the [Apify CLI](https://docs.apify.com/cli). To install it manually in an existing project, use: | ||
|
|
||
| ```bash | ||
| pip install apify | ||
| ``` | ||
|
|
||
| :::note API client alternative | ||
|
|
||
| If you need to interact with the Apify API programmatically without creating Actors, use the [Apify API client for Python](https://docs.apify.com/api/client/python) instead. | ||
|
|
||
| ::: |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we can explicitly checkout the
needs.changelog_update.outputs.changelog_commitish, to prevent race conditions or other mishaps?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, checkout now explicitly uses
ref: ${{ needs.changelog_update.outputs.changelog_commitish }}