...
/Improving SEO with the Recommendations Component
Improving SEO with the Recommendations Component
Learn how we can build a component to display a list of recommended posts.
We'll cover the following...
Interlinking plays a crucial role in enhancing SEO and boosting rankings by connecting relevant pages through links. A quick way to automate the process of interlinking is to create a list of recommendations under each post, where users can explore other related topics. In this lesson, we’ll take a look at how we can build a responsive Recommendations
component in Astro and how we can reuse it in several places with other components combined.
Creating Recommendations
To get started, let’s see how we want to use the component first. According to the design, we want to display three recommended posts in a responsive manner.
Because the list of recommendations will be different on each page, we need this component to be configurable. Because it’s easier to remember slugs, let’s make the component capable of accepting a list of recommendations in the form of URLs.
<Recommendationsrecommended={['1st-recommended','2nd-recommended','3rd-recommended']}/>
To get the relevant posts based on their slugs, we can use Astro’s collection API along with a .filter
array method to only keep the posts that are passed to the recommended
prop. This functionality has already been implemented in the Recommendations
component in the code widget below. See how we get the correct posts in src/components/Recommendations.astro
.
--- title: "Latest Astro Post Title" description: "Description for the post" publishDate: "2023.06.19" heroImage: "https://images.unsplash.com/photo-1581500274180-6331eea8b184?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8OHx8YXN0cm98ZW58MHx8MHx8fDA%3D&auto=format&fit=crop&w=1200&q=60" excerpt: "Excerpt from a recommended article. Content is trimmed to a maximum of 150 characters for brevity. If the content exceeds the character limit, three dots will be displayed using JavaScript's `substring` method." faq: - id: 1 question: "Post with FAQ" answer: "FAQ answer" open: true - id: 2 question: "FAQ 2nd Question" answer: "Answer to 2nd FAQ" --- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Vitae ultricies leo integer malesuada nunc vel risus commodo viverra. Adipiscing enim eu turpis egestas pretium. Euismod elementum nisi quis eleifend quam adipiscing. In hac habitasse platea dictumst vestibulum. Sagittis purus sit amet volutpat. Netus et malesuada fames ac turpis egestas. Eget magna fermentum iaculis eu non diam phasellus vestibulum lorem. Varius sit amet mattis vulputate enim. Habitasse platea dictumst quisque sagittis. Integer quis auctor elit sed vulputate mi. Dictumst quisque sagittis purus sit amet. Morbi tristique senectus et netus. Id semper risus in hendrerit gravida rutrum quisque non tellus. Habitasse platea dictumst quisque sagittis purus sit amet. Tellus molestie nunc non blandit massa. Cursus vitae congue mauris rhoncus. Accumsan tortor posuere ac ut. Fringilla urna porttitor rhoncus dolor. Elit ullamcorper dignissim cras tincidunt lobortis. In cursus turpis massa tincidunt dui ut ornare lectus. Integer feugiat scelerisque varius morbi enim nunc. Bibendum neque egestas congue quisque egestas diam. Cras ornare arcu dui vivamus arcu felis bibendum. Dignissim suspendi --- ## Title Morbi tristique senectus et netus. Id semper risus in hendrerit gravida rutrum quisque non tellus. Habitasse platea dictumst quisque sagittis purus sit amet. Tellus molestie nunc non blandit massa. Cursus vitae congue mauris rhoncus. Accumsan tortor posuere ac ut. Fringilla urna porttitor rhoncus dolor. Elit ullamcorper dignissim cras tincidunt lobortis. In cursus turpis massa tincidunt dui ut ornare lectus. Integer feugiat scelerisque varius morbi enim nunc. Bibendum neque egestas congue quisque egestas diam. Cras ornare arcu dui vivamus arcu felis bibendum. Dignissim suspendi - List - With - Items - With Adjusted Styles
The component also accepts two other props: noMargin
(line 7) and inline
(line 8). These props control how the cards are displayed. These are used as conditional classes using the class:list
(line 17) directive. However, ...