Skip to content

Commit

Permalink
fix: Fix an issue where the module would attempt to generate og:local…
Browse files Browse the repository at this point in the history
…e tags without required ISO code

In the case where SEO features were enabled but the locales option did not contain required iso key,
the module would still attempt to generate those tags and thus crash the app, this adds a check on
ISO codes to prevent this error

Fixes #80
  • Loading branch information
paulgv committed May 10, 2018
1 parent f98c74e commit 5dd97d5
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/plugins/seo.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,28 @@ Vue.mixin({
.filter(item => !!item)

// og:locale meta
const meta = [
// Replace dash with underscore as defined in spec: language_TERRITORY
{ hid: 'og:locale', name: 'og:locale', property: 'og:locale', content: currentLocaleData[LOCALE_ISO_KEY].replace(/-/g, '_') },
const meta = []
// og:locale - current
if (currentLocaleData && currentLocaleData[LOCALE_ISO_KEY]) {
meta.push({
hid: 'og:locale',
name: 'og:locale',
property: 'og:locale',
// Replace dash with underscore as defined in spec: language_TERRITORY
content: currentLocaleData[LOCALE_ISO_KEY].replace(/-/g, '_')
})
}
// og:locale - alternate
meta.push(
...this.$i18n.locales
.filter(l => l[LOCALE_ISO_KEY] !== currentLocaleData[LOCALE_ISO_KEY])
.filter(l => l[LOCALE_ISO_KEY] && l[LOCALE_ISO_KEY] !== currentLocaleData[LOCALE_ISO_KEY])
.map(locale => ({
hid: 'og:locale:alternate-' + locale[LOCALE_ISO_KEY],
name: 'og:locale:alternate',
property: 'og:locale:alternate',
content: locale[LOCALE_ISO_KEY].replace(/-/g, '_')
}))
]
);

return {
htmlAttrs,
Expand Down

0 comments on commit 5dd97d5

Please sign in to comment.