pug-site-core 3.0.15 → 3.0.17

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 CHANGED
@@ -19,6 +19,7 @@ import UglifyJS from "uglify-js";
19
19
  import { minify as htmlMinify } from "html-minifier-terser";
20
20
  import { paths } from "./paths.js";
21
21
  import path from "path";
22
+ import { fetchABTestInfo } from "./utils.js";
22
23
 
23
24
  const { config } = await import(paths.config);
24
25
 
@@ -447,13 +448,18 @@ export async function buildFn() {
447
448
 
448
449
  let totalCommonData = {};
449
450
  totalCommonData.langCommon = config.commonData;
450
- let languageData = (await import(paths.languageData)).default
451
+ let languageData = (await import(paths.languageData)).default;
451
452
  await async.each(config.languageList, async (lang) => {
452
453
  let commonData = await (await import(paths.getData))["get_common_data"](lang);
453
454
  commonData.lang = _.merge(commonData.lang, languageData[lang]);
454
455
  totalCommonData[lang] = commonData;
455
456
  });
456
457
 
458
+ const ABTestInfo = await fetchABTestInfo(config.siteConfig.siteAbbr);
459
+ if (ABTestInfo) {
460
+ totalCommonData.langCommon.ABTestInfo = ABTestInfo;
461
+ }
462
+
457
463
  // await fse.copy(jsonDataPath, paths.resolveRoot(outputPath, "data"), {
458
464
  // filter: (src, dest) => {
459
465
  // // 排除_common.json 文件
package/lib/utils.js CHANGED
@@ -3,6 +3,7 @@ import path from "path";
3
3
  import JavaScriptObfuscator from "javascript-obfuscator";
4
4
  import { paths } from "./paths.js";
5
5
  import detectPort from "detect-port";
6
+ import axios from "axios";
6
7
 
7
8
 
8
9
  const { config } = await import(paths.config);
@@ -680,4 +681,21 @@ export async function getFilePathByFunctionName(functionName) {
680
681
  console.error("根据函数名查找文件路径失败:", error);
681
682
  return null;
682
683
  }
684
+ }
685
+
686
+ /**
687
+ * 获取 AB 测试信息
688
+ * @param {string} siteAbbr - 站点简称(如 config.siteConfig.siteAbbr)
689
+ * @returns {Promise<object|null>} 返回 ABTestInfo 对象或 null
690
+ */
691
+ export async function fetchABTestInfo(siteAbbr) {
692
+ try {
693
+ const res = await axios.get("http://new.sp.com/open-api/abtest-info", {
694
+ params: { site: siteAbbr },
695
+ });
696
+ return (res && res.data && res.data.result) ? res.data.result : null;
697
+ } catch (error) {
698
+ console.error("获取ABTestInfo失败:", error);
699
+ return null;
700
+ }
683
701
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pug-site-core",
3
- "version": "3.0.15",
3
+ "version": "3.0.17",
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": "取消压缩失败的massage log",
55
+ "description": "修改ABTest数据获取的接口",
56
56
  "files": [
57
57
  "lib/",
58
58
  "index.js"