Skip to content

Commit

Permalink
feat(theme): dynamic render custom pages
Browse files Browse the repository at this point in the history
  • Loading branch information
wibus-wee committed Aug 14, 2022
1 parent 9724457 commit 3ec5bc8
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/modules/theme/theme.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { LinksService } from '../links/links.service';
import { PageService } from '../page/page.service';
import { PostService } from '../post/post.service';
import { UserService } from '../user/user.service';
import { CategoryThemeInterface, IndexThemeInterface, PageThemeInterface, PostThemeInterface, TagThemeInterface, ThemeBasicInterface } from './theme.interface';
import { CategoryThemeInterface, CustomThemeInterface, IndexThemeInterface, PageThemeInterface, PostThemeInterface, TagThemeInterface, ThemeBasicInterface } from './theme.interface';
import { CategoryType } from '../category/category.model';
import { ConfigsService } from '../configs/configs.service';
import { CannotFindException } from '~/common/exceptions/cant-find.exception';
Expand Down Expand Up @@ -289,5 +289,24 @@ export class ThemeController {
);
}

@Get(":path/:props*")
async dynamic(
@Res() res,
@Param("path") path: string,
@Param("props") props: string,
) {
// 检查是否存在该路径对应的文件
const filePath = join(THEME_DIR, (await this.themeService.currentTheme())!.name, `page-${path}.ejs`);
if (!fs.existsSync(filePath)) {
return res.view(
`${(await this.themeService.currentTheme())!.name}/404.ejs` as string,
{
...(await this.basicProps()),
path: `/${path}`,
props: props.split("/"),
} as CustomThemeInterface,
)
}
}

}

0 comments on commit 3ec5bc8

Please sign in to comment.