+ 2
Please help me!! I'm having a problem about blog posts mechanism.
The problem is that when we are creating a post in blogger or medium.com or somewhere else similar to those will show a brief details of a post in a main page and once we click on 'read more' button or on post will navigate to new url where the all details are included in the post (the whole content of a post will display in new url). As a junior developer l, I want to know how it's happening?? Better if you can answer me using React.js + node.js + mongodb technologies. Any answers will be appreciated.
1 ответ
0
There are a few ways to do this. Exactly how will depend on both the shape/structure of the API response & how you prefer to use the response in the frontend.
The main page needs to have a list of all the posts. In Node, this is often an array of post objects. Along with a title and a unique identifier which is usually used to form the URL (aka slug), each post object can be given an excerpt in the API. This excerpt is a sample of the post, usually the first few words or first couple of sentences. There will also often be a date for each post.
You can use these details in the front end when you're iterating through the list of posts. E.f. for each post, you can render a <p>{post.excerpt}</>
If you don't have control of the API responses but you want to get an excerpt when it's not being returned, you'll have to get the full content then select an excerpt from that. It's much nicer if the API gives you the excerpt but sometimes you don't have that available.