mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-29 14:38:50 +02:00
feat(v2): docs version configuration: lastVersion, version.{path,label} (#3357)
* add new docs versioning options * Add some tests for new versioning options * Add some docs for version configurations * try to fix broken link detection after /docs/ root paths have been removed on deploy previews * improve dev/deploypreview versioning configurations * disable custom current version path, as it produces broken links * readVersionDocs should not be order sensitive * fix versions page according to versioning config * fix versions page according to versioning config
This commit is contained in:
parent
4bfc3bbbe7
commit
ae877f2990
15 changed files with 387 additions and 79 deletions
|
@ -6,20 +6,21 @@
|
|||
*/
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import Layout from '@theme/Layout';
|
||||
|
||||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||
import Link from '@docusaurus/Link';
|
||||
import useBaseUrl from '@docusaurus/useBaseUrl';
|
||||
import Layout from '@theme/Layout';
|
||||
|
||||
import versions from '../../versions.json';
|
||||
import {useVersions, useLatestVersion} from '@theme/hooks/useDocs';
|
||||
|
||||
function Version() {
|
||||
const context = useDocusaurusContext();
|
||||
const {siteConfig = {}} = context;
|
||||
const latestVersion = versions[0];
|
||||
const pastVersions = versions.filter((version) => version !== latestVersion);
|
||||
const {siteConfig} = useDocusaurusContext();
|
||||
const versions = useVersions();
|
||||
const latestVersion = useLatestVersion();
|
||||
const currentVersion = versions.find((version) => version.name === 'current');
|
||||
const pastVersions = versions.filter(
|
||||
(version) => version !== latestVersion && version.name !== 'current',
|
||||
);
|
||||
|
||||
const repoUrl = `https://github.com/${siteConfig.organizationName}/${siteConfig.projectName}`;
|
||||
return (
|
||||
<Layout
|
||||
|
@ -34,12 +35,12 @@ function Version() {
|
|||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>{latestVersion}</th>
|
||||
<th>{latestVersion.label}</th>
|
||||
<td>
|
||||
<Link to={useBaseUrl('/docs')}>Documentation</Link>
|
||||
<Link to={latestVersion.path}>Documentation</Link>
|
||||
</td>
|
||||
<td>
|
||||
<a href={`${repoUrl}/releases/tag/v${latestVersion}`}>
|
||||
<a href={`${repoUrl}/releases/tag/v${latestVersion.name}`}>
|
||||
Release Notes
|
||||
</a>
|
||||
</td>
|
||||
|
@ -47,23 +48,25 @@ function Version() {
|
|||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div className="margin-bottom--lg">
|
||||
<h3 id="next">Next version (Unreleased)</h3>
|
||||
<p>Here you can find the documentation for unreleased version.</p>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>master</th>
|
||||
<td>
|
||||
<Link to={useBaseUrl('/docs/next')}>Documentation</Link>
|
||||
</td>
|
||||
<td>
|
||||
<a href={repoUrl}>Source Code</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{currentVersion !== latestVersion && (
|
||||
<div className="margin-bottom--lg">
|
||||
<h3 id="next">Next version (Unreleased)</h3>
|
||||
<p>Here you can find the documentation for unreleased version.</p>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>master</th>
|
||||
<td>
|
||||
<Link to={currentVersion.path}>Documentation</Link>
|
||||
</td>
|
||||
<td>
|
||||
<a href={repoUrl}>Source Code</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
{pastVersions.length > 0 && (
|
||||
<div className="margin-bottom--lg">
|
||||
<h3 id="archive">Past Versions</h3>
|
||||
|
@ -74,15 +77,13 @@ function Version() {
|
|||
<table>
|
||||
<tbody>
|
||||
{pastVersions.map((version) => (
|
||||
<tr key={version}>
|
||||
<th>{version}</th>
|
||||
<tr key={version.name}>
|
||||
<th>{version.label}</th>
|
||||
<td>
|
||||
<Link to={useBaseUrl(`/docs/${version}`)}>
|
||||
Documentation
|
||||
</Link>
|
||||
<Link to={version.path}>Documentation</Link>
|
||||
</td>
|
||||
<td>
|
||||
<a href={`${repoUrl}/releases/tag/v${version}`}>
|
||||
<a href={`${repoUrl}/releases/tag/v${version.name}`}>
|
||||
Release Notes
|
||||
</a>
|
||||
</td>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue