DEV Social Badge - Going Open-source!
Tags: showdev, webdev, javascript, meta
Published: 2020-02-25 14:26:23

I just open-sourced the codebase for the [DEV Social Badge](https://benprice.dev/posts/intro-dev-social-badge/) that I've been working on. Check it out on [GitHub](https://github.com/BenjaminPrice/dev-social-badge)!

DEV Social Badge is an _unofficial_ social badge that queries the [DEV.to](https://dev.to/) API to see if your blog post has been posted on DEV.

This first release, [v0.1.0](https://github.com/BenjaminPrice/dev-social-badge/releases/tag/v0.1.0), should still be considered unstable and used at your own risk.

***

> **An important requirement for this to work:** You must be using Canonical URLs on DEV.
>
> <cite>_This allows the code to determine which of your DEV posts matches the post hosting the badge._</cite>

***

## Using the script

Using the script is fairly straight forward. You have to add a couple of tags to your `<head>` and a couple in the `<body>`, where you want the badge to appear.

### Adding the script tag to the <head>

Add the following script tag somewhere in your `<head>` to load the minified script.

    <!-- Place script tag before the end of the head tag -->
    <script src="https://unpkg.com/dev-social-badge@0.1.0/dist/dev-social-badge.min.js"> </script>

### Adding the devbadge and script tags to the <body>

The `<devbadge />` will be replaced by the script with the social badge, if the script is able to find a matching post on DEV. If it doesn't return any matching posts, nothing gets added to your page.

***

_If you're using a template for your blog posts, I suggest adding this to the template file for your blog posts - not your main site layout._ This will help to reduce unnecessary API calls to [DEV.to](https://dev.to/).

***

    <!-- Place devbadge tag wherever you'd like the badge to appear -->
    <devbadge />
    <!-- Place script tag before the end of the body tag -->
    <script>window.onload = function(){typeof findOnDev !== "undefined" && findOnDev()}</script>

## API Limits

Currently, there are no published limits on API calls. But, that doesn't mean that there isn't one. It's possible that this could stop functioning.

Additionally, the DEV API [documentation](https://docs.dev.to/api/) states that responses are cached for 24 hours. Don't expect your badge to show the positive reaction count in real-time.

## You can help

You don't need to write any code to help the project. Just giving the repository a ★Star on [GitHub](https://github.com/BenjaminPrice/dev-social-badge) will help towards getting the project hosted on other CDNs, such as [cdnjs](https://cdnjs.com/).

I will be adding [Issues](https://github.com/BenjaminPrice/dev-social-badge/issues) to the repository for areas where I'd like some help, as well as to get my improvement ideas out of my head, over the next day or two. If you'd like to contribute to the code, please check out the [Contribution Guidelines](https://github.com/BenjaminPrice/dev-social-badge/blob/master/CONTRIBUTING.md) (so far, they're quite sparse).

## Let me hear from you

Please share your thoughts in the comments thread on DEV. I'd love to get your feedback and opinions.

---

This post [originally appeared](https://benprice.dev/posts/dev-social-badge-going-open-source/) on [benprice.dev](https://benprice.dev).