fix: refactor stuff
This commit is contained in:
parent
27bc2fc747
commit
748f57dd55
|
|
@ -20,7 +20,7 @@ export default defineConfig({
|
|||
// 为 .md 文件配置 raw-loader,支持 webpackContext 加载
|
||||
chain.module
|
||||
.rule('md-raw')
|
||||
.test(/\.md$/)
|
||||
.test(/\.md|\.yarn|\.csv$/)
|
||||
.type('asset/source');
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ function scanDirectory(dir: string): ContentIndex {
|
|||
const stats = statSync(fullPath);
|
||||
if (stats.isDirectory()) {
|
||||
scan(fullPath, relPath);
|
||||
} else if (entry.endsWith(".md")) {
|
||||
} else if (entry.endsWith(".md") || entry.endsWith(".csv") || entry.endsWith(".yarn")) {
|
||||
try {
|
||||
const content = readFileSync(fullPath, "utf-8");
|
||||
index[normalizedRelPath] = content;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import { Component, createSignal, createEffect, onCleanup, Show, createResource } from 'solid-js';
|
||||
import { parseMarkdown } from '../markdown';
|
||||
import { fetchData, extractSection } from '../data-loader';
|
||||
import { extractSection } from '../data-loader';
|
||||
import mermaid from 'mermaid';
|
||||
import {getIndexedData} from "../data-loader/file-index";
|
||||
|
||||
export interface ArticleProps {
|
||||
src: string;
|
||||
|
|
@ -12,7 +13,7 @@ export interface ArticleProps {
|
|||
}
|
||||
|
||||
async function fetchArticleContent(params: { src: string; section?: string }): Promise<string> {
|
||||
const text = await fetchData(params.src);
|
||||
const text = await getIndexedData(params.src);
|
||||
// 如果指定了 section,提取对应内容
|
||||
return params.section ? extractSection(text, params.section) : text;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,16 +8,11 @@ import { getIndexedData } from '../../data-loader/file-index';
|
|||
* @returns 解析结果,包含 front matter 和剩余内容
|
||||
*/
|
||||
function parseFrontMatter(content: string): { frontmatter?: JSONObject; remainingContent: string } {
|
||||
// 检查是否以 --- 开头
|
||||
if (!content.trim().startsWith('---')) {
|
||||
return { remainingContent: content };
|
||||
}
|
||||
|
||||
// 分割内容
|
||||
const parts = content.split(/(?:^|\n)---\s*\n/);
|
||||
const parts = content.trim().split(/(?:^|\n)---\s*\n/g);
|
||||
|
||||
// 至少需要三个部分:空字符串、front matter、剩余内容
|
||||
if (parts.length < 3) {
|
||||
if (parts.length !== 3 || parts[0] !== '') {
|
||||
return { remainingContent: content };
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue