Prevent extra / appearing after doc url

This commit is contained in:
Tom Moor
2017-09-27 22:36:10 -07:00
parent fe559baeff
commit 5ada7fd090
2 changed files with 20 additions and 13 deletions

View File

@ -34,10 +34,14 @@ export function documentMoveUrl(doc: Document): string {
* Replace full url's document part with the new one in case
* the document slug has been updated
*/
export function documentUpdateUrl(oldUrl: string, newUrl: string): string {
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('/');
const urlParts = oldUrl.trim().split('/');
const actions = urlParts.slice(3);
if (actions[0]) {
return [newUrl, actions].join('/');
}
return newUrl;
}
export function newDocumentUrl(collection: Collection): string {