Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for async excerpt functions? #156

Open
pdehaan opened this issue Mar 31, 2023 · 2 comments
Open

Add support for async excerpt functions? #156

pdehaan opened this issue Mar 31, 2023 · 2 comments

Comments

@pdehaan
Copy link

pdehaan commented Mar 31, 2023

I was working on a project that needed to call an async method when creating excerpts but I couldn't get the excerpt function to work w/ async functions. Not sure if I'm doing something wrong or if promises just aren't supported and this is a feature request.

@webketje
Copy link

webketje commented Apr 22, 2023

Why should gray-matter be responsible for this? This is indeed not supported and would be a breaking change as it will forcethe main matter parse function to become async.
Can't you do sth like below?

async function fetchExcerptForFile(file) { /* do async stuff & return promise with excerpt */ }

// assuming files is an arr of { content: '...', filepath: '...' } or such
const parsedFiles = await Promise.all(files.map(async file => {
  const excerpt = await fetchExcerptForFile(file)
  return matter(file.content, { excerpt: () => excerpt })
}))

@pdehaan
Copy link
Author

pdehaan commented Apr 23, 2023

@webketje Yeah, sorry. We are using Eleventy which uses gray-matter for front-matter parsing and I think we were trying to generate excerpts and wanting to re-parse them using LiquidJS or something and an async parser for excerpt() would have helped out. But we found an alternate approach using shortcodes and filters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants