Skip to content

Fix editLink for products not accounting for orgName from repositories.json #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions .vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default defineConfig({
const repositoriesMap: Map<string, RepoData> = new Map(repositories.map((repoData: RepoData) => [repoData.repository, repoData]));

const repoName = pageData.relativePath.split('/')[1];
const repoData = repositoriesMap.get(repoName);
const repoData = repositoriesMap.get(repoName?.replace(/\d+-/g, ''));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move replace to the line with repoName calculation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved replace operation inline with repoName calculation in both transformPageData and editLink pattern. Now uses repoName?.replace(/\d+-/g, '') directly in the assignment. Commit f9a40a6


return {
params: {
Expand Down Expand Up @@ -154,22 +154,21 @@ export default defineConfig({
text: 'Редактировать страницу',
pattern: ( pageData ) => {

const filePath = pageData.filePath
const relativePath = pageData.relativePath
const organization = pageData.params?.organization;

const [_, repoName, ...rest] = filePath.split('/')
// Common calculation for repo extraction from relativePath
const [_, repoName, ...rest] = relativePath.split('/')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

что-то не сходится. раз это до рерайтов, значит, здесь имя репозитория будет с цифрами в начале. в filePath цифр уже быть не должно, а значит и replace строкой ниже уже не нужен.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right about the logic. I'm using relativePath (before rewrites) so the repo name has prefixes like 003-extends, which is why I need the replace(/\d+-/g, '') on line 164. This is consistent with transformPageData which also uses relativePath and cleans the name for organization lookup. Would you prefer I use filePath instead and remove the replace, or keep the current consistent approach?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Используй filePath

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to use filePath instead of relativePath and removed the manual cleaning since filePath is already processed by URL rewrites. Commit 816719e

const repoNamePath = repoName.replace(/\d+-/g, '')
const restPath = rest.join('/')
const orgName = organization || 'autumn-library';

if (filePath.startsWith('api/')) {
if (relativePath.startsWith('api/')) {
return `https://github.com/${orgName}/${repoNamePath}/edit/master/docs/api/${restPath}`
}

if (filePath.startsWith('products/')) {
return `https://github.com/${orgName}/${repoNamePath}/edit/master/docs/product/${restPath}`
}
return ''
// For products
return `https://github.com/${orgName}/${repoNamePath}/edit/master/docs/product/${restPath}`
}
},

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.