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
#How to add dynamic data to static blog?
75 messages · Page 1 of 1 (latest)
🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord
🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize
✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)
yeah @misty gazelle to keep the states of comments, liked/disliked, reactions etc, you definitely need database
ok
but as those blogs are mostly static, you only have dynamic part for comments, reactions ...
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?
yea
do i do the same with the mdx -> json data?
oh, I see you mean the markdown?
yea
yeah, there is a bunch of library supporting that feature
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?
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
yea not at all
do they provide a way to update the content?
im not sure if this is usable for very large amounts of data but it hsould be fine
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
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
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
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
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
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
yea
then you should probably check the possibility - it's better than redoing everything what you have done
ok
i was wondering before i started how news sites like new yorker build their sites
why don't you use cms?
Strapi is the next-gen headless CMS, open-source, javascript, enabling content-rich experiences to be created, managed and exposed to any digital device.
check out these links
they are Content Managemnet System
ohh cool so that's how people create posts
exactly
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
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
ok that's good
just have unique slug for each blog
ok
and then you need that in your tables for reactions, user replies
ok i'll start writing and see if everything works