wgt-node-utils 1.2.67 → 1.2.69

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.67",
3
+ "version": "1.2.69",
4
4
  "description": "WGT工具类包",
5
5
  "main": "dist/bundle.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -882,7 +882,7 @@ class wgtNodeUtils {
882
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
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 });
885
+ const seoRenderAlternateLink = this.renderAlternateLink({ languageList, url, pathWithoutLang, lang });
886
886
  const seoraphAndTwitterFun = this.graphAndTwitterFun({ image, url, title, hostname, description, lang, pathWithoutLang });
887
887
  const seoContent = {
888
888
  seoRenderLdJson,
@@ -912,11 +912,6 @@ class wgtNodeUtils {
912
912
  * @param genre: 游戏所属分类
913
913
  */
914
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;
918
- }
919
-
920
915
  const currentType = type || 'WebApplication';
921
916
  const inLanguage = languageList ? languageList.map(item => item.code) : [];
922
917
  const organizationUrl = `https://${hostname}`;
@@ -980,14 +975,18 @@ class wgtNodeUtils {
980
975
  * @param {Array} languageList - 语言列表
981
976
  * @param {string} url - 页面URL
982
977
  */
983
- renderAlternateLink = ({ languageList, url, pathWithoutLang }) => {
978
+ renderAlternateLink = ({ languageList, url, pathWithoutLang, lang }) => {
984
979
  const languageLinkList = languageList.map(item => ({
985
980
  rel: 'alternate',
986
981
  hrefLang: item.code === 'en' ? 'en' : item.code,
987
982
  href: item.code === 'en' ? pathWithoutLang : url.replace(/(https?:\/\/[^/]+)\/en(?=\/|$)/, `$1/${item.code}`)
988
983
  }));
989
984
  languageLinkList.push({ rel: 'alternate', hrefLang: 'x-default', href: pathWithoutLang });
990
- languageLinkList.push({ rel: 'canonical', href: pathWithoutLang });
985
+ // canonical 指向当前语言的实际 URL,非英语语言需替换为对应语言路径
986
+ const canonicalUrl = (lang && lang !== 'en')
987
+ ? url.replace(/(https?:\/\/[^/]+)\/en(?=\/|$)/, `$1/${lang}`)
988
+ : pathWithoutLang;
989
+ languageLinkList.push({ rel: 'canonical', href: canonicalUrl });
991
990
  return languageLinkList
992
991
  }
993
992
  // Open Graph 和 Twitter Card 站外引流触点