Moved url updating to a helper function

This commit is contained in:
Jori Lallo
2017-09-12 20:14:14 -07:00
parent 5c43e12218
commit 76afaacc6e
2 changed files with 14 additions and 3 deletions

View File

@@ -38,3 +38,13 @@ export function searchUrl(query?: string): string {
export function notFoundUrl(): string {
return '/404';
}
/**
* Replace full url's document part with the new one in case
* the document slug has been updated
*/
export function updateDocumentUrl(oldUrl: string, newUrl: string): string {
// Update url to match the current one
const urlParts = oldUrl.split('/');
return [newUrl, urlParts.slice(3)].join('/');
}