Add initial project files
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import { hasLocale } from 'next-intl';
|
||||
import { routing } from './routing';
|
||||
|
||||
/**
|
||||
* Internal hrefs in page content are locale-prefixed (`/{locale}/{path}`);
|
||||
* when the site serves unprefixed URLs, the prefix is stripped at render
|
||||
* time so navigation does not bounce through the proxy redirect.
|
||||
*/
|
||||
export function toPublicHref(href: string): string {
|
||||
if (routing.localePrefix !== 'never') {
|
||||
return href;
|
||||
}
|
||||
|
||||
const [, first = '', ...rest] = href.split('/');
|
||||
|
||||
if (!hasLocale(routing.locales, first)) {
|
||||
return href;
|
||||
}
|
||||
|
||||
return `/${rest.join('/')}`;
|
||||
}
|
||||
Reference in New Issue
Block a user