DEV Community

loading...
Cover image for Writing a dev.to blog post with VSCode

Writing a dev.to blog post with VSCode

Tim Deschryver
๐Ÿ‘Ÿ Runner ๐Ÿ‘จโ€๐Ÿ’ป OSS enthusiast - NgRx, Angular Testing Library, MSW โœ Blogger
Originally published at timdeschryver.dev ใƒป2 min read

Today, I present you ๐Ÿ“ New Blog Post a simple way to create and publish dev.to blog posts from within Visual Studio Code.

Installation

To install the or search for ๐Ÿ“ New Blog Post in the extensions go to the marketplace https://marketplace.visualstudio.com/items?itemName=timdeschryver.new-blog-post.

Writing a dev.to post

The default template of this extension is the dev.to template. To create create a new blog post, right click in the explorer or use the command palette and select ๐Ÿ“ New Blog Post

Gif on how to create a new blog post

Publishing to dev.to

In order to be able to publish your post to dev.to, you have to first create an API access token.
You can create one at https://dev.to/settings/account. Once you have your token copy paste the token in your VSCode settings with the post.publishToken setting:

{
  "post.publishToken": "jbVJ8mwfY2WrPUGfDWjx4xxB"
}
Enter fullscreen mode Exit fullscreen mode

To add this to your config, search via the command palette for settings

When you have added the token to your settings, go back to your post and you can use the ๐Ÿš€ Publish to dev.to command in the command palette.

Image showing how to publish to dev.to

Why

I created this extension to get familiar with VSCode extensions.

Also, my workflow to write my blog posts is to:

  • write them within VSCode
  • publish them to GitHub
  • there's a now trigger that automatically deploys a new version to timdeschryver.dev
  • manually cross-post on dev.to

To make it a little bit easier to myself, I think this extension is a good addition to save a few minutes ๐Ÿ™‚.

More info

For more info and the source code of this extension, go to the GitHub repo

Discussion (32)

Collapse
ben profile image
Ben Halpern

Installed! Please everyone let us know if there are other APIs we can provide to improve this experience so folks feel like they have full confidence in this process. Really fun stuff!!!

Collapse
timdeschryver profile image
Tim Deschryver Author • Edited

Thanks Ben!
If I encounter something I will definitely create an issue on GitHub ๐Ÿ˜ƒ

Maybe one thing that took my a couple of minutes, would be to add some kind of validation responses in the response. For example: if the title has not been filled in, the response is 500: Internal Server Error.

curl -X POST -H "Content-Type: application/json" \
-H "api-key: ACCESS_TOKEN" \
-d '{"article": {"body_markdown": "a body"}}' \
https://dev.to/api/articles

But as I'm writing this, I also noticed that the api docs mentioned these validation messages - so it is probably me who's doing something wrong ๐Ÿ˜…

If you want I can create an issue for this and we can take it from there.

Collapse
cbrintnall profile image
Christian Brintnall • Edited

Could still benefit from a proper status code, in this case it sounds like you were missing information, so maybe a 400 is appropriate?

Thread Thread
sleeplessbyte profile image
Derk-Jan Karrenbeld

422 would probably be more appropriate, but yes, a 4xx status is the way to go.

Thread Thread
timdeschryver profile image
Tim Deschryver Author

Yes, I think having a 4xx would make these "errors" more understandable for us.

Collapse
cyril profile image
Cyril Niobรฉ

Nice tool! Thanks to share it :)

I visited your website, could you explain a bit your flow you used to update your website based on Now to create a new post on your site? I'm curious about it!

thanks

Collapse
timdeschryver profile image
Tim Deschryver Author

Thank Cyril!

I'm using Sapper as a static site generator (you could use more popular ones like Gatbsy, Gridsome, Next, ...). When I push changes to GitHub, Now has a trigger to build the website and deploy it to their servers.

In your repo, you should have a now.json for config, and a now-build script.

You can find out more info on Now for GitHub, if you have a question, feel free to DM me.

Collapse
shreyasminocha profile image
Shreyas Minocha

+1 for now. now is great.

Collapse
gabe profile image
Gabe

Really cool - between this and VS Code's Spotify extension I may never have to leave my editor now

Collapse
lautarolobo profile image
Lautaro Lobo

Spotify extension? Holy Mowly! That goes to the 'search it after exams' list ๐Ÿ˜๐Ÿ‘

Collapse
timdeschryver profile image
Tim Deschryver Author

Thanks Gabe! ๐Ÿ™

Collapse
designpuddle profile image
Chris Bertrand

Nice job, just hoping that token is not your real one!

Collapse
timdeschryver profile image
Tim Deschryver Author

It WAS my real one.
The thing was that I couldn't revoke my access token, so I had to delay the publication of this post. Good thing the dev.to team solved this issue in a day ๐Ÿ˜

Collapse
designpuddle profile image
Chris Bertrand

Phew! Gotta be wary of those sorts of things!

Collapse
hagnerd profile image
Matt Hagner

Awesome VSCode extension! I made a CLI @hagnerd/devto inspired by this extension for any non-VSCode users. I'm sure it's a little rough around the edges still, but figured anyone who stumbled on this post might be interested. :)

Collapse
ceceliacreates profile image
Cecelia Martinez

Using this now! I had a question about code snippets but I was able to figure it out using markdown. Thanks for sharing!

Collapse
timdeschryver profile image
Tim Deschryver Author

Yes, the post you write is completely in markdown. I'm sorry I did not mention it.

Collapse
ceceliacreates profile image
Cecelia Martinez

I'm getting an "internal server error" when I try to publish. Any ideas how I could troubleshoot this? I'm not extremely fluent with VS Code extensions yet.

Collapse
timdeschryver profile image
Tim Deschryver Author

This version of the extension, simply calls the dev.to API and shows the response of the API. I will work on this, so these errors will be more readable in one of the upcoming versions.

I think you're getting this error because one of the front matter properties are not filled in - for more info see the api docs and search for front matter.
For now, feel free to DM me your blog post (or a trimmed down version) and I can take a look.

Thread Thread
ceceliacreates profile image
Cecelia Martinez

That makes sense! I didn't have the cover image and canonical url filled out. I'll let you know how it goes with my next post, planning on making another by early next week.

Thread Thread
timdeschryver profile image
Tim Deschryver Author

For what its worth, I just tried it with an empty image and canonical and it seems to be working on my end. The only required field (that I know of) is the title

Collapse
felipeaguiarcode profile image
Felipe Silva Aguiar

Wow, it's amazing!

Collapse
bhupesh profile image
Bhupesh Varshney ๐Ÿ‘พ

Awesome ๐Ÿ”ฅ๐Ÿ”ฅ

Collapse
timdeschryver profile image
Tim Deschryver Author

Thanks Bhupesh! ๐Ÿ™

Collapse
nelo_mf profile image
Manuel Fernandez • Edited

Sounds awesome! I'll give it a try tomorrow (left my laptop at the office)

Collapse
timdeschryver profile image
Tim Deschryver Author • Edited

Cool! Feedback is always appreciated ๐Ÿ˜‰

Collapse
beelzenef profile image
Elena.NET

this is awesome, thanks!

Collapse
rhymes profile image
rhymes

Awesome Tim!!

Collapse
timdeschryver profile image
Tim Deschryver Author

Thanks rhymes! ๐Ÿ™

Collapse
sandeepbalachandran profile image
Sandeep Balachandran

happy

Collapse
bigj1m profile image
Jean-Michel Plourde

Wow! This is an awesome extension and a great way to learn. Good job

Collapse
timdeschryver profile image
Tim Deschryver Author

Thanks Jim!
It was indeed a fun experience where I a couple of things.