fix(docs): автоматически закрепляет index.md первым в сайдбаре
Добавлен Node-скрипт, который инжектит sidebar_position: 0 в front matter docs/index.md перед сборкой Docusaurus. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -50,6 +50,10 @@ runs:
|
|||||||
cp -r "${{ inputs.docs-path }}" "${DOCUSAURUS_DIR}/docs"
|
cp -r "${{ inputs.docs-path }}" "${DOCUSAURUS_DIR}/docs"
|
||||||
cp "${{ github.workspace }}/.docuservix.yml" "${DOCUSAURUS_DIR}"
|
cp "${{ github.workspace }}/.docuservix.yml" "${DOCUSAURUS_DIR}"
|
||||||
|
|
||||||
|
- name: Prepare docs
|
||||||
|
shell: bash
|
||||||
|
working-directory: ${{ github.action_path }}/docusaurus
|
||||||
|
run: node scripts/prepare-docs.mjs
|
||||||
|
|
||||||
- name: Install Docusaurus dependencies
|
- name: Install Docusaurus dependencies
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
const docsDir = path.resolve(import.meta.dirname, '..', process.argv[2] || 'docs');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Гарантирует наличие sidebar_position: 0 в front matter файла index.md
|
||||||
|
*/
|
||||||
|
function pinIndexToTop() {
|
||||||
|
const indexPath = path.join(docsDir, 'index.md');
|
||||||
|
if (!fs.existsSync(indexPath)) return;
|
||||||
|
|
||||||
|
let content = fs.readFileSync(indexPath, 'utf8');
|
||||||
|
|
||||||
|
if (content.startsWith('---\n')) {
|
||||||
|
const endIdx = content.indexOf('\n---\n', 4);
|
||||||
|
if (endIdx === -1) return;
|
||||||
|
|
||||||
|
const frontMatter = content.slice(4, endIdx);
|
||||||
|
if (/^sidebar_position\s*:/m.test(frontMatter)) return;
|
||||||
|
|
||||||
|
content = '---\nsidebar_position: 0\n' + frontMatter + '\n---\n' + content.slice(endIdx + 5);
|
||||||
|
} else {
|
||||||
|
content = '---\nsidebar_position: 0\n---\n' + content;
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.writeFileSync(indexPath, content);
|
||||||
|
console.log('prepare-docs: pinned index.md to sidebar top');
|
||||||
|
}
|
||||||
|
|
||||||
|
pinIndexToTop();
|
||||||
Reference in New Issue
Block a user