I made DEV.to widget for websites/blogs
Saurabh Daware 🌻

Saurabh Daware 🌻 @saurabhdaware

About: - JavaScript <3 - I make silly libraries - Building Abell, A new static-site-generator.

Location:
Bengaluru, India 🇮🇳
Joined:
May 31, 2019

I made DEV.to widget for websites/blogs

Publish Date: Oct 20 '19
302 55

Hey Everyone! So I made an (Unofficial) DEV.to widget / profile-card which you can use in your websites and blogs (You just have to copy-paste 2 lines of code :D).

Here's how it looks like

Usage ( JUST 2 LINES OF CODE :D )

    <dev-widget data-username="saurabhdaware"></dev-widget>

    <!-- Place script tag before the end of the body tag -->
    <script src="https://unpkg.com/dev-widget@^1/dist/card.component.min.mjs" type="module"></script>

Enter fullscreen mode Exit fullscreen mode

And BOOM that's it! Just put your dev.to username in data-username attribute and you will get your profile card :D


If you want to install it as ES6 module (Mostly used in frameworks)

npm install --save dev-widget
Enter fullscreen mode Exit fullscreen mode

and import at the top of your file

import 'dev-widget'
Enter fullscreen mode Exit fullscreen mode

Then you can use

<dev-widget data-username="saurabhdaware"></dev-widget>
Enter fullscreen mode Exit fullscreen mode

There are some other attributes like data-width, data-limit You can checkout full documentation on my GitHub:

GitHub logo saurabhdaware / DEV-widget

Unofficial Widget/profile card for https://dev.to/

DEV widget

GitHub package.json version Contributions to DEV Widget are welcomed

GUI to Generate Card: https://dev-widget.netlify.app/create

Codepen: https://codepen.io/saurabhdaware/pen/NWWbOvv

Unofficial Widget / profile card for dev.to.

You can use it in your website/blog and show off your DEV.to articles 🌻

Screenshot of the DEV.to Widget


Installation and Usage

- Through script tag

    <dev-widget data-username="saurabhdaware"></dev-widget>

    <!-- Place script tag before the end of the body tag -->
    <script src="https://unpkg.com/dev-widget@^1/dist/card.component.min.mjs" type="module"></script>
Enter fullscreen mode Exit fullscreen mode

- As NPM module

This can be used in React, Vue and almost any other frontend framework

npm install --save dev-widget
Enter fullscreen mode Exit fullscreen mode

Inside your framework component

import 'dev-widget'
Enter fullscreen mode Exit fullscreen mode

Attributes Guide

attributes description default
data-username Your DEV.to Username
data-width Width of the card 300px
data-contentheight Height of the Aricles Container 300px
data-theme Theme of the card (dark, ocean, pink, cobalt2, default) default
data-name (optional) Name to display on card Will

Do ⭐ the repository 🦄

Also, for the hacktoberfest, if anyone wants to contribute to this project, I would love to help. You can checkout CONTRIBUTING.md for contribution guidelines.

GitHub: https://github.com/saurabhdaware/DEV-widget
NPM: https://npmjs.org/package/dev-widget
Codepen: https://codepen.io/saurabhdaware/pen/NWWbOvv

Comments 55 total

  • Fulton Browne
    Fulton BrowneOct 20, 2019

    I will use this on my blog, thanks

  • Rose
    RoseOct 20, 2019

    Love the idea, well done 😊

  • Maniflames
    ManiflamesOct 20, 2019

    Looks very neat!

  • Nick Taylor
    Nick TaylorOct 21, 2019

    Cool stuff Saurabh!

  • Paula Santamaría
    Paula SantamaríaOct 21, 2019

    Looks great, thank you!

  • Ben Halpern
    Ben HalpernOct 21, 2019

    This is so beautifully done. I’m super impressed.

  • Eddie
    EddieOct 21, 2019

    Amazing dude! A+ for Web Components implementation. Loved how you split the css into a separate module. Very impressive.

  • Ari Kalfus
    Ari KalfusOct 21, 2019

    This is great. Nit: Promote healthy web practices and add sub-resource integrity (SRI) via the integrity attribute on your example.

    developer.mozilla.org/en-US/docs/W...

    You can grab your hash from unpkg via the meta query parameter:

    https://unpkg.com/dev-widget@1.0.1/dist/card.component.mjs?meta

    <script src="https://unpkg.com/dev-widget@1.0.1/dist/card.component.mjs" type="module" integrity="sha384-755Jblzb17ugkA3KRCLz4XS8CPb3xEwBdBMk8ZBw51agtKmppILXMJrKvuTRkUhy"></script>
    
    • Saurabh Daware 🌻
      Saurabh Daware 🌻Oct 21, 2019

      Oh I didn't know about this thank you so much! I'll check it out

    • Lou (🚀 Open Up The Cloud ☁️)
      Lou (🚀 Open Up The Cloud ☁️)Oct 21, 2019

      Came here to say that too — bravo!

      • Saurabh Daware 🌻
        Saurabh Daware 🌻Oct 21, 2019

        Oh thank you! I've added integity hash to my codepen demo. Not really sure how I can get that hash before publishing so that I can set in readme (Apparently that hash changed from 1.0.1 to 1.0.2)

        • Ari Kalfus
          Ari KalfusOct 21, 2019

          Yup, the hash will change for each version of the script pushed to the CDN.

  • Prafulla Raichurkar
    Prafulla RaichurkarOct 21, 2019

    Cool 🤩

  • Deepak Sisodiya
    Deepak SisodiyaOct 21, 2019

    great

  • Sean G. Wright
    Sean G. WrightOct 21, 2019

    Nice work!

    I love that you've made something so many other devs (including myself) appreciate (based on the comments).

    The idea isn't that complex - someone else could have done it...

    But no one else did - you did!

    You took the time to figure everything out, make a quality, modern web component, and shared it with the world.

    Congrats and thanks!

    🙏

  • Suzanne Aitchison
    Suzanne AitchisonOct 21, 2019

    This is awesome! ♥️

  • rhymes
    rhymesOct 21, 2019

    So cool! Great job!

  • Anjan Kant
    Anjan KantOct 21, 2019

    Well done! I'll use it :)

  • Hugo Torzuoli
    Hugo TorzuoliOct 21, 2019

    So simple, very nice !

  • z2lai
    z2laiOct 23, 2019

    Wow, this adds so much value to a single-page portfolio by being able to show potential employers all the articles you've written with just TWO LINES OF CODE! The idea is pure genius, the execution looks perfect and I'm sure the code is just as elegant as the execution! I can also imagine this widget boosting the number of people using dev.to to write their articles.

    So simple yet so beautiful. Extremely inspiring stuff mate, congratulations!

    • Saurabh Daware 🌻
      Saurabh Daware 🌻Oct 23, 2019

      Thank you so much for such kind words 🌻🌻🦄

      • z2lai
        z2laiOct 23, 2019

        Wow, I get two sunflowers! I am honoured.

        • Saurabh Daware 🌻
          Saurabh Daware 🌻Oct 24, 2019

          haha your comment was the first thing I saw this morning and is surely gonna help me start my day with positivity, so you deserve a sunflower garden

          Here you go: 🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻Thank You!🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻🌻

  • KP
    KPNov 24, 2019

    @saurabhdaware this is phenomenal. I know you've open sourced the code but I'd like to build something very similar for my own site. Any pointers on how to get started would be great. Are you using the DEV APIs? Would I need to create those first for my own site before creating a public widget like this?

    • Saurabh Daware 🌻
      Saurabh Daware 🌻Nov 24, 2019

      Hi KP, yes I've used DEV API. There's a DEV API that returns the list of articles on providing the username. Even in my person website I am doing something similar in the articles section saurabhdaware.in

      Thank you for kind words 🌻🌻

      • KP
        KPNov 24, 2019

        Thanks @saurabhdaware . Looks like the code you've written is in .mjs file format....which is new to me....I'll give it a closer look and hope you dont mind me forking and using it in the future! Some quick questions for you...

        • What is the advantage of mjs files for modules (versus regular js)? I've never used this file format.
        • How do you host on unpkg, and how do you create a command like this?

          npm install --save dev-widget

        • Any gotchas I need to be aware of / careful of when creating my own widget?

        Thanks for the inspiration! 🌻

        • Saurabh Daware 🌻
          Saurabh Daware 🌻Nov 24, 2019
          • .mjs lets you use import and export in web without having a webpack build environment.

          • You have to publish it as a npm package and all npm packages are synced to unpkg

          • Gotchas:

            • The api does not return user's data directly, It comes under each article value with user's key
            • If user has written 0 articles, you dont get any value so no user data in this case.
            • If you are going to build on top of web components, you'll have to follow the webcomponent best practices (You'll find them on internet) for the widget to work in frameworks

          And yes you can go ahead and fork it

          Do share the link once you're done :D

          • KP
            KPNov 24, 2019

            @saurabhdaware thanks! These tips are going to be really helpful.

            I'll definitely let you know if I end up using it! First step, I'm trying to simply include your widget locally to see it in action...and then I can start modifying it :D

            I'm trying to include this dev widget in my nuxt.js project, in one of my pages. For context, each page in Nuxt is nothing but a vue component.

            Here is my code:

            <template>
              <div class="container">
            
                <div>
                    <dev-widget data-username="saurabhdaware"></dev-widget>
                </div>
            
              </div>
            </template>
            
            <script>
            
            export default {
              layout: "default",
            };
            </script>
            
            <script src="https://unpkg.com/dev-widget@1.0.3/dist/card.component.mjs" type="module"></script>
            
            

            Any idea what I am doing wrong here? I keep getting an error:
            Unknown custom element: < dev-widget >

            • Saurabh Daware 🌻
              Saurabh Daware 🌻Nov 24, 2019

              you'll have to follow the npm install and import 'dev-widget' instead of the link</p>

              • KP
                KPNov 24, 2019

                Thank you...there's gotta be a workaround though! It works fine in a raw HTML file...so it should work in vue as well!

                • Saurabh Daware 🌻
                  Saurabh Daware 🌻Nov 24, 2019

                  You can make it work in framework that way by putting that script file before end of body tag in your index.html.

                  These frameworks follow a particular standard and having compinents as module is by far the most comfortable way of adding anything. It also makes this process standard since it gets similar to how you would add a usual vue component.

                  What you write in your vue component is not really staright up appeneded to the final bundle rather they are in some way compiled (in v v v general terms) and they are bundled with vue's code along with it. So it is not really possible to standardize that script include thing (unless you write different widget for different frameworks)

                  • KP
                    KPNov 24, 2019

                    That makes total sense @saurabhdaware . Thanks for the explanation! 🌻

                    I'll do some more research to see if I can get this working in vue / nuxt component pages!

                    • KP
                      KPNov 24, 2019

                      Here's how to use your widget in Nuxt, for future reference:

                      @kiyuku1 's answer would work, but here's the complete solution that would work if we want to include a js (or mjs) file in ONE nuxt.js page only, instead of globally:

                      <template>
                        <div class="container">
                      
                          <div>
                              <dev-widget data-username="saurabhdaware"></dev-widget>
                          </div>
                      
                        </div>
                      </template>
                      
                      <script>
                      
                      export default {
                        layout: "default",
                      
                        head: {
                          script: [
                      • Saurabh Daware 🌻
                        Saurabh Daware 🌻Nov 24, 2019

                        Oh I did not know Nuxt required separate handling. Thank you so much 🌻

  • Raghav Misra
    Raghav MisraJan 3, 2020

    Amazing! I saw this and was impressed. Then I saw web components, great job. Dev Api use will definitely go up a lot now 😁

  • DaNeil C
    DaNeil CJan 8, 2020

    great widget!

  • Janko
    JankoNov 29, 2020

    I'm new here a I tried it with my account (jankoweb) and it does not work. Your example works. Could you help me?

  • Mateusz Nowak
    Mateusz NowakNov 1, 2021

    Hi, good job! :) How could I use it with React / Gatsby?

Add comment