From 8cff15d554b4998d25cccf41da498467c6490ec2 Mon Sep 17 00:00:00 2001 From: Kostiantyn Miakshyn Date: Sun, 6 Oct 2024 00:52:30 +0200 Subject: [PATCH] Slugify Collectives and Pages (get rid of slug nesting for pages) Signed-off-by: Konstantin Myakshin --- lib/Migration/Version021200Date20240820000001.php | 3 +-- lib/Service/PageService.php | 2 +- lib/Service/SlugGeneratorService.php | 4 ++-- src/components/Collective.vue | 2 +- src/router.js | 4 ++-- src/stores/pages.js | 3 +-- 6 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/Migration/Version021200Date20240820000001.php b/lib/Migration/Version021200Date20240820000001.php index fb7d8a9ef..e1caac2c5 100644 --- a/lib/Migration/Version021200Date20240820000001.php +++ b/lib/Migration/Version021200Date20240820000001.php @@ -60,7 +60,6 @@ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $queryCollectives->select(['id', 'circle_unique_id'])->from('collectives'); $resultCollectives = $queryCollectives->executeQuery(); - $queryPages = $this->connection->getQueryBuilder(); $queryPages->select(['id']) ->from('collectives_pages'); @@ -81,7 +80,7 @@ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array continue; } - $slug = $this->slugGeneratorService->generatePageSlug($pageInfo->getId(), $pageInfo->getTitle()); + $slug = $this->slugGeneratorService->generatePageSlug($pageInfo->getTitle()); $update ->setParameter('file_id', $pageInfo->getId(), IQueryBuilder::PARAM_INT) ->setParameter('slug', $slug, IQueryBuilder::PARAM_STR) diff --git a/lib/Service/PageService.php b/lib/Service/PageService.php index f2da979bb..de929ebfa 100644 --- a/lib/Service/PageService.php +++ b/lib/Service/PageService.php @@ -1102,6 +1102,6 @@ private function generateSlugForPage(string $title, ?File $file): ?string { return null; } - return $this->slugGeneratorService->generatePageSlug($file->getId(), $title); + return $this->slugGeneratorService->generatePageSlug($title); } } diff --git a/lib/Service/SlugGeneratorService.php b/lib/Service/SlugGeneratorService.php index 8edbca384..5d3a378f1 100644 --- a/lib/Service/SlugGeneratorService.php +++ b/lib/Service/SlugGeneratorService.php @@ -21,7 +21,7 @@ public function generateCollectiveSlug(int $collectiveId, string $name): string return $this->slugger->slug($name)->toString() . '-' . $collectiveId; } - public function generatePageSlug(int $fileId, string $title): string { - return $this->slugger->slug($title)->toString() . '-' . $fileId; + public function generatePageSlug(string $title): string { + return $this->slugger->slug($title)->toString(); } } diff --git a/src/components/Collective.vue b/src/components/Collective.vue index 9e4bcf2f8..027df08df 100644 --- a/src/components/Collective.vue +++ b/src/components/Collective.vue @@ -98,7 +98,7 @@ export default { const routerParams = this.$router.currentRoute.params // If the current page is not the one we are supposed to be on, redirect if (this.currentPage && !this.isIndexPage) { - const actualUrl = `${routerParams.collectiveSlugPart}-${routerParams.collectiveId}/${routerParams.pageSlugPart}-${routerParams.pageId}` + const actualUrl = `${routerParams.collectiveSlugPart}-${routerParams.collectiveId}/page-${routerParams.pageId}-${routerParams.pageSlug}` const expectedUrl = this.pageSlugPath(this.currentPage) if (actualUrl !== expectedUrl) { diff --git a/src/router.js b/src/router.js index 9d90f2283..b67403b97 100644 --- a/src/router.js +++ b/src/router.js @@ -41,7 +41,7 @@ const routes = [ component: CollectiveView, props: (route) => route.params, children: [ - { path: ':pageSlugPart+-:pageId(\\d+)' }, + { path: 'page-:pageId(\\d+)-:pageSlug' }, { path: ':page*' }, ], }, @@ -56,7 +56,7 @@ const routes = [ component: CollectiveView, props: (route) => route.params, children: [ - { path: ':pageSlugPart+-:pageId(\\d+)' }, + { path: 'page-:pageId(\\d+)-:pageSlug' }, { path: ':page*' }, ], }, diff --git a/src/stores/pages.js b/src/stores/pages.js index 2e9c0a401..5395f858b 100644 --- a/src/stores/pages.js +++ b/src/stores/pages.js @@ -120,8 +120,7 @@ export const usePagesStore = defineStore('pages', { pageSlugPath: (state) => (page) => { const collectivesStore = useCollectivesStore() const collective = collectivesStore.currentCollective.slug || collectivesStore.currentCollective.name - const slugsPath = pageParents(state)(page.id).map(p => p.slug) - return [collective, ...slugsPath].filter(Boolean).map(encodeURIComponent).join('/') + return [collective, `page-${page.id}-${page.slug}`].join('/') }, pagePathTitle: () => (page) => {