Skip to content
Open

Href #665

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -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"]
}
}
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"dbaeumer.vscode-eslint"
]
}
13 changes: 13 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
],
"eslint.alwaysShowStatus": true,
"eslint.format.enable": true
}
82 changes: 82 additions & 0 deletions scripts/aem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"]';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is not meant to be modified.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should I make changes in script.js

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
Expand Down Expand Up @@ -718,6 +799,7 @@ export {
loadFooter,
loadHeader,
loadScript,
addAlternateLink,
loadSection,
loadSections,
readBlockConfig,
Expand Down
Loading