Content change content programatically
I'm trying to add style tag to the h1 of my posts:
I tried the
{style="...
that didn't work
I also tried in nuxt config:
and I also tried in the nuxt config:
I just can't seem to get anything.
I am not getting logs in dev or during nuxi generate.
What am i doing wrong?5 Replies
Hi @nandi95. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
It looks like you're trying to modify your Markdown content in Nuxt Content, specifically to add styling to h1 elements. Let me help you troubleshoot this issue.
Transformers and Hooks Setup
Your approach using transformers and hooks is correct, but there might be some issues with implementation. Let's address them:
1. Using Content Hooks
The
content:file:afterParse
hook should work, but you need to ensure it's properly set up. Here's how you should implement it:
If you're not seeing logs, it could be because:
- The hook might not be triggered if you're using Nuxt Content v3 with a different hook naming convention
- Console logs might be suppressed in the build process
2. Using Custom Transformers
For your custom transformer approach, you need to create the actual transformer file:
Then reference it in your config:
Debugging Tips
1. Make sure you're restarting your Nuxt server after making changes to the configuration
2. For local debugging with Nuxt Content, you can enable the preview mode:
This will help you see if your transformers are being applied correctly Local Debug.
3. Check if your transformer file is being properly loaded by adding more explicit console logs at the top level of the file.
Alternative Approach
If you're specifically looking to style h1 elements in your Markdown content, you might want to consider using Nuxt UI Pro's typography system which provides direct control over styling:
This approach allows you to customize the styling of typography elements directly Typography.
Let me know if you need more specific help with your implementation!
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@478977928730902528> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Also tried the hook in a nitro plugin
these only run when it's transformed which only happens the first time it's passed so you may need to delete your .data / .nuxt folder to get it to trigger
that was it!
I was running nuxi cleanup
but the .data stayed
so that's the transformer only running, how do I get the hooks running?
so nuxt.callHook in content seems to be undefined...
nuxt is there, callHook function isn't