feat: ✨ add excerpt logic
This commit is contained in:
parent
afab1ab781
commit
6a6c5e5e14
10 changed files with 34 additions and 17 deletions
|
@ -40,6 +40,15 @@ export default async function (eleventyConfig) {
|
|||
: collection.getFilteredByGlob('./src/{posts,drafts}/*.md')
|
||||
);
|
||||
|
||||
eleventyConfig.setFrontMatterParsingOptions({
|
||||
excerpt: (file) => {
|
||||
if (!file.data.tags) return; // immediately return if not a blog post with tags
|
||||
const separator = '<!-- more -->';
|
||||
const excerpt = file.content.substring(0, file.content.indexOf(separator)).trim();
|
||||
file.excerpt = new markdownIt(MARKDOWNIT_OPTIONS).render(excerpt).trim();
|
||||
}
|
||||
});
|
||||
|
||||
eleventyConfig.addPlugin(eleventyPluginCiu);
|
||||
eleventyConfig.addPlugin(eleventyPluginEmbedEverything);
|
||||
eleventyConfig.addPlugin(eleventyPluginIcons, {
|
||||
|
@ -144,6 +153,7 @@ export default async function (eleventyConfig) {
|
|||
dateObj.toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' })
|
||||
);
|
||||
eleventyConfig.addFilter('toHTML', (str) => new markdownIt(MARKDOWNIT_OPTIONS).render(str ? str : ''));
|
||||
eleventyConfig.addFilter('toPlain', (str) => (str ? str.replace(/<[^>]+>/g, '') : null));
|
||||
}
|
||||
|
||||
export const config = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue