wgt-node-utils 1.2.68 → 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/dist/bundle.js +1 -1
- package/package.json +1 -1
- package/src/index.js +7 -3
package/package.json
CHANGED
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,
|
|
@@ -975,14 +975,18 @@ class wgtNodeUtils {
|
|
|
975
975
|
* @param {Array} languageList - 语言列表
|
|
976
976
|
* @param {string} url - 页面URL
|
|
977
977
|
*/
|
|
978
|
-
renderAlternateLink = ({ languageList, url, pathWithoutLang }) => {
|
|
978
|
+
renderAlternateLink = ({ languageList, url, pathWithoutLang, lang }) => {
|
|
979
979
|
const languageLinkList = languageList.map(item => ({
|
|
980
980
|
rel: 'alternate',
|
|
981
981
|
hrefLang: item.code === 'en' ? 'en' : item.code,
|
|
982
982
|
href: item.code === 'en' ? pathWithoutLang : url.replace(/(https?:\/\/[^/]+)\/en(?=\/|$)/, `$1/${item.code}`)
|
|
983
983
|
}));
|
|
984
984
|
languageLinkList.push({ rel: 'alternate', hrefLang: 'x-default', href: pathWithoutLang });
|
|
985
|
-
|
|
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 });
|
|
986
990
|
return languageLinkList
|
|
987
991
|
}
|
|
988
992
|
// Open Graph 和 Twitter Card 站外引流触点
|