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 40662e61..3180d6ac 100644 --- a/scripts/aem.js +++ b/scripts/aem.js @@ -239,6 +239,87 @@ 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 { + 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); + } + if (!document.head.querySelector(selector2)) { + const link = document.createElement('link'); + link.rel = 'alternate'; + 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) { + // 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 +799,7 @@ export { loadFooter, loadHeader, loadScript, + addAlternateLink, loadSection, loadSections, readBlockConfig,