How to add dynamic data to static blog?
Unanswered
Red-legged Kittiwake posted this in #help-forum
Red-legged KittiwakeOP
i am creating a blog-like website where i invite other students to post their stories and advice using nextjs. i used velite (similar to contentlayer) to convert markdown to json server-side. since the posts are mostly static, pre-fetching all the posts works fine. but now i want to add more dynamic functions, such as voting, comments, user profiles, and more. how should i accomplish this? do i need to start using a database like mysql and prismadb? how would the mdx posts connect with the database in that case? currently, the data for each post is all text, as shown in the picture. how would i, for example, connect a post to a registered user account? any guidance would be greatly appreciated
74 Replies
yeah @Red-legged Kittiwake to keep the states of comments, liked/disliked, reactions etc, you definitely need database
Red-legged KittiwakeOP
ok
but as those blogs are mostly static, you only have dynamic part for comments, reactions ...
Red-legged KittiwakeOP
in the past, ive followed some build-along tutorials making reddit and twitter clones. i dont remember exactly how they converted user input into text, but i think it was using some external library to simplify everything
the post data is then added to an entry in db
user input into text means?Red-legged KittiwakeOP
yea
@Red-legged Kittiwake the post data is then added to an entry in db
Red-legged KittiwakeOP
do i do the same with the mdx -> json data?
oh, I see you mean the markdown?
Red-legged KittiwakeOP
yea
yeah, there is a bunch of library supporting that feature
Red-legged KittiwakeOP
i've been able to convert it to json and render it okay
im just not sure how to connect it to dynamic data like user profiles and voting and comments
hmmm
where do you store your blog data?
@James4u where do you store your blog data?
Red-legged KittiwakeOP
im using velite https://velite.js.org/guide/introduction
i have a bunch of mdx files in src/content/posts
and velite builds them into json
then i can just import and use it directly
I see, so it's not a cloud store then
Red-legged KittiwakeOP
yea not at all
do they provide a way to update the content?
Red-legged KittiwakeOP
im not sure if this is usable for very large amounts of data but it hsould be fine
@James4u do they provide a way to update the content?
Red-legged KittiwakeOP
i haven't tried
i'm not clear on the technical terms and how it works, but from waht i've seen it's just a preprocessor?
probably not I guess
Red-legged KittiwakeOP
yea, so i probably cant store vote data in the mdx
yeah, then you definitely need a database but how are you gonna identify each blog in your database?
maybe you have slug - oh you have it
Red-legged KittiwakeOP
idk how i would connect each blog to the database
bc right now, i direcly access the posts data and redner it
yeah, it's okay
Red-legged KittiwakeOP
do i need to add an intermediate step where i store the json into db?
but then i'd have to re-fetch it, right?
hmm
you can keep your blog with velite or something
and then just store reaction/comments any dynamic parts in your database
but again, please check if they provide a way to update the content
being not able to update his own content doesn't make sense
Red-legged KittiwakeOP
i can update it manually
i think it's meant for static pages
oh, is it your own blog site?
okay then, just make sure that you have something unique for each blog - in your case slug will be okay
make some tables in your database for comments and reactions
@James4u oh, is it your own blog site?
Red-legged KittiwakeOP
for now, i haven't provided ways for users to directly post things, though that might be needed in the future
but comments can't be markdown like your own blog
Red-legged KittiwakeOP
yea
@Red-legged Kittiwake for now, i haven't provided ways for users to directly post things, though that might be needed in the future
then you should probably check the possibility - it's better than redoing everything what you have done
Red-legged KittiwakeOP
ok
i was wondering before i started how news sites like new yorker build their sites
why don't you use cms?
Red-legged KittiwakeOP
what's that
i googled it but hard for me to understand
check out these links
they are Content Managemnet System
Red-legged KittiwakeOP
ohh cool so that's how people create posts
exactly
Red-legged KittiwakeOP
does it give users some way to make it too?
nope, you probably need to integrate it.
they provide a dashboard UI but it's for ADMIN
Red-legged KittiwakeOP
ok i did some research and thinking
i'm thinking of doing it like this:
i will use prismadb and mysql or smth for all the data, including users, posts, votes, comments, etc.
for now, i'll write the mdx files locally and have a script to convert those to json and populate the db
the comments will just be plain text for now (no need for markdown)
in the future, i might add markdown input for end-users
yeah, it makes sense
Red-legged KittiwakeOP
ok that's good
just have unique slug for each blog
Red-legged KittiwakeOP
ok
and then you need that in your tables for reactions, user replies
Red-legged KittiwakeOP
ok i'll start writing and see if everything works
@Red-legged Kittiwake ok i'll start writing and see if everything works
American Golden-Plover
You may also consider https://www.nodehive.com - it comes with a lot of features like scheduling, media management, rag/ai ready, much more