DEV Community

Cover image for I made DEV.to widget for websites/blogs

I made DEV.to widget for websites/blogs

Saurabh Daware ๐ŸŒป on October 20, 2019

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 li...
Collapse
ย 
artis3n profile image
Ari Kalfus โ€ข โ€ข Edited

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>
Collapse
ย 
loujaybee profile image
Lou (๐Ÿš€ Open Up The Cloud โ˜๏ธ) โ€ข

Came here to say that too โ€” bravo!

Collapse
ย 
saurabhdaware profile image
Saurabh Daware ๐ŸŒป โ€ข

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)

Thread Thread
ย 
artis3n profile image
Ari Kalfus โ€ข โ€ข Edited

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

Collapse
ย 
saurabhdaware profile image
Saurabh Daware ๐ŸŒป โ€ข

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

Collapse
ย 
kp profile image
KP โ€ข

@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?

Collapse
ย 
saurabhdaware profile image
Saurabh Daware ๐ŸŒป โ€ข

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 ๐ŸŒป๐ŸŒป

Collapse
ย 
kp profile image
KP โ€ข โ€ข Edited

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! ๐ŸŒป

Thread Thread
ย 
saurabhdaware profile image
Saurabh Daware ๐ŸŒป โ€ข
  • .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

Thread Thread
ย 
kp profile image
KP โ€ข โ€ข Edited

@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 >

Thread Thread
ย 
saurabhdaware profile image
Saurabh Daware ๐ŸŒป โ€ข

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

Collapse
ย 
seangwright profile image
Sean G. Wright โ€ข โ€ข Edited

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!

๐Ÿ™

Collapse
ย 
saurabhdaware profile image
Saurabh Daware ๐ŸŒป โ€ข

Thank you so much! this means a lot ๐ŸŒป

Collapse
ย 
z2lai profile image
z2lai โ€ข โ€ข Edited

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!

Collapse
ย 
saurabhdaware profile image
Saurabh Daware ๐ŸŒป โ€ข

Thank you so much for such kind words ๐ŸŒป๐ŸŒป๐Ÿฆ„

Collapse
ย 
z2lai profile image
z2lai โ€ข

Wow, I get two sunflowers! I am honoured.

Thread Thread
ย 
saurabhdaware profile image
Saurabh Daware ๐ŸŒป โ€ข

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!๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป๐ŸŒป

Collapse
ย 
ben profile image
Ben Halpern โ€ข

This is so beautifully done. Iโ€™m super impressed.

Collapse
ย 
saurabhdaware profile image
Saurabh Daware ๐ŸŒป โ€ข

Thank you so much ben๐ŸŒป means a lot ๐Ÿฆ„๐Ÿฆ„

Collapse
ย 
loujaybee profile image
Lou (๐Ÿš€ Open Up The Cloud โ˜๏ธ) โ€ข

Will this create any significant impact on DEV API consumption?

Collapse
ย 
paulasantamaria profile image
Paula Santamarรญa โ€ข

Looks great, thank you!

Collapse
ย 
saurabhdaware profile image
Saurabh Daware ๐ŸŒป โ€ข

Thank you Paula :D

Collapse
ย 
maniflames profile image
Maniflames โ€ข โ€ข Edited

Looks very neat!

Collapse
ย 
saurabhdaware profile image
Saurabh Daware ๐ŸŒป โ€ข

Thank you :)

Collapse
ย 
nickytonline profile image
Nick Taylor โ€ข

Cool stuff Saurabh!

Collapse
ย 
saurabhdaware profile image
Saurabh Daware ๐ŸŒป โ€ข

Thank you so much ๐ŸŒป

Collapse
ย 
prafulla-codes profile image
Prafulla Raichurkar โ€ข

Cool ๐Ÿคฉ

Collapse
ย 
saurabhdaware profile image
Saurabh Daware ๐ŸŒป โ€ข

Thank you Prafulla :D

Collapse
ย 
rose profile image
Rose โ€ข

Love the idea, well done ๐Ÿ˜Š

Collapse
ย 
saurabhdaware profile image
Saurabh Daware ๐ŸŒป โ€ข

Thank you so much ๐Ÿฆ„

Collapse
ย 
deepaksisodiya profile image
Deepak Sisodiya โ€ข

great

Collapse
ย 
saurabhdaware profile image
Saurabh Daware ๐ŸŒป โ€ข

Thank you :D

Collapse
ย 
fultonbrowne profile image
Fulton Browne โ€ข

I will use this on my blog, thanks

Collapse
ย 
saurabhdaware profile image
Saurabh Daware ๐ŸŒป โ€ข

so cool! thank you :D

Collapse
ย 
eaich profile image
Eddie โ€ข

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

Collapse
ย 
saurabhdaware profile image
Saurabh Daware ๐ŸŒป โ€ข

Thank youuu ๐Ÿ•บ๐ŸŒป

Collapse
ย 
s_aitchison profile image
Suzanne Aitchison โ€ข

This is awesome! โ™ฅ๏ธ

Collapse
ย 
saurabhdaware profile image
Saurabh Daware ๐ŸŒป โ€ข

Thank you :D

Collapse
ย 
rhymes profile image
rhymes โ€ข

So cool! Great job!

Collapse
ย 
saurabhdaware profile image
Saurabh Daware ๐ŸŒป โ€ข

Thank you rhymes :)

Collapse
ย 
anjankant profile image
Anjan Kant โ€ข

Well done! I'll use it :)

Collapse
ย 
saurabhdaware profile image
Saurabh Daware ๐ŸŒป โ€ข

Thank you ๐ŸŒป

Collapse
ย 
zooly profile image
Hugo Torzuoli โ€ข

So simple, very nice !

Collapse
ย 
saurabhdaware profile image
Saurabh Daware ๐ŸŒป โ€ข

Thank you ๐Ÿฆ„

Collapse
ย 
raghavmisra profile image
Raghav Misra โ€ข

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

Collapse
ย 
saurabhdaware profile image
Saurabh Daware ๐ŸŒป โ€ข

Thank you Raghav :D

Collapse
ย 
caffiendkitten profile image
DaNeil C โ€ข

great widget!

Collapse
ย 
saurabhdaware profile image
Saurabh Daware ๐ŸŒป โ€ข

Thank you so much :)

Collapse
ย 
mateusznowak profile image
Mateusz Nowak โ€ข

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

Collapse
ย 
jankoweb profile image
Janko โ€ข

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