-
Notifications
You must be signed in to change notification settings - Fork 2
Fix editLink для продуктов не учитывает orgName из repositories.json #75
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
Changes from 10 commits
503cdf5
173e88c
01cc92c
857e1cc
311171c
5e7874d
7eb46ea
6ecddc8
8f6637e
e9efca7
780c011
81275ef
c824520
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Это сайт на vitepress для экосистемы Autumn. Он содержит как описание продуктов, так и описание их API. | ||
Локально уже установлен node.js, зависимости. | ||
Документация подчинённых проектов (repositories.json) синхронизирована в каталог sync. | ||
Структура сайта собирается динамически, с активным использованием rewrite rules. | ||
|
||
Проверяй свои действия, собирая сайт и проверяя результирующие html-файлы. Используй curl на локальный адрес сайта только при необходимости. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: "Coding Agent Environment Setup" | ||
|
||
# Allow testing of the setup steps from your repository's "Actions" tab. | ||
on: workflow_dispatch | ||
|
||
jobs: | ||
# The job MUST be called `copilot-setup-steps` or it will not be picked up by Copilot. | ||
copilot-setup-steps: | ||
runs-on: ubuntu-latest | ||
|
||
# Set the permissions to the lowest permissions possible needed for your steps. | ||
# Copilot will be given its own token for its operations. | ||
permissions: | ||
# Clone the repository to install dependencies | ||
contents: read | ||
|
||
steps: | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '23' # Use the Node.js version compatible with VitePress | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Fetch documentation contents | ||
run: npm run sync | ||
|
||
- name: Build the site | ||
run: npm run docs:build |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,12 +19,30 @@ export default defineConfig({ | |
const repositories = JSON.parse(fs.readFileSync('repositories.json', 'utf-8')); | ||
const repositoriesMap: Map<string, RepoData> = new Map(repositories.map((repoData: RepoData) => [repoData.repository, repoData])); | ||
|
||
const repoName = pageData.relativePath.split('/')[1]?.replace(/\d+-/g, ''); | ||
let repoName: string; | ||
|
||
if (pageData.relativePath.startsWith('api/')) { | ||
// For API paths, repository name is in the second segment after rewrite | ||
repoName = pageData.relativePath.split('/')[1]?.replace(/\d+-/g, '') || ''; | ||
} else { | ||
// Use filePath to determine if this is autumn documentation | ||
// pageData.filePath contains the original path before rewrites | ||
if (pageData.filePath && pageData.filePath.includes('products/000-autumn')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Можно для всех вариантов использовать filePath, разве нет? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're absolutely right! I've simplified the logic to use filePath consistently for all variants instead of the mixed approach. Now both API and product paths extract repository names from filePath by parsing the directory structure (api/000-autumn → autumn, products/003-extends → extends) rather than mixing relativePath and filePath approaches. This is much cleaner and more consistent. Fixed in c824520. |
||
// This is autumn documentation at root level (after rewrite from products/000-autumn/) | ||
repoName = 'autumn'; | ||
} else { | ||
// For other products, repository name is in the first segment after rewrite | ||
const firstSegment = pageData.relativePath.split('/')[0]; | ||
repoName = firstSegment?.replace(/\d+-/g, '') || ''; | ||
} | ||
} | ||
|
||
const repoData = repositoriesMap.get(repoName); | ||
|
||
return { | ||
params: { | ||
organization: repoData?.organization, | ||
repository: repoData?.repository, | ||
nixel2007 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
|
@@ -156,19 +174,29 @@ export default defineConfig({ | |
|
||
const relativePath = pageData.relativePath | ||
const organization = pageData.params?.organization; | ||
const repository = pageData.params?.repository; | ||
|
||
// If we have repository info from params, use it directly | ||
if (organization && repository) { | ||
if (relativePath.startsWith('api/')) { | ||
// For API paths, remove 'api/' and repository name from path | ||
const [_, repoSegment, ...rest] = relativePath.split('/') | ||
const restPath = rest.join('/') | ||
return `https://github.com/${organization}/${repository}/edit/master/docs/api/${restPath}`; | ||
} | ||
|
||
// Common calculation for repo extraction from relativePath | ||
const [_, repoName, ...rest] = relativePath.split('/') | ||
const repoNamePath = repoName?.replace(/\d+-/g, '') || '' | ||
const restPath = rest.join('/') | ||
const orgName = organization || 'autumn-library'; | ||
|
||
if (relativePath.startsWith('api/')) { | ||
return `https://github.com/${orgName}/${repoNamePath}/edit/master/docs/api/${restPath}` | ||
} | ||
|
||
if (relativePath.startsWith('products/')) { | ||
return `https://github.com/${orgName}/${repoNamePath}/edit/master/docs/product/${restPath}` | ||
// For product pages - use filePath to determine if it's autumn docs | ||
if (pageData.filePath && pageData.filePath.includes('products/000-autumn')) { | ||
// This is autumn documentation at root level - path after first segment | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Кажется, ты здесь ошибся. Для autumn rest будет начиная с первого сегмента. Перепроверь эту функцию целиком. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're absolutely correct! For autumn docs, |
||
const [_, ...rest] = relativePath.split('/') | ||
const restPath = rest.join('/') | ||
return `https://github.com/${organization}/${repository}/edit/master/docs/product/${restPath}`; | ||
} else { | ||
// This is other repository documentation - path after first segment (repository name) | ||
const [_, ...rest] = relativePath.split('/') | ||
const restPath = rest.join('/') | ||
return `https://github.com/${organization}/${repository}/edit/master/docs/product/${restPath}`; | ||
} | ||
} | ||
|
||
return '' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Разве для relativePath нужно применять корректирующий replace? Проверь в логах.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're absolutely correct! The replace operation was unnecessary. After URL rewrites, the relativePath already has numbers stripped out:
api/000-autumn/...
→api/autumn/...
(no numbers in "autumn")products/003-extends/...
→extends/...
(no numbers in "extends")The replace(/\d+-/g, '') operations were redundant. Fixed in 780c011.