#How to add dynamic data to static blog?

75 messages · Page 1 of 1 (latest)

misty gazelle
#

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

shy carbonBOT
#

🔎 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)

neon pike
#

yeah @misty gazelle to keep the states of comments, liked/disliked, reactions etc, you definitely need database

misty gazelle
#

ok

neon pike
#

but as those blogs are mostly static, you only have dynamic part for comments, reactions ...

misty gazelle
#

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

neon pike
#

user input into text means?

misty gazelle
#

yea

misty gazelle
neon pike
#

oh, I see you mean the markdown?

misty gazelle
#

yea

neon pike
#

yeah, there is a bunch of library supporting that feature

misty gazelle
#

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

neon pike
#

where do you store your blog data?

misty gazelle
#

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

neon pike
#

I see, so it's not a cloud store then

misty gazelle
#

yea not at all

neon pike
#

do they provide a way to update the content?

misty gazelle
#

im not sure if this is usable for very large amounts of data but it hsould be fine

misty gazelle
#

i'm not clear on the technical terms and how it works, but from waht i've seen it's just a preprocessor?

neon pike
#

probably not I guess

misty gazelle
#

yea, so i probably cant store vote data in the mdx

neon pike
#

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

misty gazelle
#

idk how i would connect each blog to the database

#

bc right now, i direcly access the posts data and redner it

neon pike
#

yeah, it's okay

misty gazelle
#

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

neon pike
#

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

misty gazelle
#

i can update it manually

#

i think it's meant for static pages

neon pike
#

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

misty gazelle
neon pike
#

but comments can't be markdown like your own blog

misty gazelle
#

yea

neon pike
misty gazelle
#

ok

#

i was wondering before i started how news sites like new yorker build their sites

neon pike
#

why don't you use cms?

misty gazelle
#

what's that

#

i googled it but hard for me to understand

neon pike
#

check out these links

#

they are Content Managemnet System

misty gazelle
#

ohh cool so that's how people create posts

neon pike
#

exactly

misty gazelle
#

does it give users some way to make it too?

neon pike
#

nope, you probably need to integrate it.

#

they provide a dashboard UI but it's for ADMIN

misty gazelle
#

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

neon pike
#

yeah, it makes sense

misty gazelle
#

ok that's good

neon pike
#

just have unique slug for each blog

misty gazelle
#

ok

neon pike
#

and then you need that in your tables for reactions, user replies

misty gazelle
#

ok i'll start writing and see if everything works