wgt-node-utils 1.2.60 → 1.2.62

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/eslint.config.mjs CHANGED
@@ -1,13 +1,13 @@
1
- import globals from "globals";
2
- import pluginJs from "@eslint/js";
3
- import tseslint from "typescript-eslint";
4
- import pluginReact from "eslint-plugin-react";
5
-
6
-
7
- export default [
8
- {files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"]},
9
- {languageOptions: { globals: globals.browser }},
10
- pluginJs.configs.recommended,
11
- ...tseslint.configs.recommended,
12
- pluginReact.configs.flat.recommended,
1
+ import globals from "globals";
2
+ import pluginJs from "@eslint/js";
3
+ import tseslint from "typescript-eslint";
4
+ import pluginReact from "eslint-plugin-react";
5
+
6
+
7
+ export default [
8
+ {files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"]},
9
+ {languageOptions: { globals: globals.browser }},
10
+ pluginJs.configs.recommended,
11
+ ...tseslint.configs.recommended,
12
+ pluginReact.configs.flat.recommended,
13
13
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wgt-node-utils",
3
- "version": "1.2.60",
3
+ "version": "1.2.62",
4
4
  "description": "WGT工具类包",
5
5
  "main": "dist/bundle.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -149,9 +149,9 @@ class wgtNodeUtils {
149
149
  */
150
150
  getImgDomainByHostname = (hostname, Env) => {
151
151
  let self = this;
152
- let needReplaceArr = [ 'pro', 'qa', 'dev', 'test', 'development' ];
152
+ let needReplaceArr = ['pro', 'qa', 'dev', 'test', 'development'];
153
153
  if (needReplaceArr.includes(Env)) {
154
- if(Env === 'qa' || Env === 'test') {
154
+ if (Env === 'qa' || Env === 'test') {
155
155
  return `http://test-service.gamebridge.games/image_server`
156
156
  }
157
157
  return `https://img.enjoy4fun.com`;
@@ -246,13 +246,13 @@ class wgtNodeUtils {
246
246
 
247
247
  // 增加preact依赖
248
248
  this.fileContents['preact.min.js'] = fs.readFileSync(path.join(dirname, `../${buildName}/dist/preact.min.js`), 'utf8');
249
-
249
+
250
250
  // 增加wgt-web-ui的css文件
251
251
  if (useGlobal) {
252
252
  // 获取wgt-web-ui的css文件
253
253
  this.fileContents['global.css'] = fs.readFileSync(path.join(dirname, `../${buildName}/assets/global.css`), 'utf8');
254
254
  }
255
-
255
+
256
256
 
257
257
  console.log('静态资源列表:');
258
258
 
@@ -846,5 +846,127 @@ class wgtNodeUtils {
846
846
  });
847
847
  }
848
848
 
849
+
850
+ // seo 相关标签
851
+ /**
852
+ *
853
+ * @param {string} url - 页面URL
854
+ * @param {string} name - 页面名称
855
+ * @param {string} image - 页面logo
856
+ * @param {string} author - 网站名称
857
+ * @param {string} aggregateRating - 页面评分
858
+ * @param {string} description - 页面描述
859
+ * @param {string} hostname - 网站域名
860
+ * @param {Array} languageList - 语言列表
861
+ * @param {string} lang - 语言代码
862
+ * @param {string} title - 页面标题
863
+ */
864
+ seoFun = ({ url, name, image, author, aggregateRating, description, hostname, languageList, lang, title }) => {
865
+ const pathWithoutLang = url ? url.replace(/(https?:\/\/[^/]+)\/en\b/, "$1") : '/';
866
+ const seoRenderLdJson = this.renderLdJson({ pathWithoutLang, name, image, author, aggregateRating, description, hostname });
867
+ const seoRenderAlternateLink = this.renderAlternateLink({ languageList, url, pathWithoutLang });
868
+ const seoraphAndTwitterFun = this.graphAndTwitterFun({ image, url, title, hostname, description, lang, pathWithoutLang });
869
+ const seoContent = {
870
+ seoRenderLdJson,
871
+ seoRenderAlternateLink,
872
+ seoraphAndTwitterFun
873
+ }
874
+ return { seoContent }
875
+ }
876
+ /**
877
+ * renderLdJson 生成结构化数据,用于在google搜索结果中展示卡片
878
+ * @param url: 页面url
879
+ * @param name: 页面名称
880
+ * @param image: 页面logo
881
+ * @param author: 网站名称
882
+ * @param aggregateRating: 页面评分 示例:{
883
+ '@type': 'AggregateRating',
884
+ 'ratingValue': 4.8,
885
+ 'reviewCount': players,
886
+ 'bestRating': 5,
887
+ 'worstRating': 1
888
+ }
889
+ * @param description: 页面描述
890
+ * @param hostname: 网站域名
891
+ */
892
+ renderLdJson = ({ url, name, image, author, aggregateRating, description, hostname }) => {
893
+ const ld = {
894
+ '@context': 'https://schema.org/', // 语境
895
+ '@type': 'WebPage',
896
+ 'name': name, // 网站名称
897
+ 'author': {
898
+ '@type': 'Organization',
899
+ 'name': author
900
+ },
901
+ 'image': image,
902
+ 'description': description,
903
+ 'potentialAction': {
904
+ '@type': 'SearchAction',
905
+ 'target': `https://${hostname}/search/{search_term_string}`,
906
+ 'query-input': 'required name=search_term_string'
907
+ },
908
+ 'url': url,
909
+ 'operatingSystem': 'Web Browser',
910
+ 'applicationCategory': 'BrowserGame',
911
+ 'offers': {
912
+ '@type': 'Offer',
913
+ 'price': '0',
914
+ 'priceCurrency': 'USD'
915
+ },
916
+ "publisher": {
917
+ '@type': 'Organization',
918
+ 'name': author,
919
+ 'url': hostname
920
+ }
921
+ };
922
+ // 非详情页不增加该字段
923
+ if (aggregateRating) {
924
+ ld.aggregateRating = aggregateRating;
925
+ }
926
+ return ld;
927
+ }
928
+
929
+ // 国际化 hreflang 标签配置
930
+ /**
931
+ *
932
+ * @param {Array} languageList - 语言列表
933
+ * @param {string} url - 页面URL
934
+ */
935
+ renderAlternateLink = ({ languageList, url, pathWithoutLang }) => {
936
+ const languageLinkList = languageList.map(item => ({
937
+ rel: 'alternate',
938
+ hrefLang: item.code === 'en' ? 'en' : item.code,
939
+ href: item.code === 'en' ? pathWithoutLang : url
940
+ }));
941
+ languageLinkList.push({ rel: 'alternate', hrefLang: 'x-default', href: pathWithoutLang });
942
+ return languageLinkList
943
+ }
944
+ // Open Graph 和 Twitter Card 站外引流触点
945
+ graphAndTwitterFun = ({ image, title, hostname, description, lang, pathWithoutLang }) => {
946
+
947
+ // 处理图片URL,确保是完整的URL
948
+ const siteUrl = `${pathWithoutLang || ''}`;
949
+
950
+ return [
951
+ { property: 'og:type', content: 'website' },
952
+ { property: 'og:site_name', content: hostname },
953
+ { property: 'og:title', content: title },
954
+ { property: 'og:description', content: description },
955
+ { property: 'og:url', content: siteUrl },
956
+ { property: 'og:image', content: image },
957
+ { property: 'og:image:alt', content: title },
958
+ { property: 'og:image:width', content: '1200' },
959
+ { property: 'og:image:height', content: '600' },
960
+ { property: 'og:locale', content: lang === 'en' ? 'en_US' : lang === 'zh' ? 'zh_CN' : `${lang}_${lang.toUpperCase()}` },
961
+ { name: 'twitter:card', content: 'summary_large_image' },
962
+ { name: 'twitter:site', content: '' },
963
+ { name: 'twitter:title', content: title },
964
+ { name: 'twitter:description', content: description },
965
+ { name: 'twitter:image', content: image },
966
+ { name: 'twitter:image:alt', content: title },
967
+ { name: 'twitter:url', content: siteUrl },
968
+ ];
969
+ }
970
+
849
971
  }
850
972
  module.exports = new wgtNodeUtils('cli_a538bc45e770d00b', 'EDK1uleQyLym6WWDISo00dwx4gssiskJ');