Skip to content

Commit

Permalink
Merge pull request #804 from serlo/improve-course-page-alias
Browse files Browse the repository at this point in the history
chore(alias): small changes to course page alias code
  • Loading branch information
hugotiburtino authored Jun 19, 2024
2 parents 5843d1d + 205c400 commit 07df0b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion __tests__/__utils__/services/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function getUuid(instance: Instance, path: string) {
const regexes = [
new RegExp('^/(?<id>\\d+)$'),
new RegExp(
'(?<subject>[^/]+/)?(?<id>\\d+)(?<coursePageId>/[a-z0-9-]+)?/(?<title>[^/]*)$',
'(?<subject>[^/]+/)?(?<id>\\d+)(?<coursePageId>/[0-9a-f]+)?/(?<title>[^/]*)$',
),
]

Expand Down
8 changes: 6 additions & 2 deletions src/current-alias-redirects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,12 @@ async function getPathInfo(
} else {
const subject = uuid.alias.split('/').at(1) ?? 'serlo'
const slugTitle = toSlug(coursePage.title)

currentPath = `/${subject}/${uuid.id}/${coursePage.id.slice(0, 8)}/${slugTitle}`
const shortPageId = coursePage.id.split('-').at(0)
if (!shortPageId) {
currentPath = uuid.alias
} else {
currentPath = `/${subject}/${uuid.id}/${shortPageId}/${slugTitle}`
}
}
}
} catch (e) {
Expand Down

0 comments on commit 07df0b4

Please sign in to comment.