Skip to content

Commit b3af986

Browse files
authored
chore: setup versioned docs with docusaurus (#5001)
1 parent 1c4c114 commit b3af986

190 files changed

Lines changed: 36403 additions & 24 deletions

File tree

Some content is hidden

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

.github/workflows/deploy-docs.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@ jobs:
2424
steps:
2525
- name: Checkout
2626
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
27+
with:
28+
fetch-depth: 0
2729

2830
- name: Setup
2931
uses: ./.github/actions/setup
3032

33+
- name: Generate 5.x component docs
34+
run: node scripts/generate-component-docs.ts origin/5.0 docs/src/data/componentDocs5x.json
35+
3136
- name: Build docs
3237
run: yarn --cwd docs build
3338

docs/component-docs-plugin/useDocs.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import { useActiveDocContext } from '@docusaurus/plugin-content-docs/client';
12
// @ts-ignore
23
// eslint-disable-next-line import/no-unresolved
34
import { usePluginData } from '@docusaurus/useGlobalData';
45

6+
import componentDocs5x from '../src/data/componentDocs5x.json';
7+
58
const pluginName = 'component-docs-plugin';
69

710
export interface ComponentDocsPluginData {
@@ -27,19 +30,29 @@ export interface Data {
2730

2831
export interface Prop {
2932
required: boolean;
30-
tsType: {
33+
tsType?: {
3134
name: string;
3235
raw?: string;
33-
};
36+
} | null;
3437
description: string;
35-
defaultValue: {
38+
defaultValue?: {
3639
value: string;
37-
};
40+
} | null;
3841
}
3942

43+
const versionedDocs: { [versionName: string]: ComponentDocsPluginData } = {
44+
'5.x': componentDocs5x,
45+
};
46+
4047
function useDoc(withPath: string) {
48+
const activeDocContext = useActiveDocContext(undefined);
4149
const pluginData = usePluginData(pluginName) as ComponentDocsPluginData;
42-
return pluginData?.docs?.[withPath];
50+
const versionName = activeDocContext.activeVersion?.name;
51+
const versionedDoc = versionName
52+
? versionedDocs[versionName]?.docs?.[withPath]
53+
: undefined;
54+
55+
return versionedDoc ?? pluginData?.docs?.[withPath];
4356
}
4457

4558
export default useDoc;

docs/docs/guides/07-contributing.mdx

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

docs/docusaurus.config.js

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ const config = {
6060
[
6161
'./component-docs-plugin',
6262
{
63-
docsRootDir: path.join(__dirname, 'docs', 'components'),
63+
docsRootDir: path.join(
64+
__dirname,
65+
'versioned_docs',
66+
'version-6.x',
67+
'components'
68+
),
6469
libsRootDir: path.join(__dirname, '..', 'src', 'components'),
6570
pages: {
6671
ActivityIndicator: 'ActivityIndicator',
@@ -195,12 +200,24 @@ const config = {
195200
({
196201
docs: {
197202
sidebarPath: require.resolve('./sidebars.js'),
203+
includeCurrentVersion: false,
204+
lastVersion: '5.x',
205+
versions: {
206+
'6.x': {
207+
label: '6.x',
208+
banner: 'unreleased',
209+
},
210+
'5.x': {
211+
label: '5.x',
212+
banner: 'none',
213+
},
214+
},
198215
editUrl: (params) => {
199216
const urlToMain =
200217
'https://github.com/callstack/react-native-paper/tree/main';
201218

202219
if (params.docPath.includes('guides')) {
203-
return `${urlToMain}/docs/docs/${params.docPath}`;
220+
return `${urlToMain}/docs/${params.versionDocsDirPath}/${params.docPath}`;
204221
}
205222

206223
const customUrls = {
@@ -260,24 +277,23 @@ const config = {
260277
label: 'Showcase',
261278
},
262279
{
263-
type: 'dropdown',
264-
label: 'v5.x',
280+
type: 'docsVersionDropdown',
265281
position: 'right',
266-
items: [
282+
dropdownItemsAfter: [
267283
{
268-
label: 'v4.x',
284+
label: '4.x',
269285
href: `${publicUrl}4.0/`,
270286
},
271287
{
272-
label: 'v3.x',
288+
label: '3.x',
273289
href: `${publicUrl}3.0/`,
274290
},
275291
{
276-
label: 'v2.x',
292+
label: '2.x',
277293
href: `${publicUrl}2.0/`,
278294
},
279295
{
280-
label: 'v1.x',
296+
label: '1.x',
281297
href: `${publicUrl}1.0/`,
282298
},
283299
],

0 commit comments

Comments
 (0)