📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
support nested subcategories
Blue Mouse17d1d7401b3e
diff --git a/backend/apps/cloud/src/blog/blog.controller.ts b/backend/apps/cloud/src/blog/blog.controller.tsindex ed618f889..ea656cb17 100644--- a/backend/apps/cloud/src/blog/blog.controller.ts+++ b/backend/apps/cloud/src/blog/blog.controller.ts@@ -45,4 +45,23 @@ export class BlogController {return post}++ @Get('/:category/:subcategory/:slug')+ @ApiResponse({ status: 200 })+ async getNestedCategorySlug(+ @Param('category') category: string,+ @Param('subcategory') subcategory: string,+ @Param('slug') slug: string,+ ): Promise<any> {+ const post = await this.blogService.getArticleBySlug(+ slug,+ `${category}/${subcategory}`,+ )++ if (!post) {+ throw new NotFoundException()+ }++ return post+ }}diff --git a/backend/apps/cloud/src/blog/blog.service.ts b/backend/apps/cloud/src/blog/blog.service.tsindex 6a266568f..0e42fe961 100644--- a/backend/apps/cloud/src/blog/blog.service.ts+++ b/backend/apps/cloud/src/blog/blog.service.ts@@ -64,14 +64,20 @@ const resolveBlogPostsPath = (...segments: string[]) => {return resolved}+const isValidCategoryPath = (category: string): boolean => {+ return category.split('/').every(isSafePathSegment)+}++const categorySegments = (category: string): string[] => category.split('/')+const getFileNames = async (category?: string): Promise<string[]> => {try {- if (category && !isSafePathSegment(category)) {+ if (category && !isValidCategoryPath(category)) {return []}const pathToRead = category- ? resolveBlogPostsPath(category)+ ? resolveBlogPostsPath(...categorySegments(category)): resolveBlogPostsPath()const dirents = await fs.readdir(pathToRead, { withFileTypes: true })@@ -91,7 +97,7 @@ const getPost = async (if (!isSafePathSegment(slug)) {return null}- if (category && !isSafePathSegment(category)) {+ if (category && !isValidCategoryPath(category)) {return null}@@ -103,7 +109,7 @@ const getPost = async (}const filepath = category- ? resolveBlogPostsPath(category, filename)+ ? resolveBlogPostsPath(...categorySegments(category), filename): resolveBlogPostsPath(filename)let file: Buffer@@ -152,6 +158,7 @@ const getArticlesFromDir = async (category?: string): Promise<any[]> => {slug: category ? `${category}/${baseSlug}` : baseSlug,title: attributes.title,hidden: attributes.hidden,+ standalone: attributes.standalone,intro: attributes.intro,date: attributes.date,_date: getDateFromFilename(d.name),@@ -233,7 +240,7 @@ export class BlogService {}}- if (category && !isSafePathSegment(category)) {+ if (category && !isValidCategoryPath(category)) {return []}@@ -241,7 +248,7 @@ export class BlogService {try {const dirPath = category- ? resolveBlogPostsPath(category)+ ? resolveBlogPostsPath(...categorySegments(category)): BLOG_POSTS_BASEdirents = await fs.readdir(dirPath, { withFileTypes: true })} catch (reason) {@@ -264,7 +271,10 @@ export class BlogService {try {const filePath = category- ? resolveBlogPostsPath(category, actualFilename)+ ? resolveBlogPostsPath(+ ...categorySegments(category),+ actualFilename,+ ): resolveBlogPostsPath(actualFilename)const file = await fs.readFile(filePath)@@ -273,7 +283,6 @@ export class BlogService {)if (attributes.standalone === true) {- // Include category path for standalone articles in subfoldersif (category) {return [category, slug]}@@ -306,8 +315,12 @@ export class BlogService {continue}+ const fullCategory = category+ ? `${category}/${directoryName}`+ : directoryName+const _files = await this.getSitemapFileNames(- directoryName,+ fullCategory,infiniteRecursive,)filesInDirectories = [...filesInDirectories, ..._files]diff --git a/backend/blog-posts b/backend/blog-postsindex fefef8090..d90f881b5 160000--- a/backend/blog-posts+++ b/backend/blog-posts@@ -1 +1 @@-Subproject commit fefef8090a1d6a046f221a1bf3b528a0923734b6+Subproject commit d90f881b57f53f907fcff4e6d12fd401bbc68c7fdiff --git a/web/app/routes/blog._index.tsx b/web/app/routes/blog._index.tsxindex 5cc39797c..203d708c3 100644--- a/web/app/routes/blog._index.tsx+++ b/web/app/routes/blog._index.tsx@@ -81,7 +81,7 @@ export default function Posts() {/></svg><div className='relative'>- <Link to={post.slug}>+ <Link to={post.standalone ? `/${post.slug}` : post.slug}><h3 className='pt-8 text-base font-semibold text-slate-900 lg:pt-0 dark:text-slate-200'>{post.title}</h3>@@ -101,7 +101,7 @@ export default function Posts() {<Text as='p' size='sm'><LinkclassName='flex max-w-max items-center text-sm font-medium underline decoration-dashed hover:decoration-solid'- to={post.slug}+ to={post.standalone ? `/${post.slug}` : post.slug}><span className='relative'>Read more</span><CaretRightIcon className='relative mt-px ml-0.5 size-3 overflow-visible' />