fix: refactor stuff

This commit is contained in:
hypercross 2026-03-13 15:52:51 +08:00
parent 27bc2fc747
commit 748f57dd55
4 changed files with 7 additions and 11 deletions

View File

@ -20,7 +20,7 @@ export default defineConfig({
// 为 .md 文件配置 raw-loader支持 webpackContext 加载 // 为 .md 文件配置 raw-loader支持 webpackContext 加载
chain.module chain.module
.rule('md-raw') .rule('md-raw')
.test(/\.md$/) .test(/\.md|\.yarn|\.csv$/)
.type('asset/source'); .type('asset/source');
}, },
}, },

View File

@ -63,7 +63,7 @@ function scanDirectory(dir: string): ContentIndex {
const stats = statSync(fullPath); const stats = statSync(fullPath);
if (stats.isDirectory()) { if (stats.isDirectory()) {
scan(fullPath, relPath); scan(fullPath, relPath);
} else if (entry.endsWith(".md")) { } else if (entry.endsWith(".md") || entry.endsWith(".csv") || entry.endsWith(".yarn")) {
try { try {
const content = readFileSync(fullPath, "utf-8"); const content = readFileSync(fullPath, "utf-8");
index[normalizedRelPath] = content; index[normalizedRelPath] = content;

View File

@ -1,7 +1,8 @@
import { Component, createSignal, createEffect, onCleanup, Show, createResource } from 'solid-js'; import { Component, createSignal, createEffect, onCleanup, Show, createResource } from 'solid-js';
import { parseMarkdown } from '../markdown'; import { parseMarkdown } from '../markdown';
import { fetchData, extractSection } from '../data-loader'; import { extractSection } from '../data-loader';
import mermaid from 'mermaid'; import mermaid from 'mermaid';
import {getIndexedData} from "../data-loader/file-index";
export interface ArticleProps { export interface ArticleProps {
src: string; src: string;
@ -12,7 +13,7 @@ export interface ArticleProps {
} }
async function fetchArticleContent(params: { src: string; section?: string }): Promise<string> { async function fetchArticleContent(params: { src: string; section?: string }): Promise<string> {
const text = await fetchData(params.src); const text = await getIndexedData(params.src);
// 如果指定了 section提取对应内容 // 如果指定了 section提取对应内容
return params.section ? extractSection(text, params.section) : text; return params.section ? extractSection(text, params.section) : text;
} }

View File

@ -8,16 +8,11 @@ import { getIndexedData } from '../../data-loader/file-index';
* @returns front matter * @returns front matter
*/ */
function parseFrontMatter(content: string): { frontmatter?: JSONObject; remainingContent: string } { 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、剩余内容 // 至少需要三个部分空字符串、front matter、剩余内容
if (parts.length < 3) { if (parts.length !== 3 || parts[0] !== '') {
return { remainingContent: content }; return { remainingContent: content };
} }