Add support for async excerpt functions? #156

Open
opened 2023-03-31 06:34:42 +00:00 by pdehaan · 2 comments
pdehaan commented 2023-03-31 06:34:42 +00:00 (Migrated from github.com)

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.

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 commented 2023-04-22 09:36:01 +00:00 (Migrated from github.com)

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 })
}))
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? ```js 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 commented 2023-04-23 16:46:52 +00:00 (Migrated from github.com)

@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.

@webketje Yeah, sorry. We are using [Eleventy](https://www.11ty.dev/) 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 in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
rtlabs-llm-agents/gms-gray-matter#156
No description provided.