Skip to content

Commit

Permalink
fix(client): merge locales head correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy committed Dec 14, 2023
1 parent 0a4cc04 commit 2fe35bb
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
17 changes: 14 additions & 3 deletions e2e/docs/.vuepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,31 @@ import { e2eTheme } from './theme/node/e2eTheme.js'
export default defineUserConfig({
base: '/',

head: [],
head: [
['meta', { name: 'foo', content: 'foo' }],
['meta', { name: 'bar', content: 'bar' }],
['meta', { name: 'baz', content: 'baz' }],
],

locales: {
'/': {
lang: 'en-US',
title: 'VuePress E2E',
description: 'VuePress E2E Test Site',
head: [],
head: [
['meta', { name: 'foo-en', content: 'foo-en' }],
['meta', { name: 'bar', content: 'foobar' }],
['meta', { name: 'baz', content: 'foobar baz' }],
],
},
'/zh/': {
lang: 'zh-CN',
title: 'VuePress E2E',
description: 'VuePress E2E 测试站点',
head: [],
head: [
['meta', { name: 'foo-zh', content: 'foo-zh' }],
['meta', { name: 'bar', content: 'foobar zh' }],
],
},
},

Expand Down
Binary file added e2e/docs/.vuepress/public/favicon.ico
Binary file not shown.
Binary file added e2e/docs/.vuepress/public/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 24 additions & 2 deletions e2e/tests/site-data.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,18 @@ describe('siteData', () => {
})

it('head', () => {
// TODO
cy.get('head meta[name="foo"]')
.should('have.length', 1)
.should('have.attr', 'content', 'foo')
cy.get('head meta[name="bar"]')
.should('have.length', 1)
.should('have.attr', 'content', 'foobar')
cy.get('head meta[name="baz"]')
.should('have.length', 1)
.should('have.attr', 'content', 'foobar baz')
cy.get('head meta[name="foo-en"]')
.should('have.length', 1)
.should('have.attr', 'content', 'foo-en')
})
})

Expand All @@ -49,7 +60,18 @@ describe('siteData', () => {
})

it('head', () => {
// TODO
cy.get('head meta[name="foo"]')
.should('have.length', 1)
.should('have.attr', 'content', 'foo')
cy.get('head meta[name="bar"]')
.should('have.length', 1)
.should('have.attr', 'content', 'foobar zh')
cy.get('head meta[name="baz"]')
.should('have.length', 1)
.should('have.attr', 'content', 'baz')
cy.get('head meta[name="foo-zh"]')
.should('have.length', 1)
.should('have.attr', 'content', 'foo-zh')
})
})
})
6 changes: 6 additions & 0 deletions packages/client/src/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,11 @@ export const resolvers = reactive({
): SiteLocaleData => ({
...site,
...site.locales[routeLocale],
head: [
// when merging head, the locales head should be placed before root head
// to get higher priority
...(site.locales[routeLocale]?.head ?? []),
...(site.head ?? []),
],
}),
})

0 comments on commit 2fe35bb

Please sign in to comment.