wgt-node-utils 1.2.66 → 1.2.67

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wgt-node-utils",
3
- "version": "1.2.66",
3
+ "version": "1.2.67",
4
4
  "description": "WGT工具类包",
5
5
  "main": "dist/bundle.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -879,9 +879,9 @@ class wgtNodeUtils {
879
879
  * @param {string} applicationCategory: 应用分类 BrowserGame BrowserNews
880
880
  * @param {string} genre: 游戏所属分类
881
881
  */
882
- seoFun = ({ url, name, image, author, aggregateRating, description, hostname, languageList, lang, title, type, applicationCategory, genre }) => {
882
+ seoFun = ({ url, name, image, author, aggregateRating, description, hostname, languageList, lang, title, type, applicationCategory, genre,time }) => {
883
883
  const pathWithoutLang = url ? url.replace(/(https?:\/\/[^/]+)\/en\b/, "$1") : '/';
884
- const seoRenderLdJson = this.renderLdJson({ pathWithoutLang, name, image, author, aggregateRating, description, hostname, type,languageList, applicationCategory, genre });
884
+ const seoRenderLdJson = this.renderLdJson({ pathWithoutLang, name, image, author, aggregateRating, description, hostname, type, languageList, applicationCategory, genre,time });
885
885
  const seoRenderAlternateLink = this.renderAlternateLink({ languageList, url, pathWithoutLang });
886
886
  const seoraphAndTwitterFun = this.graphAndTwitterFun({ image, url, title, hostname, description, lang, pathWithoutLang });
887
887
  const seoContent = {
@@ -911,63 +911,66 @@ class wgtNodeUtils {
911
911
  * @param applicationCategory: 应用分类 BrowserGame BrowserNews
912
912
  * @param genre: 游戏所属分类
913
913
  */
914
- renderLdJson = ({ url, name, image, author, aggregateRating, description, hostname, type, languageList, applicationCategory, genre }) => {
915
- if (!type) {
916
- type = 'WebApplication';
917
- }
918
- let inLanguage = [];
919
- if (languageList) {
920
- inLanguage = languageList.map(item => {
921
- return item.code;
922
- });
914
+ renderLdJson = ({ url, name, image, author, aggregateRating, description, hostname, type, languageList, applicationCategory, genre, time }) => {
915
+ if (!url || !name) {
916
+ console.warn('renderLdJson: missing required fields (url, name)');
917
+ return null;
923
918
  }
919
+
920
+ const currentType = type || 'WebApplication';
921
+ const inLanguage = languageList ? languageList.map(item => item.code) : [];
922
+ const organizationUrl = `https://${hostname}`;
923
+
924
924
  const ld = {
925
- '@context': 'https://schema.org/', // 语境
926
- '@type': type,
927
- 'name': name, // 网站名称
928
- 'author': {
929
- '@type': 'Organization',
930
- 'name': author
931
- },
932
- 'image': image,
925
+ '@context': 'https://schema.org/',
926
+ '@type': currentType,
927
+ 'name': name,
933
928
  'description': description,
934
- 'potentialAction': {
935
- '@type': 'SearchAction',
936
- 'target': `https://${hostname}/search/{search_term_string}`,
937
- 'query-input': 'required name=search_term_string'
938
- },
939
- 'inLanguage': inLanguage,
940
929
  'url': url,
941
- 'operatingSystem': 'Web Browser',
942
- 'applicationCategory': applicationCategory || 'BrowserGame',
943
- 'offers': {
944
- '@type': 'Offer',
945
- 'price': '0',
946
- 'priceCurrency': 'USD'
930
+ 'image': image,
931
+ 'publisher': {
932
+ '@type': 'Organization',
933
+ 'name': author,
934
+ 'url': organizationUrl
947
935
  },
948
- availableOnDevice: ["Mobile", "Tablet", "Desktop"],
949
- featureList: [
950
- 'No download required',
951
- 'Instant use in browser',
952
- 'Thousands of free content',
953
- 'Daily updates',
954
- 'Mobile compatible'
955
- ],
956
- isAccessibleForFree: true,
957
- "publisher": {
936
+ 'author': {
958
937
  '@type': 'Organization',
959
938
  'name': author,
960
- 'url': hostname
939
+ 'url': organizationUrl
961
940
  }
962
941
  };
963
- // 非详情页不增加该字段
964
- if (aggregateRating) {
965
- ld.aggregateRating = aggregateRating;
942
+
943
+ if (inLanguage.length > 0) {
944
+ ld.inLanguage = inLanguage.length === 1 ? inLanguage[0] : inLanguage;
966
945
  }
967
- // 仅部分页面拥有: 游戏所属分类
946
+
947
+ if (currentType === 'NewsArticle') {
948
+ ld.headline = name && name.length > 110 ? name.substring(0, 110) : name;
949
+ ld.datePublished = time || new Date().toISOString();
950
+ ld.mainEntityOfPage = {
951
+ '@type': 'WebPage',
952
+ '@id': url
953
+ };
954
+ } else {
955
+ ld.operatingSystem = 'Web Browser';
956
+ ld.applicationCategory = applicationCategory || 'BrowserGame';
957
+ ld.offers = {
958
+ '@type': 'Offer',
959
+ 'price': '0',
960
+ 'priceCurrency': 'USD',
961
+ 'availability': 'https://schema.org/InStock',
962
+ 'url': url
963
+ };
964
+
965
+ if (aggregateRating && typeof aggregateRating === 'object' && Object.keys(aggregateRating).length > 0) {
966
+ ld.aggregateRating = aggregateRating;
967
+ }
968
+ }
969
+
968
970
  if (genre) {
969
971
  ld.genre = genre;
970
972
  }
973
+
971
974
  return ld;
972
975
  }
973
976
 
@@ -977,7 +980,7 @@ class wgtNodeUtils {
977
980
  * @param {Array} languageList - 语言列表
978
981
  * @param {string} url - 页面URL
979
982
  */
980
- renderAlternateLink = ({ languageList, url, pathWithoutLang }) => {
983
+ renderAlternateLink = ({ languageList, url, pathWithoutLang }) => {
981
984
  const languageLinkList = languageList.map(item => ({
982
985
  rel: 'alternate',
983
986
  hrefLang: item.code === 'en' ? 'en' : item.code,