DEV Community

Cover image for The Unofficial Dev.To Embed Web Component
Mads Stoumann
Mads Stoumann

Posted on

The Unofficial Dev.To Embed Web Component

The other day, I re-discovered the dev.to API and found out that it can be used without an API key. Thatโ€™s really great if you want to embed your articles anywhere โ€” maybe on a personal blog โ€” without the hassle of protecting secret keys. You can fetch a list of articles by a given author or a specific article.

So, I coded a web component that lets you grab either a list of articles or a specific one. Letโ€™s start with the โ€œlist modeโ€:

<dev-to
  author="madsstoumann"
  theme="classic"
  itemsperpage="10"
  links="internal">
</dev-to>
๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung ๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung

Hereโ€™s what we get:
List

Notice the theme and links attributes.

Iโ€™ve added 3 themes to choose from (but you can easily add your own):

  • brutalist
  • classic
  • modern

links can be either โ€œinternalโ€ or โ€œexternalโ€. The first opens the article directly within the web component, while the latter opens the article on dev.to in a new tab.

Now, letโ€™s click on โ€œThe Golden Ratio in CSSโ€.

Classic Theme

Very posh, classic theme, isnโ€™t it?!

If you just want to show the article directly, without showing the list first, you can use the component in โ€œarticle modeโ€:

<dev-to article="2014104" theme="classic"></dev-to>
๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung ๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung

Letโ€™s change the theme to โ€œmodernโ€:

Modern

... or how about โ€œbrutalistโ€, for that raw, industrial look?

Brutalist


Internationalization

If you want to display dates and UI text in your local language, the component supports i18n this way:

<dev-to 
  author="madsstoumann"
  lang="es"
  i18n='{"es":{"more":"Mรกs...","reactions":"reacciones"}}'>
</dev-to>
๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung ๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung

Customization

The component exposes several parts that you can style using CSS ::part():

dev-to::part(avatar) {
  border-radius: 50%;
  border: 2px solid currentColor;
}

dev-to::part(cover) {
  filter: sepia(0.3);
}

dev-to::part(more) {
  background: #ff00ff;
}
๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung ๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung

Shadow DOM or Not?

If you need to style the component directly (without shadowDOM and parts), just add the noshadow attribute:

<dev-to author="madsstoumann" noshadow></dev-to>
๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung ๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung

Demo

You can try out a demo, using external links, here: browser.style/ui/dev-to

Installation

You can install the component directly from npm:

npm i @browser.style/dev-to
๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung ๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung

Or import the script directly from browser.style:

<script
  type="module"
  src="https://browser.style/ui/dev-to/index.js">
</script>
๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung ๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung

Let me know what you think!


Cover Photo by Markus Spiske: https://www.pexels.com/photo/mork-computer-gron-software-225769/

Top comments (18)

๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung
 
ben profile image
Ben Halpern •

Nice

๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung
 
madsstoumann profile image
Mads Stoumann •

Thanks!

๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung
 
dansasser profile image
Daniel T Sasser II •

Very good ๐Ÿ‘ I've been playing around with it, integrating the comment section and reactions into my blog for articles that have been cross posted. I have it working pretty good and I'm about ready to update my blog with it.

๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung
 
madsstoumann profile image
Mads Stoumann •

Nice! Will you share a link when itโ€™s up?

๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung
 
dansasser profile image
Daniel T Sasser II •

Will do ๐Ÿ‘
I've been meaning to update it for a couple of weeks now actually. I have so many projects going between my AI research and our current app development. But now that you and I are talking about it, it's back to the top of the list!

๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung
 
peter profile image
Peter Kim Frank •

This is really cool ๐Ÿ”ฅ

๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung
 
madsstoumann profile image
Mads Stoumann •

Thanks!

๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung
 
grahamthedev profile image
GrahamTheDev •

Love this bud. FYI brutalist might need a tweak in dark mode as the lines obscure the text.

Great component!

๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung
 
madsstoumann profile image
Mads Stoumann •

Oh, added those lines as a last-minute thing! Will add light-dark() soon.

๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung
 
madsstoumann profile image
Mads Stoumann •

Fixed!

๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung
 
grahamthedev profile image
GrahamTheDev •

Nice!

๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung
 
jankapunkt profile image
Jan Kรผster ๐Ÿ”ฅ •

Is browser.style owned by yourself?

๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung
 
madsstoumann profile image
Mads Stoumann •

Yes, itโ€™s my personal, digital playground!

๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung
 
artydev profile image
artydev •

Thank you very much

๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung
 
madsstoumann profile image
Mads Stoumann •

Thank you!

๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung
 
louis7 profile image
Louis Liu •

Cool!

๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung
 
madhurima_rawat profile image
Madhurima Rawat •

Great article ๐Ÿ‘. Truly we learn a new thing every day .

๐Ÿ† Live Soccer TV: madsstoumann/the unofficial devto embed web component hjk - Jadwal Siaran Langsung
 
madsstoumann profile image
Mads Stoumann •

Thanks, happy to hear that!

Some comments may only be visible to logged-in visitors. Sign in to view all comments.