Skip to content

Commit d8828c8

Browse files
authored
Generate og:url (#37)
* Add canonical URL as og:url * Update tests
1 parent 1616a4b commit d8828c8

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

packages/vue-i18n-routing/src/__test__/__snapshots__/compatibles.test.ts.snap

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ exports[`localeHead > composition mode > should be worked > en 1`] = `
3838
},
3939
],
4040
"meta": [
41+
{
42+
"content": "http://localhost:8080/en/about",
43+
"hid": "i18n-og-url",
44+
"property": "og:url",
45+
},
4146
{
4247
"content": "en_US",
4348
"hid": "i18n-og",
@@ -90,6 +95,11 @@ exports[`localeHead > composition mode > should be worked > ja 1`] = `
9095
},
9196
],
9297
"meta": [
98+
{
99+
"content": "http://localhost:8080/ja",
100+
"hid": "i18n-og-url",
101+
"property": "og:url",
102+
},
93103
{
94104
"content": "ja_JP",
95105
"hid": "i18n-og",
@@ -142,6 +152,11 @@ exports[`localeHead > legacy mode > should be worked > en 1`] = `
142152
},
143153
],
144154
"meta": [
155+
{
156+
"content": "http://localhost:8080/en/about",
157+
"hid": "i18n-og-url",
158+
"property": "og:url",
159+
},
145160
{
146161
"content": "en_US",
147162
"hid": "i18n-og",
@@ -194,6 +209,11 @@ exports[`localeHead > legacy mode > should be worked > ja 1`] = `
194209
},
195210
],
196211
"meta": [
212+
{
213+
"content": "http://localhost:8080/ja",
214+
"hid": "i18n-og-url",
215+
"property": "og:url",
216+
},
197217
{
198218
"content": "ja_JP",
199219
"hid": "i18n-og",

packages/vue-i18n-routing/src/compatibles/head.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,15 @@ export function localeHead(
5858
}
5959

6060
addHreflangLinks.call(this, locales as LocaleObject[], unref(i18n.baseUrl), metaObject.link, identifierAttribute)
61-
addCanonicalLinks.call(this, unref(i18n.baseUrl), metaObject.link, identifierAttribute, addSeoAttributes)
61+
// eslint-disable-next-line prettier/prettier
62+
addCanonicalLinksAndOgUrl.call(
63+
this,
64+
unref(i18n.baseUrl),
65+
metaObject.link,
66+
metaObject.meta,
67+
identifierAttribute,
68+
addSeoAttributes
69+
)
6270
addCurrentOgLocale(currentLocale, currentLocaleIso, metaObject.meta, identifierAttribute)
6371
addAlternateOgLocales(locales as LocaleObject[], currentLocaleIso, metaObject.meta, identifierAttribute)
6472
}
@@ -122,10 +130,11 @@ function addHreflangLinks(
122130
}
123131
}
124132

125-
function addCanonicalLinks(
133+
function addCanonicalLinksAndOgUrl(
126134
this: RoutingProxy,
127135
baseUrl: string,
128136
link: MetaAttrs,
137+
meta: MetaAttrs,
129138
identifierAttribute: NonNullable<I18nHeadOptions['identifierAttribute']>,
130139
seoAttributesOptions: I18nHeadOptions['addSeoAttributes']
131140
) {
@@ -167,6 +176,12 @@ function addCanonicalLinks(
167176
rel: 'canonical',
168177
href
169178
})
179+
180+
meta.push({
181+
[identifierAttribute]: 'i18n-og-url',
182+
property: 'og:url',
183+
content: href
184+
})
170185
}
171186
}
172187

packages/vue-i18n-routing/src/composables/__test__/__snapshots__/head.test.ts.snap

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ exports[`useLocaleHead > basic > should be worked > en 1`] = `
3838
},
3939
],
4040
"meta": [
41+
{
42+
"content": "http://localhost:8080/en/about",
43+
"hid": "i18n-og-url",
44+
"property": "og:url",
45+
},
4146
{
4247
"content": "en_US",
4348
"hid": "i18n-og",
@@ -90,6 +95,11 @@ exports[`useLocaleHead > basic > should be worked > ja 1`] = `
9095
},
9196
],
9297
"meta": [
98+
{
99+
"content": "http://localhost:8080/ja",
100+
"hid": "i18n-og-url",
101+
"property": "og:url",
102+
},
93103
{
94104
"content": "ja_JP",
95105
"hid": "i18n-og",

0 commit comments

Comments
 (0)