How to add a Like button for your blog posts on your Astro website

Introduction

This is a step by step guide to integrate Feelback with your Astro website. With this guide you will add a Like button to your blog posts.

Astro like button example

In this tutorial you will:

Step 1: Setup the Feelback project

If you don't have already a Feelback account, please signup and create one. It's free and doesn't require a credit card to use.


Access the Feelback panel, and create a project if you don't have any. Feelback panel projects

You can use your website name.

Feelback panel create project

After that, create a ContentSet which will contain your content and feedbacks you will receive.

Feelback panel create content-set

Pick the Pulse type to enable this content-set to receive Like signals.

Feelback panel content-set type

Some further configuration:

Feelback panel content-set flags

You will end up with a ContentSet like the following one:

Feelback panel content-set info

Step 2: Install the Feelback plugin

In your Astro project directory, just install the astro-feelback package:

npm install astro-feelback

Step 3: Add the FeelbackPulse component to the layout page

Now you are ready to add the Like button to your blog post page. Let’s suppose you want to add a Heart button near your blog post title.


For this guide, we will create a new component named BlogPostTitle which will display the title and the like button.

BlogPostTitle.astro

---
import FeelbackPulse from "astro-feelback/components/FeelbackPulse.astro";
import "astro-feelback/styles/feelback.css";

// here you will copy the content-set id from the panel
const CONTENT_SET_LIKES = "your-content-set-id-from-panel";

interface Props {
    date: Date
    title: string
}
---

<div class="title-header">
    <span class="post-date">{Astro.props.date.toDateString()}</span>
    <h1>{Astro.props.title}</h1>

    <FeelbackPulse contentSetId={CONTENT_SET_LIKES}
        preset="heart" // <-- shows the Heart icon
        showCount // <-- shows the likes count
    />
</div>

You can use the BlogPostTitle component inside your BlogPost layout page. The result should be something like this:

Like button example

Additional documentation with all properties and customization you can use are available inside the dedicated Astro integration guide.

Step 4: (Optional) Customize the component style

You can override the predefined style with additional CSS.


For example, you can add some selector to change the button icons size and set some custom value.

---
import "astro-feelback/styles/feelback.css";
---
<style is:global>
   .feelback-icon svg {
     width: 24px;
     height: 24px;
   }
</style>

Full documentation with advanced customization is available inside the Astro integration guide.

Contributing

The astro-feelback package is open source and available on github. Any contribution is much appreciated. Issues, bug reports and feature requests are welcome. Do not hesitate to reach us or ask for help.

Additional resources

Other guides for Astro

Documentation