lint: добавление линтера
Reviewed-on: #5 Co-authored-by: Arswarog <arswarog@yandex.ru> Co-committed-by: Arswarog <arswarog@yandex.ru>
This commit was merged in pull request #5.
This commit is contained in:
+26
-14
@@ -1,3 +1,5 @@
|
||||
/* eslint-disable no-console -- logs required */
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
@@ -9,23 +11,33 @@ pinIndexToTop();
|
||||
* Гарантирует наличие sidebar_position: 0 в front matter файла index.md
|
||||
*/
|
||||
function pinIndexToTop() {
|
||||
const indexPath = path.join(docsDir, 'index.md');
|
||||
if (!fs.existsSync(indexPath)) return;
|
||||
const indexPath = path.join(docsDir, 'index.md');
|
||||
|
||||
let content = fs.readFileSync(indexPath, 'utf8');
|
||||
if (!fs.existsSync(indexPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (content.startsWith('---\n')) {
|
||||
const endIdx = content.indexOf('\n---\n', 4);
|
||||
if (endIdx === -1) return;
|
||||
let content = fs.readFileSync(indexPath, 'utf8');
|
||||
|
||||
const frontMatter = content.slice(4, endIdx);
|
||||
if (/^sidebar_position\s*:/m.test(frontMatter)) return;
|
||||
if (content.startsWith('---\n')) {
|
||||
const endIdx = content.indexOf('\n---\n', 4);
|
||||
|
||||
content = '---\nsidebar_position: 0\n' + frontMatter + '\n---\n' + content.slice(endIdx + 5);
|
||||
} else {
|
||||
content = '---\nsidebar_position: 0\n---\n' + content;
|
||||
}
|
||||
if (endIdx === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
fs.writeFileSync(indexPath, content);
|
||||
console.log('prepare-docs: pinned index.md to sidebar top');
|
||||
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');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user