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

feat: pre / post parsing hooks #2925

Open
wants to merge 6 commits into
base: v3
Choose a base branch
from
Open

Conversation

harlan-zw
Copy link
Contributor

@harlan-zw harlan-zw commented Dec 20, 2024

πŸ”— Linked issue

#2921

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

The runtime hooks from Content v2 were useful for modules to provide an integration with markdown files. For example, allowing users to provide custom frontmater keys or inferring data from the markdown body.

In Content v3 these runtime hooks are moved to the build time which is a great performance win, however, we no longer have access to the parsing hooks.

This PR introduces the collection:parsedFile hook to allow modules to start integrating with v3.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@harlan-zw harlan-zw requested a review from farnabaz December 20, 2024 12:29
@farnabaz
Copy link
Member

Thanks for the PR

Can we also call a hook before parsing the file with raw markdown? There is also a feature request for beforeParse hook in v3 #2921

Also let's rename the hooks and add content: prefix to emphasize the hook's owner and scope.

  • content:file:beforeParse (I think using :file: instead of :collection: makes more sense)
  • content:file:afterParse

It is worth mentioning that the body field in v3 is minified and the tree structure is different from v2 so we might need to explain the new minified structure. (we can add this in a separate PR)

Copy link

cloudflare-workers-and-pages bot commented Dec 20, 2024

Deploying nuxt-content with Β Cloudflare Pages Β Cloudflare Pages

Latest commit: d553630
Status:🚫  Build failed.

View logs

@harlan-zw harlan-zw changed the title feat: collection:parsedFile hook feat: hooks content:file:beforeParse, content:file:afterParse Dec 20, 2024
Copy link

pkg-pr-new bot commented Dec 20, 2024

npm i https://pkg.pr.new/@nuxt/content@2925

commit: d553630

@harlan-zw harlan-zw changed the title feat: hooks content:file:beforeParse, content:file:afterParse feat: pre / post parsing hooks Dec 20, 2024
@harlan-zw
Copy link
Contributor Author

harlan-zw commented Dec 20, 2024

Thanks for the quick review! I've added beforeParse and renamed the after parse hook.

It would be nice to have the content from afterParse typed but I don't think there's a way to do that unless we introduce collection based hooks but the complexity probably isn't worth pursuing at this stage.

Let me know if you'd like anything else updated.

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

Successfully merging this pull request may close these issues.

2 participants