Skip to content

Commit

Permalink
Slugify Collectives and Pages (get rid of slug nesting for pages)
Browse files Browse the repository at this point in the history
Signed-off-by: Konstantin Myakshin <[email protected]>
  • Loading branch information
Koc committed Oct 5, 2024
1 parent 0ded93c commit c9fd222
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 10 deletions.
3 changes: 1 addition & 2 deletions lib/Migration/Version021200Date20240820000001.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/PageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions lib/Service/SlugGeneratorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,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();
}
}
2 changes: 1 addition & 1 deletion src/components/Collective.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const routes = [
component: CollectiveView,
props: (route) => route.params,
children: [
{ path: ':pageSlugPart+-:pageId(\\d+)' },
{ path: 'page-:pageId(\\d+)-:pageSlug' },
{ path: ':page*' },
],
},
Expand All @@ -56,7 +56,7 @@ const routes = [
component: CollectiveView,
props: (route) => route.params,
children: [
{ path: ':pageSlugPart+-:pageId(\\d+)' },
{ path: 'page-:pageId(\\d+)-:pageSlug' },
{ path: ':page*' },
],
},
Expand Down
3 changes: 1 addition & 2 deletions src/stores/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit c9fd222

Please sign in to comment.