diff --git a/client/src/components/pages/SideBar.tsx b/client/src/components/pages/SideBar.tsx index 3bd15a97b6..8af9499a1a 100644 --- a/client/src/components/pages/SideBar.tsx +++ b/client/src/components/pages/SideBar.tsx @@ -1,4 +1,5 @@ import React from 'react'; +import path from 'path'; import { SideBarContainer, SideBarSiteName, @@ -51,7 +52,7 @@ function renderSideBarContent(posts: PostMetadata[] | DefinitionMetadata[]) { @@ -70,7 +71,7 @@ function renderSideBarContent(posts: PostMetadata[] | DefinitionMetadata[]) { {meta.word} @@ -81,3 +82,19 @@ function renderSideBarContent(posts: PostMetadata[] | DefinitionMetadata[]) { ); } } + +function buildHref(meta: PostMetadata | DefinitionMetadata): string { + if (isPostMetadata(meta)) { + if (!meta.path) { + throw new Error('Post metadata does not have a valid "path".'); + } + return path.join('/', meta.path); + } else { + if (!meta.dictionary || !meta.slug) { + throw new Error( + 'Definition metadata must include both "dictionary" and "slug".' + ); + } + return `/dictionaries/${meta.dictionary}/${meta.slug}`; + } +}