From 88b39486769d4bd264158b9c184b6965c3b86409 Mon Sep 17 00:00:00 2001 From: Gayathri Anchal M K_C Date: Fri, 28 Nov 2025 10:16:33 +0530 Subject: [PATCH 1/5] added href and check only for en-us --- scripts/aem.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/scripts/aem.js b/scripts/aem.js index 40662e61..3090bcfd 100644 --- a/scripts/aem.js +++ b/scripts/aem.js @@ -239,6 +239,47 @@ async function loadCSS(href) { }); } +/** + * Adds an alternate hreflang link into the document head. + * Uses getRegionLocale to dynamically construct the href based on current page region/locale. + * @param {string} [hreflang='en-US'] language-region value (e.g. "en-US") + * @param {string} [href] URL for the alternate page (auto-generated if not provided) + */ +async function addAlternateLink(){ + try { + // Import getRegionLocale to get current region and locale + const { getRegionLocale } = await import('./utils.js'); + const [region, locale] = getRegionLocale(); + const href = `https://www.ingredion.com/${region}/${locale}/company/careers`; + // Convert locale format from en-us to en-US for hreflang (get last part and uppercase it) + const parts = locale.split('-'); + const hreflang = `${parts[0]}-${parts[1].toUpperCase()}`; + const selector = `link[rel="alternate"][hreflang="${hreflang}"][href="${href}"]`; + + if (!document.head.querySelector(selector)) { + const link = document.createElement('link'); + link.rel = 'alternate'; + link.hreflang = hreflang; + link.href = href; + document.head.appendChild(link); + } + } catch (err) { + // silently ignore if DOM is not available or other error + // eslint-disable-next-line no-console + console.debug('addAlternateLink error:', err); + } +} + +// Ensure the alternate link is added once DOM is ready +if (typeof document !== 'undefined') { + if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', () => addAlternateLink()); + } else { + addAlternateLink(); + } +} + + /** * Loads a non module JS file. * @param {string} src URL to the JS file @@ -718,6 +759,7 @@ export { loadFooter, loadHeader, loadScript, + addAlternateLink, loadSection, loadSections, readBlockConfig, From 18c78d69e3f4c80d490f23e500a901fd47d6d2cd Mon Sep 17 00:00:00 2001 From: Gayathri Anchal M K_C Date: Thu, 4 Dec 2025 16:12:20 +0530 Subject: [PATCH 2/5] added href for all regions --- scripts/aem.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/scripts/aem.js b/scripts/aem.js index 3090bcfd..b4f933a9 100644 --- a/scripts/aem.js +++ b/scripts/aem.js @@ -250,10 +250,19 @@ async function addAlternateLink(){ // Import getRegionLocale to get current region and locale const { getRegionLocale } = await import('./utils.js'); const [region, locale] = getRegionLocale(); - const href = `https://www.ingredion.com/${region}/${locale}/company/careers`; - // Convert locale format from en-us to en-US for hreflang (get last part and uppercase it) + var companycarrer='company/careers'; const parts = locale.split('-'); - const hreflang = `${parts[0]}-${parts[1].toUpperCase()}`; + var hreflang = `${parts[0]}-${parts[1].toUpperCase()}`; + + if (locale === 'es-mx') + companycarrer='compania/carrera'; + else if (locale === 'pt-br') + companycarrer='institucional/carreiras-na-ingredion'; + else if (locale === 'es-co') + companycarrer='nuestra-compania/carreras'; + if(locale === 'en-uk') + hreflang = 'en-GB'; + const href = `https://www.ingredion.com/${region}/${locale}/${companycarrer}`; const selector = `link[rel="alternate"][hreflang="${hreflang}"][href="${href}"]`; if (!document.head.querySelector(selector)) { From 833bf49a092e96d1bf59693ec8a5bf2705bbb1d0 Mon Sep 17 00:00:00 2001 From: Gayathri Anchal M K_C Date: Thu, 4 Dec 2025 16:22:35 +0530 Subject: [PATCH 3/5] added href for all regions with lint --- scripts/aem.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/scripts/aem.js b/scripts/aem.js index b4f933a9..1e558003 100644 --- a/scripts/aem.js +++ b/scripts/aem.js @@ -245,23 +245,24 @@ async function loadCSS(href) { * @param {string} [hreflang='en-US'] language-region value (e.g. "en-US") * @param {string} [href] URL for the alternate page (auto-generated if not provided) */ -async function addAlternateLink(){ +async function addAlternateLink() { try { // Import getRegionLocale to get current region and locale + let companycarrer = 'company/careers'; const { getRegionLocale } = await import('./utils.js'); const [region, locale] = getRegionLocale(); - var companycarrer='company/careers'; const parts = locale.split('-'); - var hreflang = `${parts[0]}-${parts[1].toUpperCase()}`; - - if (locale === 'es-mx') - companycarrer='compania/carrera'; - else if (locale === 'pt-br') - companycarrer='institucional/carreiras-na-ingredion'; - else if (locale === 'es-co') - companycarrer='nuestra-compania/carreras'; - if(locale === 'en-uk') + let hreflang = `${parts[0]}-${parts[1].toUpperCase()}`; + + if (locale === 'es-mx'){ + companycarrer = 'compania/carrera'; + }else if (locale === 'pt-br'){ + companycarrer = 'institucional/carreiras-na-ingredion'; + }else if (locale === 'es-co') + companycarrer = 'nuestra-compania/carreras'; + if(locale === 'en-uk'){ hreflang = 'en-GB'; + } const href = `https://www.ingredion.com/${region}/${locale}/${companycarrer}`; const selector = `link[rel="alternate"][hreflang="${hreflang}"][href="${href}"]`; From a2715ee7b13283d96d9a582aa61661692157a27a Mon Sep 17 00:00:00 2001 From: Gayathri Anchal M K_C Date: Thu, 4 Dec 2025 17:43:54 +0530 Subject: [PATCH 4/5] spaces --- .eslintrc.json | 32 ++++++++++++++++++++++++++++++++ .vscode/extensions.json | 5 +++++ .vscode/settings.json | 13 +++++++++++++ scripts/aem.js | 16 +++++++--------- 4 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 .eslintrc.json create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 00000000..ab240fff --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,32 @@ +{ + "root": true, + "env": { + "browser": true, + "node": true, + "es2021": true + }, + "parser": "@babel/eslint-parser", + "parserOptions": { + "requireConfigFile": false, + "ecmaVersion": 2021, + "sourceType": "module" + }, + "extends": [ + "airbnb-base" + ], + "rules": { + "indent": ["error", 2], + "no-trailing-spaces": "error", + "space-before-function-paren": ["error", { + "anonymous": "always", + "named": "never", + "asyncArrow": "always" + }], + "keyword-spacing": ["error", { "before": true, "after": true }], + "space-in-parens": ["error", "never"], + "array-bracket-spacing": ["error", "never"], + "object-curly-spacing": ["error", "always"], + "comma-spacing": ["error", { "before": false, "after": true }], + "space-before-blocks": ["error", "always"] + } +} diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 00000000..b308e589 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "dbaeumer.vscode-eslint" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..1a977bd7 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,13 @@ +{ + "editor.codeActionsOnSave": { + "source.fixAll.eslint": true + }, + "eslint.validate": [ + "javascript", + "javascriptreact", + "typescript", + "typescriptreact" + ], + "eslint.alwaysShowStatus": true, + "eslint.format.enable": true +} diff --git a/scripts/aem.js b/scripts/aem.js index 1e558003..31a6716a 100644 --- a/scripts/aem.js +++ b/scripts/aem.js @@ -254,18 +254,17 @@ async function addAlternateLink() { const parts = locale.split('-'); let hreflang = `${parts[0]}-${parts[1].toUpperCase()}`; - if (locale === 'es-mx'){ - companycarrer = 'compania/carrera'; - }else if (locale === 'pt-br'){ + if (locale === 'es-mx') { + companycarrer = 'compania/carrera'; + } else if (locale === 'pt-br') { companycarrer = 'institucional/carreiras-na-ingredion'; - }else if (locale === 'es-co') - companycarrer = 'nuestra-compania/carreras'; - if(locale === 'en-uk'){ - hreflang = 'en-GB'; + } else if (locale === 'es-co') { companycarrer = 'nuestra-compania/carreras'; } + if (locale === 'en-uk') { + hreflang = 'en-GB'; } const href = `https://www.ingredion.com/${region}/${locale}/${companycarrer}`; const selector = `link[rel="alternate"][hreflang="${hreflang}"][href="${href}"]`; - + if (!document.head.querySelector(selector)) { const link = document.createElement('link'); link.rel = 'alternate'; @@ -289,7 +288,6 @@ if (typeof document !== 'undefined') { } } - /** * Loads a non module JS file. * @param {string} src URL to the JS file From f0aa3b9e19defcaa289542a76778d741210f1d0c Mon Sep 17 00:00:00 2001 From: Gayathri Anchal M K_C Date: Thu, 4 Dec 2025 23:50:55 +0530 Subject: [PATCH 5/5] included all 7 regions --- scripts/aem.js | 72 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 20 deletions(-) diff --git a/scripts/aem.js b/scripts/aem.js index 31a6716a..3180d6ac 100644 --- a/scripts/aem.js +++ b/scripts/aem.js @@ -247,29 +247,61 @@ async function loadCSS(href) { */ async function addAlternateLink() { try { - // Import getRegionLocale to get current region and locale - let companycarrer = 'company/careers'; - const { getRegionLocale } = await import('./utils.js'); - const [region, locale] = getRegionLocale(); - const parts = locale.split('-'); - let hreflang = `${parts[0]}-${parts[1].toUpperCase()}`; - - if (locale === 'es-mx') { - companycarrer = 'compania/carrera'; - } else if (locale === 'pt-br') { - companycarrer = 'institucional/carreiras-na-ingredion'; - } else if (locale === 'es-co') { companycarrer = 'nuestra-compania/carreras'; } - if (locale === 'en-uk') { - hreflang = 'en-GB'; + const selector1 = 'link[rel="alternate"][hreflang="en-US"][href="https://www.ingredion.com/na/en-us/company/careers"]'; + const selector2 = 'link[rel="alternate"][hreflang="en-UK"][href="https://www.ingredion.com/emea/en-uk/company/careers"]'; + const selector3 = 'link[rel="alternate"][hreflang="en-SG"][href="https://www.ingredion.com/apac/en-sg/company/careers"]'; + const selector4 = 'link[rel="alternate"][hreflang="es-MX"][href="https://www.ingredion.com/na/es-mx/compania/carrera"]'; + const selector5 = 'link[rel="alternate"][hreflang="es-CO"][href="https://www.ingredion.com/sa/es-co/nuestra-compania/carreras"]'; + const selector6 = 'link[rel="alternate"][hreflang="pt-BR"][href="https://www.ingredion.com/sa/pt-br/institucional/carreiras-na-ingredion"]'; + const selector7 = 'link[rel="alternate"][hreflang="ja-JP"][href="https://www.ingredion.com/apac/ja-jp/company/careers"]'; + + if (!document.head.querySelector(selector1)) { + const link = document.createElement('link'); + link.rel = 'alternate'; + link.hreflang = 'en-US'; + link.href = 'https://www.ingredion.com/na/en-us/company/careers'; + document.head.appendChild(link); } - const href = `https://www.ingredion.com/${region}/${locale}/${companycarrer}`; - const selector = `link[rel="alternate"][hreflang="${hreflang}"][href="${href}"]`; - - if (!document.head.querySelector(selector)) { + if (!document.head.querySelector(selector2)) { const link = document.createElement('link'); link.rel = 'alternate'; - link.hreflang = hreflang; - link.href = href; + link.hreflang = 'en-UK'; + link.href = 'https://www.ingredion.com/emea/en-uk/company/careers'; + document.head.appendChild(link); + } + if (!document.head.querySelector(selector3)) { + const link = document.createElement('link'); + link.rel = 'alternate'; + link.hreflang = 'en-SG'; + link.href = 'https://www.ingredion.com/apac/en-sg/company/careers'; + document.head.appendChild(link); + } + if (!document.head.querySelector(selector4)) { + const link = document.createElement('link'); + link.rel = 'alternate'; + link.hreflang = 'es-MX'; + link.href = 'https://www.ingredion.com/na/es-mx/compania/carrera'; + document.head.appendChild(link); + } + if (!document.head.querySelector(selector5)) { + const link = document.createElement('link'); + link.rel = 'alternate'; + link.hreflang = 'es-CO'; + link.href = 'https://www.ingredion.com/sa/es-co/nuestra-compania/carreras'; + document.head.appendChild(link); + } + if (!document.head.querySelector(selector6)) { + const link = document.createElement('link'); + link.rel = 'alternate'; + link.hreflang = 'pt-BR'; + link.href = 'https://www.ingredion.com/sa/pt-br/institucional/carreiras-na-ingredion'; + document.head.appendChild(link); + } + if (!document.head.querySelector(selector7)) { + const link = document.createElement('link'); + link.rel = 'alternate'; + link.hreflang = 'ja-JP'; + link.href = 'https://www.ingredion.com/apac/ja-jp/company/careers'; document.head.appendChild(link); } } catch (err) {