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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
32 changes: 23 additions & 9 deletions website/src/pages/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@

import React from 'react';
import Layout from '@theme/Layout';

import useBaseUrl from '@docusaurus/useBaseUrl';
const versions = require('../../versions.json');
// The versionsArchived mapping is a custom feature, NOT a Docusaurus feature
const versionsArchived = require('../../versionsArchived.json');

const VersionItem = ({version, currentVersion}) => {
const VersionItem = ({version, archivedDocumentationUrl, currentVersion}) => {
const versionName = version === 'next' ? 'Master' : version;

const isCurrentVersion = currentVersion === version;
const isNext = version === 'next';
const isRC = version.toUpperCase().indexOf('-RC') !== -1;

const latestMajorVersion = versions[0].toUpperCase().replace('-RC', '');
const documentationLink = (
<a
href={useBaseUrl(
'docs/' + (isCurrentVersion ? '' : version + '/') + 'getting-started'
)}>
Documentation
</a>

const documentationUrl = useBaseUrl(
archivedDocumentationUrl ??
`/docs/${isCurrentVersion ? '' : version + '/'}getting-started`
);
const documentationLink = <a href={documentationUrl}>Documentation</a>;

let releaseNotesURL = 'https://github.com/facebook/react-native/releases';
let releaseNotesTitle = 'Changelog';
if (isNext) {
Expand Down Expand Up @@ -125,6 +125,20 @@ const Versions = () => {
</tbody>
</table>
<h2>Archived versions</h2>
<table className="versions">
<tbody>
{Object.entries(versionsArchived).map(
([version, archivedDocumentationUrl]) => (
<VersionItem
key={'version_' + version}
version={version}
archivedDocumentationUrl={archivedDocumentationUrl}
currentVersion={currentVersion}
/>
)
)}
</tbody>
</table>
<p>
The documentation for versions below <code>0.60</code> can be found on
the separate website called{' '}
Expand Down
100 changes: 5 additions & 95 deletions website/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,105 +6,15 @@
*/

import React from 'react';
import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';
import {
useVersions,
useLatestVersion,
useActiveDocContext,
} from '@docusaurus/plugin-content-docs/client';
import {useDocsPreferredVersion} from '@docusaurus/theme-common';
import {useDocsVersionCandidates} from '@docusaurus/theme-common/internal';
import {translate} from '@docusaurus/Translate';
import {useLocation} from '@docusaurus/router';

const getVersionMainDoc = version =>
version.docs.find(doc => doc.id === version.mainDocId);
export default function DocsVersionDropdownNavbarItem({
mobile,
docsPluginId,
dropdownActiveClassDisabled,
dropdownItemsBefore,
dropdownItemsAfter,
...props
}) {
const {search, hash} = useLocation();
const activeDocContext = useActiveDocContext(docsPluginId);
const versions = useVersions(docsPluginId);
const latestVersion = useLatestVersion(docsPluginId);
const {preferredVersion, savePreferredVersionName} =
useDocsPreferredVersion(docsPluginId);
import DocsVersionDropdownNavbarItem from '@theme-original/NavbarItem/DocsVersionDropdownNavbarItem';
import {useActiveDocContext} from '@docusaurus/plugin-content-docs/client';

export default function DocsVersionDropdownNavbarItemWrapper(props) {
// (CUSTOM) Hide version dropdown on non-versioned pages
const activeDocContext = useActiveDocContext(props.docsPluginId);
if (!activeDocContext.activeDoc) {
return null;
}

// (CUSTOM) Show only `next` and last 5 versions in the dropdown
const reducedVersions = versions.slice(0, 6);

const versionLinks = reducedVersions.map(version => {
// 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: `${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;
const dropdownTo =
mobile && items.length > 1
? undefined
: getVersionMainDoc(dropdownVersion).path;

// 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}
/>
);
return <DocsVersionDropdownNavbarItem {...props} />;
}
177 changes: 0 additions & 177 deletions website/versioned_docs/version-0.60/_getting-started-linux-android.md

This file was deleted.

Loading