Skip to content

Commit 857e1cc

Browse files
Copilotnixel2007
andcommitted
Fix repository detection for autumn root paths (getting-started, framework-elements)
Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com>
1 parent 01cc92c commit 857e1cc

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

.vitepress/config.mts

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,23 @@ 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-
// 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)
2422
let repoName: string;
23+
2524
if (pageData.relativePath.startsWith('api/')) {
25+
// For API paths, repository name is in the second segment after rewrite
2626
repoName = pageData.relativePath.split('/')[1]?.replace(/\d+-/g, '') || '';
2727
} else {
28-
// For products and other paths, repository name is in the first segment
29-
repoName = pageData.relativePath.split('/')[0]?.replace(/\d+-/g, '') || '';
28+
// Check if this is a root-level autumn path (after rewrite from products/autumn/)
29+
const firstSegment = pageData.relativePath.split('/')[0];
30+
const autumnRootDirs = ['getting-started', 'framework-elements'];
31+
32+
if (autumnRootDirs.includes(firstSegment)) {
33+
// This is autumn documentation at root level
34+
repoName = 'autumn';
35+
} else {
36+
// For other products, repository name is in the first segment after rewrite
37+
repoName = firstSegment?.replace(/\d+-/g, '') || '';
38+
}
3039
}
3140

3241
const repoData = repositoriesMap.get(repoName);
@@ -170,20 +179,26 @@ export default defineConfig({
170179

171180
// If we have repository info from params, use it directly
172181
if (organization && repository) {
173-
const [_, ...rest] = relativePath.split('/')
174-
const restPath = rest.join('/')
175-
176182
if (relativePath.startsWith('api/')) {
183+
// For API paths, remove 'api/' and repository name from path
184+
const [_, repoSegment, ...rest] = relativePath.split('/')
185+
const restPath = rest.join('/')
177186
return `https://github.com/${organization}/${repository}/edit/master/docs/api/${restPath}`;
178187
}
179188

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;
189+
// For product pages
190+
const firstSegment = relativePath.split('/')[0];
191+
const autumnRootDirs = ['getting-started', 'framework-elements'];
185192

186-
if (isProductPage) {
193+
if (autumnRootDirs.includes(firstSegment)) {
194+
// This is autumn documentation at root level - path after first segment
195+
const [_, ...rest] = relativePath.split('/')
196+
const restPath = rest.join('/')
197+
return `https://github.com/${organization}/${repository}/edit/master/docs/product/${restPath}`;
198+
} else {
199+
// This is other repository documentation - path after first segment (repository name)
200+
const [_, ...rest] = relativePath.split('/')
201+
const restPath = rest.join('/')
187202
return `https://github.com/${organization}/${repository}/edit/master/docs/product/${restPath}`;
188203
}
189204
}

0 commit comments

Comments
 (0)