website-carbon-badges

1.1.3 • Public • Published

Website Carbon Badges

This badge displays a live calculation of the carbon emissions per page view of any page it is embedded on. Powered by Website Carbon and made with minimum bytes by Wholegrain Digital

To raise issues, contribute or check out the code, visit the Gitlab repo.

Installation

Adding the badge to your site is as simple as inserting the following lines into your markup where you would like the badge to appear:

<div id="wcb" class="carbonbadge"></div>
<script src="https://unpkg.com/website-carbon-badges@1.1.2/b.min.js" defer></script>

Badge - Light Version

If you need the badge to work on a dark background, add the class, .wcb-d to the div container:

<div id="wcb" class="carbonbadge wcb-d"></div>
<script src="https://unpkg.com/website-carbon-badges@1.1.2/b.min.js" defer></script>

Badge - Dark Version

See a working example here.

More Info

To reduce data transfer and server load, the badge caches the result on the user's device and will only make a maximum of one API call per day for each page it is embedded on. If a user visits the same page more than once within a day, the result will have been cached.

Development Info

To get started:

  • npm install
  • npm start (build and watch for changes)
  • npm build (runs the gulp build process)

The build process compresses the src/b.css file and then inserts it into the javascript file before uglifying the js file. Both b.min.css and b.min.js are output into the root but only b.min.js is used by the badge.

Readme

Keywords

none

Package Sidebar

Install

npm i website-carbon-badges

Weekly Downloads

1,220

Version

1.1.3

License

GPL-3.0-or-later

Unpacked Size

34 kB

Total Files

10

Last publish

Collaborators

  • danwholegrain
  • jerometoole-wg