换行符

This commit is contained in:
辉鸭蛋
2024-10-11 02:48:18 +08:00
parent 7c0fb6be73
commit 7801ca2014
3 changed files with 18 additions and 14 deletions

View File

@@ -9,6 +9,10 @@ function calculateSHA1(filePath) {
return hashSum.digest('hex');
}
function convertNewlines(text) {
return text.replace(/\\n/g, '\n');
}
function extractInfoFromCombatFile(filePath) {
const content = fs.readFileSync(filePath, 'utf8');
const authorMatch = content.match(/\/\/\s*作者:(.*)/);
@@ -21,7 +25,7 @@ function extractInfoFromCombatFile(filePath) {
return {
author: authorMatch ? authorMatch[1].trim() : '',
description: descriptionMatch ? descriptionMatch[1].trim() : '',
description: descriptionMatch ? convertNewlines(descriptionMatch[1].trim()) : '',
tags: tags
};
}
@@ -34,7 +38,7 @@ function extractInfoFromJSFolder(folderPath) {
const manifest = JSON.parse(manifestContent);
return {
version: manifest.version || '',
description: manifest.description || '',
description: convertNewlines(manifest.description || ''),
author: manifest.authors && manifest.authors.length > 0 ? manifest.authors[0].name : '',
tags: []
};
@@ -51,7 +55,7 @@ function extractInfoFromPathingFile(filePath, parentFolders) {
const content = JSON.parse(fs.readFileSync(filePath, 'utf8'));
return {
author: content.info && content.info.author ? content.info.author : '',
description: '',
description: convertNewlines(content.info && content.info.description ? content.info.description : ''),
tags: parentFolders.slice(2) // 从第三个元素开始,跳过 'pathing' 和下一级目录
};
}
@@ -73,7 +77,7 @@ function extractInfoFromTCGFile(filePath, parentFolder) {
return {
author: authorMatch ? authorMatch[1].trim() : '',
description: descriptionMatch ? descriptionMatch[1].trim() : '',
description: descriptionMatch ? convertNewlines(descriptionMatch[1].trim()) : '',
tags: [...new Set(tags)] // 去重
};
}