diff options
Diffstat (limited to 'src/config.ts')
-rw-r--r-- | src/config.ts | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/config.ts b/src/config.ts index 544d15c..ab0ec12 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,3 +1,4 @@ +import _ from 'lodash'; import { BenzinConfig } from './lib/types'; import nginxAdapter from './lib/nginxAdapter'; @@ -11,6 +12,24 @@ const config: BenzinConfig = { emojiRoot: '/public/emoji', css: '/public/style.css?h=benzin-next-cdn', }, + hooks: { + async preRender(path, data, adapter, cdn) { + if (path.length === 1 && path[0] === 'index') { + // Inject blog preview into home page + const blog = await adapter.getMarkdownSource(cdn, ['blog', 'index']); + const previewContent = blog + .split('\n') + .filter(line => line.startsWith('-')) + .slice(0, 4) + .join('\n'); + + const split = data.split('# Recent blog posts'); + return [split[0], '# Recent blog posts\n', previewContent, split[1]].join(''); + } + + return data; + } + }, }; export default config; |