Hi all,
I'm new to nuxt content and I am trying to build a personal blog with stars / comments / reads. Since nuxt content is generating static files, how can make it work with an express backend for storing stars / comments / reads?
I'm planning to use express talk to a mongo db for storing the stars / comments / reads.
One way I can think about is to use slug as the identifier of an article, and fetch db using this as article id. However if I end up changing the name of the slug, all the backend data will be messed up.
Is there a way the nuxt content apis can call my backend apis to decorate the response?
Any suggestions will be very helpful!
You can use something like this:
hooks: {
'content:file:beforeInsert': (document) => {
if (!document.postid) {
document.postid = randomID()
}
}
}
You can use something like this:
hooks: { 'content:file:beforeInsert': (document) => { if (!document.postid) { document.postid = randomID() } } }
I tried this approach but the randomId will be changing everytime I update the content of the .md file.
Couple of ideas:
Hi @davydnorris Thanks for your reply! I'm curious about md5 hash of the file. Will the md5 hash change if the file content change?
@kevinwchn you can set an ID directly in the front matter of you Markdown file so it won't change
I guess I am late at this but seeing the issue open I just though of sharing my point of view as well..
Just like Atinux said, you can include a unique ID in the front matter and use it. THATS THE WAY FOR YOU TO GO
I have done something similar with my personal bog as well. but instead of setting id in front matter I have used the slug as the unique id itself (because I am naming every file uniquely)
https://github.com/TheLearneer/santoshb.com.np/blob/master/pages/blog/_slug.vue#L75
https://github.com/TheLearneer/santoshb.com.np/blob/master/pages/blog/_slug.vue#L121-L127
Also I am using disqus commenting system but still everything you are telling accounts.