mirror of
https://github.com/Fechin/reference.git
synced 2026-11-20 21:23:11 +03:00
- Add comprehensive development tooling: * ESLint configuration with modern JavaScript rules * Prettier for consistent code formatting * Husky for Git hooks automation * lint-staged for pre-commit checks * Conventional Commits with commitlint * Stylelint for CSS code quality - Fix CSS issues: * Resolve duplicate selectors in layout_note.css * Merge duplicate selectors in layout_list.css * Ensure stylelint compliance - Apply consistent code formatting: * Format all JavaScript, CSS, and Markdown files * Standardize code style across the project * Fix console statement warnings in main.js - Update project documentation: * Enhance README with modern development practices * Update package.json with new scripts and dependencies This modernization establishes a robust development environment with automated code quality checks, consistent formatting~
51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
const h2_re = /<h2 id=".*"><a class="h-anchor" href="(#.*)">#<\/a>(.*)<\/h2>/gm;
|
|
const h3_re = /<h3 id=".*"><a class="h-anchor" href="(#.*)">#<\/a>(.*)<\/h3>/gm;
|
|
|
|
hexo.extend.filter.register('after_post_render', (data) => {
|
|
let h2_m;
|
|
const h2_list = [];
|
|
while ((h2_m = h2_re.exec(data.content)) !== null) {
|
|
h2_list.push({
|
|
anchor: h2_m[1].trim(),
|
|
title: h2_m[2].trim(),
|
|
start: h2_m.index
|
|
});
|
|
}
|
|
|
|
const h3_list = [];
|
|
for (let i = 0; i < h2_list.length; i++) {
|
|
const start = h2_list[i].start;
|
|
let end = data.content.length;
|
|
const next = h2_list[i + 1];
|
|
if (next !== undefined) {
|
|
end = next.start;
|
|
}
|
|
const h2_section = data.content.substring(start, end);
|
|
let h3_m;
|
|
const h3_items = [];
|
|
while ((h3_m = h3_re.exec(h2_section)) !== null) {
|
|
h3_items.push({
|
|
anchor: h3_m[1].trim(),
|
|
title: h3_m[2].trim()
|
|
});
|
|
}
|
|
// h2_list[i] = h2_list[i]; // Remove self-assignment
|
|
h3_list.push(h3_items);
|
|
}
|
|
|
|
const cards = [];
|
|
for (let i = 0; i < h2_list.length; i++) {
|
|
if (h3_list[i].length === 0) {
|
|
continue;
|
|
}
|
|
delete h2_list[i].start;
|
|
cards.push({
|
|
h2: h2_list[i],
|
|
h3: h3_list[i]
|
|
});
|
|
}
|
|
|
|
data.sections = cards;
|
|
return data;
|
|
});
|