Skip to content

Commit 01cc92c

Browse files
Copilotnixel2007
andcommitted
Fix repository name extraction for products after rewrite - use split[0] instead of split[1]
Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com>
1 parent 173e88c commit 01cc92c

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

.vitepress/config.mts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,16 @@ export default defineConfig({
1919
const repositories = JSON.parse(fs.readFileSync('repositories.json', 'utf-8'));
2020
const repositoriesMap: Map<string, RepoData> = new Map(repositories.map((repoData: RepoData) => [repoData.repository, repoData]));
2121

22-
const repoName = pageData.relativePath.split('/')[1]?.replace(/\d+-/g, '');
22+
// For products, after rewrite the repository name is in the first segment (index 0)
23+
// For api, the repository name is in the second segment (index 1)
24+
let repoName: string;
25+
if (pageData.relativePath.startsWith('api/')) {
26+
repoName = pageData.relativePath.split('/')[1]?.replace(/\d+-/g, '') || '';
27+
} else {
28+
// For products and other paths, repository name is in the first segment
29+
repoName = pageData.relativePath.split('/')[0]?.replace(/\d+-/g, '') || '';
30+
}
31+
2332
const repoData = repositoriesMap.get(repoName);
2433

2534
return {
@@ -165,11 +174,17 @@ export default defineConfig({
165174
const restPath = rest.join('/')
166175

167176
if (relativePath.startsWith('api/')) {
168-
return `https://github.com/${organization}/${repository}/edit/master/docs/api/${restPath}`
177+
return `https://github.com/${organization}/${repository}/edit/master/docs/api/${restPath}`;
169178
}
170179

171-
if (relativePath.startsWith('products/')) {
172-
return `https://github.com/${organization}/${repository}/edit/master/docs/product/${restPath}`
180+
// For product pages, check if path starts with known product directory names
181+
// or if we have repository info (indicating it's a product page)
182+
const repoNames = ['autumn', 'winow', 'annotations', 'extends', 'autumn-cli', 'autumn-collections', 'autumn-logos'];
183+
const isProductPage = repoNames.some(name => relativePath.startsWith(name + '/')) ||
184+
relativePath.split('/')[0] === repository;
185+
186+
if (isProductPage) {
187+
return `https://github.com/${organization}/${repository}/edit/master/docs/product/${restPath}`;
173188
}
174189
}
175190

@@ -180,11 +195,11 @@ export default defineConfig({
180195
const orgName = organization || 'autumn-library';
181196

182197
if (relativePath.startsWith('api/')) {
183-
return `https://github.com/${orgName}/${repoNamePath}/edit/master/docs/api/${restPath}`
198+
return `https://github.com/${orgName}/${repoNamePath}/edit/master/docs/api/${restPath}`;
184199
}
185200

186201
if (relativePath.startsWith('products/')) {
187-
return `https://github.com/${orgName}/${repoNamePath}/edit/master/docs/product/${restPath}`
202+
return `https://github.com/${orgName}/${repoNamePath}/edit/master/docs/product/${restPath}`;
188203
}
189204

190205
return ''

0 commit comments

Comments
 (0)