UNPKG

@newrelic/gatsby-theme-newrelic

Version:

[![Community Project header](https://github.com/newrelic/opensource-website/raw/master/src/images/categories/Community_Project.png)](https://opensource.newrelic.com/oss-category/#community-project)

26 lines (18 loc) 506 B
import { addLeadingSlash } from './location'; export const localizePath = ({ path, locale }) => { if (locale.isDefault) { return path; } const [, base] = path.split('/'); return base === locale.locale ? path : `/${locale.locale}${addLeadingSlash(path)}`; }; export const localizeExternalLink = ({ link, locale }) => { if (locale.isDefault) { return link; } const url = new URL(link); url.pathname = localizePath({ path: url.pathname, locale }); return url.href; };