Skip to content

Commit 0ed99a6

Browse files
committed
Remove duplicated versioned docs sources
1 parent c928ed0 commit 0ed99a6

184 files changed

Lines changed: 22 additions & 26403 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.

‎docs/rspress.config.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ export default withCallstackPreset(
6969
'tests/**',
7070
'visual/**',
7171
'component-docs-plugin/**',
72-
'versioned_docs/**',
7372
'README.md',
7473
],
7574
},

‎docs/scripts/generate-rspress-content.mjs‎

Lines changed: 14 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const require = createRequire(import.meta.url);
66
const componentDocsConfig = require('../component-docs.config');
77

88
const rootDir = path.resolve(path.dirname(new URL(import.meta.url).pathname), '..');
9-
const versionedDocsDir = path.join(rootDir, 'versioned_docs');
109
const sourcePagesDir = path.join(rootDir, 'src', 'pages');
1110
const staticDir = path.join(rootDir, 'static');
1211
const publicDir = path.join(rootDir, 'public');
@@ -85,6 +84,8 @@ const copyFile = (sourcePath, targetPath, transform) => {
8584
fs.writeFileSync(targetPath, transform(source));
8685
};
8786

87+
const getVersionDocsDir = (version) => path.join(rootDir, version, 'docs');
88+
8889
const createNav = (version) => {
8990
const activePrefix =
9091
version === '6.x' ? '^/(?:6\\.x/)?docs' : '^/docs';
@@ -148,12 +149,7 @@ const getComponentChildOrder = (version, dirName) => {
148149
return Object.keys(configEntry);
149150
}
150151

151-
const dirPath = path.join(
152-
versionedDocsDir,
153-
`version-${version}`,
154-
'components',
155-
dirName
156-
);
152+
const dirPath = path.join(getVersionDocsDir(version), 'components', dirName);
157153

158154
return fs
159155
.readdirSync(dirPath, { withFileTypes: true })
@@ -162,71 +158,25 @@ const getComponentChildOrder = (version, dirName) => {
162158
};
163159

164160
const createGuidesMeta = (version) => {
165-
const guidesDir = path.join(versionedDocsDir, `version-${version}`, 'guides');
161+
const guidesDir = path.join(getVersionDocsDir(version), 'guides');
162+
const metaPath = path.join(guidesDir, '_meta.json');
163+
const existingOrder = fs.existsSync(metaPath)
164+
? JSON.parse(fs.readFileSync(metaPath, 'utf8'))
165+
: [];
166166

167-
return fs
167+
const currentEntries = fs
168168
.readdirSync(guidesDir, { withFileTypes: true })
169169
.filter((entry) => entry.isFile() && /\.(md|mdx)$/.test(entry.name))
170-
.sort((left, right) => left.name.localeCompare(right.name, undefined, { numeric: true }))
171170
.map((entry) => stripNumericPrefix(entry.name));
172-
};
173-
174-
const createComponentMeta = (version) => {
175-
return getVersionComponentOrder(version);
176-
};
177171

178-
const copyGuides = (version, targetVersionDir) => {
179-
const guidesDir = path.join(versionedDocsDir, `version-${version}`, 'guides');
180-
const targetGuidesDir = path.join(targetVersionDir, 'docs', 'guides');
172+
const knownEntries = existingOrder.filter((entry) => currentEntries.includes(entry));
173+
const newEntries = currentEntries.filter((entry) => !existingOrder.includes(entry));
181174

182-
for (const entry of fs.readdirSync(guidesDir, { withFileTypes: true })) {
183-
if (!entry.isFile() || !/\.(md|mdx)$/.test(entry.name)) {
184-
continue;
185-
}
186-
187-
const sourcePath = path.join(guidesDir, entry.name);
188-
const cleanName = `${stripNumericPrefix(entry.name)}${path.extname(entry.name)}`;
189-
copyFile(sourcePath, path.join(targetGuidesDir, cleanName), (content) =>
190-
transformSharedContent(content, version)
191-
);
192-
}
175+
return [...knownEntries, ...newEntries];
193176
};
194177

195-
const copyComponentDocs = (version, targetVersionDir) => {
196-
const componentsDir = path.join(
197-
versionedDocsDir,
198-
`version-${version}`,
199-
'components'
200-
);
201-
const targetComponentsDir = path.join(targetVersionDir, 'docs', 'components');
202-
203-
const walk = (sourceDir, outputDir) => {
204-
ensureDir(outputDir);
205-
206-
for (const entry of fs.readdirSync(sourceDir, { withFileTypes: true })) {
207-
if (entry.name === '_category_.json') {
208-
continue;
209-
}
210-
211-
const sourcePath = path.join(sourceDir, entry.name);
212-
const targetPath = path.join(outputDir, entry.name);
213-
214-
if (entry.isDirectory()) {
215-
walk(sourcePath, targetPath);
216-
continue;
217-
}
218-
219-
if (!/\.(md|mdx)$/.test(entry.name)) {
220-
continue;
221-
}
222-
223-
copyFile(sourcePath, targetPath, (content) =>
224-
transformSharedContent(content, version)
225-
);
226-
}
227-
};
228-
229-
walk(componentsDir, targetComponentsDir);
178+
const createComponentMeta = (version) => {
179+
return getVersionComponentOrder(version);
230180
};
231181

232182
const writeMetaFiles = (version, targetVersionDir) => {
@@ -277,14 +227,6 @@ const writeIndexPage = (targetVersionDir) => {
277227
);
278228
};
279229

280-
const writeShowcasePage = (version, targetVersionDir) => {
281-
copyFile(
282-
path.join(versionedDocsDir, `version-${version}`, 'showcase.mdx'),
283-
path.join(targetVersionDir, 'docs', 'showcase.mdx'),
284-
(content) => transformSharedContent(content, version)
285-
);
286-
};
287-
288230
const copyStaticAssets = () => {
289231
fs.cpSync(staticDir, publicDir, { recursive: true, force: true });
290232
fs.cpSync(staticDir, path.join(publicDir, 'react-native-paper'), {
@@ -295,14 +237,10 @@ const copyStaticAssets = () => {
295237

296238
const prepareVersionDir = (version) => {
297239
const targetVersionDir = path.join(rootDir, version);
298-
fs.rmSync(targetVersionDir, { recursive: true, force: true });
299240
ensureDir(targetVersionDir);
300241

301242
writeJson(path.join(targetVersionDir, '_nav.json'), createNav(version));
302243
writeIndexPage(targetVersionDir);
303-
writeShowcasePage(version, targetVersionDir);
304-
copyGuides(version, targetVersionDir);
305-
copyComponentDocs(version, targetVersionDir);
306244
writeMetaFiles(version, targetVersionDir);
307245
};
308246

‎docs/tests/rspress-generation.test.mjs‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ test('current docs tree stays free of legacy docusaurus scaffold files', () => {
5656
false,
5757
'versioned_sidebars should not exist in the rspress docs tree'
5858
);
59+
60+
assert.equal(
61+
fs.existsSync(path.join(docsRoot, 'versioned_docs')),
62+
false,
63+
'versioned_docs should not exist in the rspress docs tree'
64+
);
5965
});
6066

6167
test('theme layout does not append a second right-side version selector', () => {
@@ -164,12 +170,8 @@ test('version selector exposes current and legacy versions', () => {
164170
assert.match(selectorSource, new RegExp(label.replace('.', '\\.')));
165171
}
166172

167-
assert.match(selectorSource, /window\.location\.assign\(link\.href\)/);
168-
assert.match(selectorSource, /anchor\.target = '_blank'/);
169-
assert.match(
170-
selectorSource,
171-
/window\.open\(link\.href, '_blank', 'noopener,noreferrer'\)/
172-
);
173+
assert.match(selectorSource, /target=\{link\.external \? '_blank' : undefined\}/);
174+
assert.match(selectorSource, /rel=\{link\.external \? 'noopener noreferrer' : undefined\}/);
173175
assert.match(selectorSource, /getStableRoute/);
174176
assert.match(selectorSource, /getNextRoute/);
175177
});

‎docs/versioned_docs/version-5.x/components/ActivityIndicator.mdx‎

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

0 commit comments

Comments
 (0)