wgt-node-utils 1.2.69 → 1.2.70

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.69",
3
+ "version": "1.2.70",
4
4
  "description": "WGT工具类包",
5
5
  "main": "dist/bundle.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -879,10 +879,10 @@ 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,time }) => {
882
+ seoFun = ({ url, name, image, author, aggregateRating, description, hostname, languageList, lang, title, type, applicationCategory, genre, time, logo }) => {
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,time });
885
- const seoRenderAlternateLink = this.renderAlternateLink({ languageList, url, pathWithoutLang, lang });
884
+ const seoRenderLdJson = this.renderLdJson({ pathWithoutLang, name, image, author, aggregateRating, description, hostname, type, languageList, applicationCategory, genre, time, logo });
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 = {
888
888
  seoRenderLdJson,
@@ -911,59 +911,71 @@ 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, time }) => {
915
- const currentType = type || 'WebApplication';
914
+ renderLdJson = ({ pathWithoutLang, name, image, author, aggregateRating, description, hostname, type, languageList, applicationCategory, genre, time, logo }) => {
915
+ const currentType = type || 'WebPage';
916
916
  const inLanguage = languageList ? languageList.map(item => item.code) : [];
917
917
  const organizationUrl = `https://${hostname}`;
918
-
919
- const ld = {
918
+ const siteName = author || hostname;
919
+ const siteLogo = logo;
920
+ let ld = {
920
921
  '@context': 'https://schema.org/',
921
- '@type': currentType,
922
+ '@type': currentType, // 默认为更通用的 WebPage
922
923
  'name': name,
923
924
  'description': description,
924
- 'url': url,
925
+ 'url': pathWithoutLang,
925
926
  'image': image,
926
- 'publisher': {
927
- '@type': 'Organization',
928
- 'name': author,
929
- 'url': organizationUrl
930
- },
931
- 'author': {
932
- '@type': 'Organization',
933
- 'name': author,
934
- 'url': organizationUrl
927
+
928
+ };
929
+ const orgStructure = {
930
+ '@type': 'Organization',
931
+ 'name': siteName,
932
+ 'url': organizationUrl,
933
+ 'logo': {
934
+ '@type': 'ImageObject',
935
+ 'url': siteLogo
935
936
  }
936
937
  };
937
-
938
+ const potentialAction = {
939
+ "@type": "SearchAction",
940
+ "target": `${organizationUrl}/search/{search_term_string}`,
941
+ "query-input": "required name=search_term_string"
942
+ }
938
943
  if (inLanguage.length > 0) {
939
944
  ld.inLanguage = inLanguage.length === 1 ? inLanguage[0] : inLanguage;
940
945
  }
941
946
 
942
- if (currentType === 'NewsArticle') {
943
- ld.headline = name && name.length > 110 ? name.substring(0, 110) : name;
947
+ if (type === 'NewsArticle') {
948
+ ld.headline = name?.substring(0, 110);
944
949
  ld.datePublished = time || new Date().toISOString();
945
- ld.mainEntityOfPage = {
946
- '@type': 'WebPage',
947
- '@id': url
950
+ ld.author = {
951
+ '@type': 'Person', // 新闻建议用 Person,或者具体的编辑名
952
+ 'name': siteName,
953
+ 'url': organizationUrl
948
954
  };
949
- } else {
955
+ ld.publisher = orgStructure;
956
+ ld.mainEntityOfPage = { '@type': 'WebPage', '@id': pathWithoutLang };
957
+ if (genre) ld.genre = genre;
958
+
959
+ } else if (type.includes("VideoGame") || type.includes("WebApplication")) {
950
960
  ld.operatingSystem = 'Web Browser';
951
961
  ld.applicationCategory = applicationCategory || 'BrowserGame';
952
962
  ld.offers = {
953
963
  '@type': 'Offer',
954
964
  'price': '0',
955
- 'priceCurrency': 'USD',
956
- 'availability': 'https://schema.org/InStock',
957
- 'url': url
965
+ 'priceCurrency': 'USD'
958
966
  };
959
-
960
- if (aggregateRating && typeof aggregateRating === 'object' && Object.keys(aggregateRating).length > 0) {
961
- ld.aggregateRating = aggregateRating;
967
+ // 修复 reviewCount 报错:必须有值且大于 0 才渲染
968
+ if (aggregateRating?.reviewCount > 0 && aggregateRating?.ratingValue > 0) {
969
+ ld.aggregateRating = {
970
+ '@type': 'AggregateRating',
971
+ 'ratingValue': aggregateRating.ratingValue,
972
+ 'reviewCount': aggregateRating.reviewCount
973
+ };
962
974
  }
963
- }
964
-
965
- if (genre) {
966
- ld.genre = genre;
975
+ } else {
976
+ ld['@type'] = 'WebSite';
977
+ ld.publisher = orgStructure;
978
+ ld.potentialAction = potentialAction;
967
979
  }
968
980
 
969
981
  return ld;