Skip to content

Commit

Permalink
exclude some tags from context
Browse files Browse the repository at this point in the history
  • Loading branch information
jemikanegara committed Aug 16, 2024
1 parent f0da8b0 commit c85773a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions utils/translation/extractTextNodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ const { getGlobalseoOptions, shouldTranslateInlineText, CONTEXT_LIMIT, MAX_WORDS
const { isExcludedClassName, isExcludedId } = require("./isExcluded");
const isUrl = require("./isUrl");

function collectAllTextContentInsideNode(node, shouldExclude = false) {
const globalseoOptions = getGlobalseoOptions();
function isIgnoredTagInContext(tagName) {
return tagName && ["HTML", "HEAD", "SCRIPT", "STYLE", "SVG", "PATH", "CIRCLE", "TEXTAREA", "INPUT", "SELECT", "OPTION", "NOSCRIPT"].includes(tagName.toUpperCase())
}

function collectAllTextContentInsideNode(node, shouldExclude = false) {
const textNodes = [];
if (isIgnoredTagInContext(node.tagName)) {
return textNodes
}

node.childNodes.forEach((child) => {
if (shouldExclude && child && child.className && typeof child.className == "string" && (child.className.includes(OLD_EXCLUDE_CLASS) || child.className.includes("globalseo-exclude"))) return;

Expand All @@ -22,6 +28,9 @@ function collectAllTextContentInsideNode(node, shouldExclude = false) {
return;
};

// if script tag or style tag skip
if (isIgnoredTagInContext(child.tagName)) return;

if (child.nodeType === Node.TEXT_NODE && child.textContent.trim()) {
textNodes.push(child);
}
Expand Down

0 comments on commit c85773a

Please sign in to comment.