-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into test-header-menu
- Loading branch information
Showing
31 changed files
with
175 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { PageContext } from 'vike/types' | ||
|
||
import { extractLocale } from '#src/locales' | ||
|
||
export function onBeforeRoute(pageContext: PageContext) { | ||
const { urlWithoutLocale, locale } = extractLocale(pageContext.urlPathname) | ||
|
||
return { | ||
pageContext: { | ||
// Make `locale` available as `pageContext.locale` | ||
locale, | ||
// Vike's router will use pageContext.urlLogical instead of pageContext.urlOriginal | ||
urlLogical: urlWithoutLocale, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { PageContextServer } from 'vike/types' | ||
|
||
import { locales } from '#src/locales' | ||
|
||
export { onPrerenderStart } | ||
|
||
function onPrerenderStart(prerenderContext: { pageContexts: PageContextServer[] }): { | ||
prerenderContext: { | ||
pageContexts: PageContextServer[] | ||
} | ||
} { | ||
const storePageContexts: PageContextServer[] = [] | ||
prerenderContext.pageContexts.forEach((pageContext) => { | ||
// Duplicate pageContext for each locale | ||
locales.forEach((locale) => { | ||
// Localize URL | ||
let { urlOriginal } = pageContext | ||
urlOriginal = `/${locale}${urlOriginal}` | ||
storePageContexts.push({ | ||
...pageContext, | ||
urlOriginal, | ||
// Set pageContext.locale | ||
locale, | ||
}) | ||
}) | ||
}) | ||
return { | ||
prerenderContext: { | ||
pageContexts: storePageContexts, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
import { PageContext } from 'vike/types' | ||
|
||
import { META } from '#src/env' | ||
import i18n from '#plugins/i18n' | ||
|
||
function getTitle(pageContext: PageContext) { | ||
// The value exported by /pages/**/+title.js is available at pageContext.config.title | ||
const val = pageContext.config.title | ||
if (typeof val === 'string') return val | ||
if (typeof val === 'function') return String(val(pageContext)) | ||
return META.DEFAULT_TITLE | ||
return i18n.global.t('meta.defaultTitle') | ||
} | ||
function getDescription(pageContext: PageContext) { | ||
const val = pageContext.config.description | ||
if (typeof val === 'string') return val | ||
if (typeof val === 'function') return val(pageContext) | ||
return META.DEFAULT_DESCRIPTION | ||
return i18n.global.t('meta.defaultDescription') | ||
} | ||
|
||
export { getTitle, getDescription } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,6 @@ config.global.provide = { | |
routeParams: { | ||
code: 'my-code', | ||
}, | ||
locale: 'de', | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export type LocaleCode = 'de' | 'en' | ||
export const locales: LocaleCode[] = ['de', 'en'] | ||
export const localeDefault = 'de' | ||
export const fallbackLocale = 'en' | ||
export const localizedLocale = [ | ||
{ locale: 'de', title: 'Deutsch' }, | ||
{ locale: 'en', title: 'English' }, | ||
] | ||
|
||
export function extractLocale(url: string) { | ||
const urlPaths = url.split('/') | ||
let locale: LocaleCode | ||
let urlWithoutLocale | ||
// We remove the URL locale, for example `/de/about` => `/about` | ||
const firstPath = urlPaths[1] as LocaleCode | ||
if (locales.includes(firstPath)) { | ||
locale = firstPath | ||
urlWithoutLocale = '/' + urlPaths.slice(2).join('/') | ||
} else { | ||
locale = localeDefault | ||
urlWithoutLocale = url | ||
} | ||
|
||
return { locale, urlWithoutLocale } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export const title = 'DreamMall | Fehler' | ||
import i18n from '#plugins/i18n' | ||
|
||
export const title = () => i18n.global.t('error.title') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export const title = 'DreamMall | Authentifizierung' | ||
import i18n from '#plugins/i18n' | ||
|
||
export const title = () => i18n.global.t('auth.title') |
Oops, something went wrong.