Skip to content

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

Merged
merged 13 commits into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from 10 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
6 changes: 6 additions & 0 deletions .github/copilot-instructions.md
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 на локальный адрес сайта только при необходимости.
34 changes: 34 additions & 0 deletions .github/workflows/copilot-setup-steps.yml
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
54 changes: 41 additions & 13 deletions .vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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, '') || '';
Copy link
Member

Choose a reason for hiding this comment

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

Разве для relativePath нужно применять корректирующий 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 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.

} 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')) {
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.

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,
}
}

Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

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

Кажется, ты здесь ошибся. Для autumn rest будет начиная с первого сегмента. Перепроверь эту функцию целиком.

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 absolutely correct! For autumn docs, rest should include all segments from the relativePath. After URL rewrite, autumn paths like getting-started/about-autumn.md should use the entire path, not skip the first segment. Fixed the logic to use const restPath = relativePath for autumn docs while keeping the segment skipping for other repositories. Edit links now work correctly - fixed in 81275ef.

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 ''
Expand Down