czon 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -4,6 +4,7 @@ exports.extractMetadataByAI = extractMetadataByAI;
|
|
|
4
4
|
const promises_1 = require("fs/promises");
|
|
5
5
|
const extractMetadataFromMarkdown_1 = require("../ai/extractMetadataFromMarkdown");
|
|
6
6
|
const metadata_1 = require("../metadata");
|
|
7
|
+
const sha256_1 = require("../utils/sha256");
|
|
7
8
|
/**
|
|
8
9
|
* 运行 AI 元数据提取
|
|
9
10
|
*/
|
|
@@ -16,12 +17,19 @@ async function extractMetadataByAI() {
|
|
|
16
17
|
console.info(`ℹ️ Skipping ${file.path}, not a Markdown file`);
|
|
17
18
|
return;
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
const content = await (0, promises_1.readFile)(file.path, 'utf-8');
|
|
21
|
+
const hash = (0, sha256_1.sha256)(content);
|
|
22
|
+
// 检查是否已有 metadata 且源文件未变化
|
|
23
|
+
if (file.metadata &&
|
|
24
|
+
file.metadata.slug &&
|
|
25
|
+
file.metadata.short_summary &&
|
|
26
|
+
hash === file.hash) {
|
|
27
|
+
console.info(`ℹ️ Skipping ${file.path}, already has metadata and content unchanged`);
|
|
21
28
|
return;
|
|
22
29
|
}
|
|
23
|
-
const content = await (0, promises_1.readFile)(file.path, 'utf-8');
|
|
24
30
|
file.metadata = await (0, extractMetadataFromMarkdown_1.extractMetadataFromMarkdown)(file.path, content);
|
|
31
|
+
// 记录提取 metadata 时的源文件 hash
|
|
32
|
+
file.hash = hash;
|
|
25
33
|
console.log(`✅ Extracted AI metadata for ${file.path}`, file.metadata.tokens_used);
|
|
26
34
|
}));
|
|
27
35
|
const errors = results.filter(r => r.status === 'rejected');
|
|
@@ -9,7 +9,6 @@ const path_1 = __importDefault(require("path"));
|
|
|
9
9
|
const findEntries_1 = require("../findEntries");
|
|
10
10
|
const metadata_1 = require("../metadata");
|
|
11
11
|
const paths_1 = require("../paths");
|
|
12
|
-
const sha256_1 = require("../utils/sha256");
|
|
13
12
|
const extractLinksFromMarkdown = (content) => {
|
|
14
13
|
const linkRegex = /\[.*?\]\((.*?)\)/g;
|
|
15
14
|
const links = [];
|
|
@@ -50,21 +49,17 @@ async function scanSourceFiles() {
|
|
|
50
49
|
continue;
|
|
51
50
|
}
|
|
52
51
|
const contentBuffer = await (0, promises_1.readFile)(fullPath);
|
|
53
|
-
const hash = (0, sha256_1.sha256)(contentBuffer);
|
|
54
52
|
paths.add(relativePath);
|
|
55
53
|
let meta = metadata_1.MetaData.files.find(f => f.path === relativePath);
|
|
56
54
|
if (!meta) {
|
|
57
|
-
meta = {
|
|
55
|
+
meta = { path: relativePath, links: [] };
|
|
58
56
|
metadata_1.MetaData.files.push(meta);
|
|
59
57
|
}
|
|
60
|
-
else {
|
|
61
|
-
meta.hash = hash;
|
|
62
|
-
}
|
|
63
58
|
// 处理 Markdown 文件
|
|
64
59
|
if (fullPath.endsWith('.md')) {
|
|
65
60
|
const content = contentBuffer.toString('utf-8');
|
|
66
61
|
const links = extractLinksFromMarkdown(content);
|
|
67
|
-
console.info(` - Found file: ${relativePath}
|
|
62
|
+
console.info(` - Found file: ${relativePath}`);
|
|
68
63
|
console.info(` Links: ${links.join(', ') || 'None'}`);
|
|
69
64
|
meta.links = links;
|
|
70
65
|
for (const link of links) {
|