pug-site-core 3.0.6 → 3.0.7
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.
- package/lib/generate.js +84 -104
- package/package.json +2 -2
package/lib/generate.js
CHANGED
|
@@ -544,29 +544,24 @@ export async function buildStatic() {
|
|
|
544
544
|
* @returns {string} 完整的HTML文件路径
|
|
545
545
|
*/
|
|
546
546
|
function buildHtmlPath(lang, outputPath, fileName = null) {
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
}
|
|
547
|
+
if (fileName) {
|
|
548
|
+
const htmlPath = paths.resolveRoot(
|
|
549
|
+
distOutputPath,
|
|
550
|
+
lang,
|
|
551
|
+
outputPath.replace(
|
|
552
|
+
outputPath
|
|
553
|
+
.split("/")
|
|
554
|
+
.pop()
|
|
555
|
+
.replace(/\.[^.]*$/, ""),
|
|
556
|
+
fileName.replace(/\.[^.]*$/, "")
|
|
557
|
+
)
|
|
558
|
+
);
|
|
559
|
+
console.log(htmlPath);
|
|
560
|
+
return htmlPath;
|
|
561
|
+
} else {
|
|
562
|
+
const htmlPath = paths.resolveRoot(distOutputPath, lang, outputPath);
|
|
564
563
|
console.log(htmlPath);
|
|
565
564
|
return htmlPath;
|
|
566
|
-
} catch (error) {
|
|
567
|
-
throw new Error(
|
|
568
|
-
`构建HTML路径失败 [lang: ${lang}, outputPath: ${outputPath}, fileName: ${fileName}]: ${error}`
|
|
569
|
-
);
|
|
570
565
|
}
|
|
571
566
|
}
|
|
572
567
|
|
|
@@ -574,21 +569,15 @@ export async function buildStatic() {
|
|
|
574
569
|
* 生成HTML内容
|
|
575
570
|
*/
|
|
576
571
|
function generateHtml(pagesPugToFn, funName, data, pagePath, commonData) {
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
throw new Error(`模板函数 ${funName} 不存在`);
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
return pagesPugToFn[funName]({
|
|
583
|
-
data,
|
|
584
|
-
_pagePath: pagePath,
|
|
585
|
-
common: commonData,
|
|
586
|
-
});
|
|
587
|
-
} catch (error) {
|
|
588
|
-
throw new Error(
|
|
589
|
-
`生成HTML失败 [funName: ${funName}, pagePath: ${pagePath}]: ${error}`
|
|
590
|
-
);
|
|
572
|
+
if (!pagesPugToFn[funName]) {
|
|
573
|
+
throw new Error(`模板函数 ${funName} 不存在`);
|
|
591
574
|
}
|
|
575
|
+
|
|
576
|
+
return pagesPugToFn[funName]({
|
|
577
|
+
data,
|
|
578
|
+
_pagePath: pagePath,
|
|
579
|
+
common: commonData,
|
|
580
|
+
});
|
|
592
581
|
}
|
|
593
582
|
|
|
594
583
|
/**
|
|
@@ -614,27 +603,21 @@ export async function buildStatic() {
|
|
|
614
603
|
const property = name.slice(1, -1);
|
|
615
604
|
|
|
616
605
|
await async.eachLimit(data, 128, async (dataItem, index) => {
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
throw new Error(`数据项索引 ${index} 中缺少属性 ${property} 或值为空`);
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
const htmlPath = buildHtmlPath(lang, obj.outPutHtmlPath, fileName);
|
|
624
|
-
const html = generateHtml(
|
|
625
|
-
pagesPugToFn,
|
|
626
|
-
funName,
|
|
627
|
-
dataItem,
|
|
628
|
-
pagePath,
|
|
629
|
-
commonData
|
|
630
|
-
);
|
|
631
|
-
const compressedHtml = await compressHtml(html, htmlPath);
|
|
632
|
-
await fse.outputFile(htmlPath, compressedHtml);
|
|
633
|
-
} catch (error) {
|
|
634
|
-
throw new Error(
|
|
635
|
-
`处理数组数据项失败 [index: ${index}, property: ${property}]: ${error}`
|
|
636
|
-
);
|
|
606
|
+
const fileName = dataItem[property];
|
|
607
|
+
if (!fileName) {
|
|
608
|
+
throw new Error(`数据项索引 ${index} 中缺少属性 ${property} 或值为空`);
|
|
637
609
|
}
|
|
610
|
+
|
|
611
|
+
const htmlPath = buildHtmlPath(lang, obj.outPutHtmlPath, fileName);
|
|
612
|
+
const html = generateHtml(
|
|
613
|
+
pagesPugToFn,
|
|
614
|
+
funName,
|
|
615
|
+
dataItem,
|
|
616
|
+
pagePath,
|
|
617
|
+
commonData
|
|
618
|
+
);
|
|
619
|
+
const compressedHtml = await compressHtml(html, htmlPath);
|
|
620
|
+
await fse.outputFile(htmlPath, compressedHtml);
|
|
638
621
|
});
|
|
639
622
|
} else {
|
|
640
623
|
const htmlPath = buildHtmlPath(lang, obj.outPutHtmlPath);
|
|
@@ -643,9 +626,10 @@ export async function buildStatic() {
|
|
|
643
626
|
await fse.outputFile(htmlPath, compressedHtml);
|
|
644
627
|
}
|
|
645
628
|
} catch (error) {
|
|
646
|
-
|
|
647
|
-
`处理数组数据失败 [lang: ${lang}, getDataFn: ${obj.getDataFn}]
|
|
629
|
+
console.error(
|
|
630
|
+
`处理数组数据失败 [lang: ${lang}, getDataFn: ${obj.getDataFn}]:`, error
|
|
648
631
|
);
|
|
632
|
+
throw error;
|
|
649
633
|
}
|
|
650
634
|
}
|
|
651
635
|
|
|
@@ -733,11 +717,10 @@ export async function buildStatic() {
|
|
|
733
717
|
throw new Error(`数据类型不支持: ${typeof data}`);
|
|
734
718
|
}
|
|
735
719
|
} catch (error) {
|
|
736
|
-
|
|
737
|
-
`处理自定义HTML构建失败 [lang: ${lang}, config: ${JSON.stringify(obj)}]
|
|
738
|
-
error
|
|
739
|
-
}`
|
|
720
|
+
console.error(
|
|
721
|
+
`处理自定义HTML构建失败 [lang: ${lang}, config: ${JSON.stringify(obj)}]:`,error
|
|
740
722
|
);
|
|
723
|
+
throw error;
|
|
741
724
|
}
|
|
742
725
|
});
|
|
743
726
|
}
|
|
@@ -758,55 +741,50 @@ export async function buildStatic() {
|
|
|
758
741
|
).filter((fileName) => fileName.endsWith(".json"));
|
|
759
742
|
|
|
760
743
|
await async.eachLimit(pagesAllJsonFileName, 128, async (jsonFileName) => {
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
const pugTemplate = data._template;
|
|
766
|
-
|
|
767
|
-
if (!pugTemplate) {
|
|
768
|
-
return;
|
|
769
|
-
}
|
|
744
|
+
const data = await fse.readJSON(
|
|
745
|
+
paths.resolveRoot(langDataPath, jsonFileName)
|
|
746
|
+
);
|
|
747
|
+
const pugTemplate = data._template;
|
|
770
748
|
|
|
771
|
-
|
|
749
|
+
if (!pugTemplate) {
|
|
750
|
+
return;
|
|
751
|
+
}
|
|
772
752
|
|
|
773
|
-
|
|
774
|
-
return;
|
|
775
|
-
}
|
|
753
|
+
const funName = pugTemplate.split(pathSymbol).join("_").slice(0, -4);
|
|
776
754
|
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
data,
|
|
781
|
-
pugTemplate,
|
|
782
|
-
commonData
|
|
783
|
-
);
|
|
755
|
+
if (dealWithEndFunName.has(funName)) {
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
784
758
|
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
}
|
|
759
|
+
const html = generateHtml(
|
|
760
|
+
pagesPugToFn,
|
|
761
|
+
funName,
|
|
762
|
+
data,
|
|
763
|
+
pugTemplate,
|
|
764
|
+
commonData
|
|
765
|
+
);
|
|
793
766
|
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
await fse.outputFile(htmlPath, compressedHtml);
|
|
802
|
-
} catch (error) {
|
|
803
|
-
throw new Error(
|
|
804
|
-
`处理JSON文件失败 [file: ${jsonFileName}]: ${error.message}`
|
|
805
|
-
);
|
|
767
|
+
// 构建输出路径
|
|
768
|
+
let finalPugTemplate = pugTemplate;
|
|
769
|
+
if (data.page_name) {
|
|
770
|
+
finalPugTemplate =
|
|
771
|
+
pugTemplate.split(pathSymbol).slice(0, -1).join(pathSymbol) +
|
|
772
|
+
pathSymbol +
|
|
773
|
+
data.page_name;
|
|
806
774
|
}
|
|
775
|
+
|
|
776
|
+
const htmlPath = paths.resolveRoot(
|
|
777
|
+
distOutputPath,
|
|
778
|
+
lang,
|
|
779
|
+
finalPugTemplate.replace(/\.[^.]*$/, ".html")
|
|
780
|
+
);
|
|
781
|
+
console.log(htmlPath);
|
|
782
|
+
const compressedHtml = await compressHtml(html, htmlPath);
|
|
783
|
+
await fse.outputFile(htmlPath, compressedHtml);
|
|
807
784
|
});
|
|
808
785
|
} catch (error) {
|
|
809
|
-
|
|
786
|
+
console.error(`处理页面JSON文件失败 [lang: ${lang}]:`, error);
|
|
787
|
+
throw error;
|
|
810
788
|
}
|
|
811
789
|
}
|
|
812
790
|
|
|
@@ -897,7 +875,8 @@ export async function buildStatic() {
|
|
|
897
875
|
|
|
898
876
|
console.log("处理语言:", lang, "完成");
|
|
899
877
|
} catch (error) {
|
|
900
|
-
|
|
878
|
+
console.error(`处理语言 ${lang} 失败:`, error);
|
|
879
|
+
throw error;
|
|
901
880
|
}
|
|
902
881
|
});
|
|
903
882
|
|
|
@@ -910,7 +889,8 @@ export async function buildStatic() {
|
|
|
910
889
|
const costTime = (Date.now() - startTime) / 1000;
|
|
911
890
|
console.log("混淆js文件耗时:", costTime, "s");
|
|
912
891
|
} catch (error) {
|
|
913
|
-
|
|
892
|
+
console.error(`混淆JavaScript文件失败:`, error);
|
|
893
|
+
throw error;
|
|
914
894
|
}
|
|
915
895
|
}
|
|
916
896
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pug-site-core",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.7",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"ws": "^8.18.0"
|
|
53
53
|
},
|
|
54
54
|
"license": "ISC",
|
|
55
|
-
"description": "
|
|
55
|
+
"description": "增加错误堆栈信息的处理",
|
|
56
56
|
"files": [
|
|
57
57
|
"lib/",
|
|
58
58
|
"index.js"
|