fix: Use friendly urls for collections (#2162)
Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
// @flow
|
||||
import queryString from "query-string";
|
||||
import Collection from "models/Collection";
|
||||
import Document from "models/Document";
|
||||
|
||||
export function homeUrl(): string {
|
||||
@ -11,13 +12,23 @@ export function starredUrl(): string {
|
||||
}
|
||||
|
||||
export function newCollectionUrl(): string {
|
||||
return "/collections/new";
|
||||
return "/collection/new";
|
||||
}
|
||||
|
||||
export function collectionUrl(collectionId: string, section: ?string): string {
|
||||
const path = `/collections/${collectionId}`;
|
||||
if (section) return `${path}/${section}`;
|
||||
return path;
|
||||
export function collectionUrl(url: string, section: ?string): string {
|
||||
if (section) return `${url}/${section}`;
|
||||
return url;
|
||||
}
|
||||
|
||||
export function updateCollectionUrl(
|
||||
oldUrl: string,
|
||||
collection: Collection
|
||||
): string {
|
||||
// Update url to match the current one
|
||||
return oldUrl.replace(
|
||||
new RegExp("/collection/[0-9a-zA-Z-_~]*"),
|
||||
collection.url
|
||||
);
|
||||
}
|
||||
|
||||
export function documentUrl(doc: Document): string {
|
||||
@ -42,14 +53,9 @@ export function documentHistoryUrl(doc: Document, revisionId?: string): string {
|
||||
* 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 {
|
||||
export function updateDocumentUrl(oldUrl: string, document: Document): string {
|
||||
// Update url to match the current one
|
||||
const urlParts = oldUrl.trim().split("/");
|
||||
const actions = urlParts.slice(3);
|
||||
if (actions[0]) {
|
||||
return [newUrl, actions].join("/");
|
||||
}
|
||||
return newUrl;
|
||||
return oldUrl.replace(new RegExp("/doc/[0-9a-zA-Z-_~]*"), document.url);
|
||||
}
|
||||
|
||||
export function newDocumentUrl(
|
||||
@ -60,7 +66,7 @@ export function newDocumentUrl(
|
||||
template?: boolean,
|
||||
}
|
||||
): string {
|
||||
return `/collections/${collectionId}/new?${queryString.stringify(params)}`;
|
||||
return `/collection/${collectionId}/new?${queryString.stringify(params)}`;
|
||||
}
|
||||
|
||||
export function searchUrl(
|
||||
|
Reference in New Issue
Block a user