Skip to content

Commit 5dd97d5

Browse files
committed
fix: Fix an issue where the module would attempt to generate og:locale 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
1 parent f98c74e commit 5dd97d5

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/plugins/seo.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,28 @@ Vue.mixin({
3939
.filter(item => !!item)
4040

4141
// og:locale meta
42-
const meta = [
43-
// Replace dash with underscore as defined in spec: language_TERRITORY
44-
{ hid: 'og:locale', name: 'og:locale', property: 'og:locale', content: currentLocaleData[LOCALE_ISO_KEY].replace(/-/g, '_') },
42+
const meta = []
43+
// og:locale - current
44+
if (currentLocaleData && currentLocaleData[LOCALE_ISO_KEY]) {
45+
meta.push({
46+
hid: 'og:locale',
47+
name: 'og:locale',
48+
property: 'og:locale',
49+
// Replace dash with underscore as defined in spec: language_TERRITORY
50+
content: currentLocaleData[LOCALE_ISO_KEY].replace(/-/g, '_')
51+
})
52+
}
53+
// og:locale - alternate
54+
meta.push(
4555
...this.$i18n.locales
46-
.filter(l => l[LOCALE_ISO_KEY] !== currentLocaleData[LOCALE_ISO_KEY])
56+
.filter(l => l[LOCALE_ISO_KEY] && l[LOCALE_ISO_KEY] !== currentLocaleData[LOCALE_ISO_KEY])
4757
.map(locale => ({
4858
hid: 'og:locale:alternate-' + locale[LOCALE_ISO_KEY],
4959
name: 'og:locale:alternate',
5060
property: 'og:locale:alternate',
5161
content: locale[LOCALE_ISO_KEY].replace(/-/g, '_')
5262
}))
53-
]
63+
);
5464

5565
return {
5666
htmlAttrs,

0 commit comments

Comments
 (0)