From 3198658b92183f8a65c1444820ef6f19ac2bdcea Mon Sep 17 00:00:00 2001 From: jemikanegara Date: Mon, 18 Nov 2024 22:15:35 +0800 Subject: [PATCH] support asterisk & trailing slash for exclude pathname --- utils/translation/isExcluded.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/utils/translation/isExcluded.js b/utils/translation/isExcluded.js index b6449e5..3eda1f8 100644 --- a/utils/translation/isExcluded.js +++ b/utils/translation/isExcluded.js @@ -20,6 +20,13 @@ function isExcludedPath(window) { const globalseoOptions = getGlobalseoOptions(window); const path = window.location.pathname; - return globalseoOptions.excludePaths.length && globalseoOptions.excludePaths.some(excludePath => excludePath && path.startsWith(excludePath)) + return globalseoOptions.excludePaths.length && globalseoOptions.excludePaths.some(excludePath => { + if (!excludePath) return false; + const isEndedWithStar = excludePath.endsWith('/*'); + if (isEndedWithStar) return path.startsWith(excludePath.slice(0, -1)); + const isEndedWithSlash = excludePath.endsWith('/'); + const withoutSlashPath = isEndedWithSlash ? excludePath.slice(0, -1) : excludePath; + return (path === excludePath) || (path == withoutSlashPath); + }) } exports.isExcludedPath = isExcludedPath;