DEV Community

Cover image for Manage your dev.to blog posts from a GIT repo and use continuous deployment to auto publish/update them

Manage your dev.to blog posts from a GIT repo and use continuous deployment to auto publish/update them

Maxime on July 07, 2019

04/2023 UPDATE: While the overall idea of the blog post remains unchanged and is still relevant, I no longer recommend to use Travis. Instead use G...
Collapse
 
protium profile image
protium

This is a really good idea with great potential. Image a standarized API for different blogs. You can automatize publishing and editing, multiple collaborators. And use a git provider as unique source of content.

And you can also make your git repo as some sort of blog. I'll use it for my next posts for sure.

Thanks!

Collapse
 
maxime1992 profile image
Maxime

Hi Brian,

This is a really good idea with great potential

Thanks! I do intend to push it further and someone else plans to help me out :)!

Image a standarized API for different blogs

That was the original purpose. But I realized it wouldn't fit into a hackday so I decided to get the project up and running with support for only one "publisher" (dev.to). My original though was that I'd build something completely abstract and we could choose for one article to publish on multiple "publisher" at the same time (dev.to, medium, etc).

And you can also make your git repo as some sort of blog

Definitely!

I'll use it for my next posts for sure.

Awesome, glad to hear that! =)

Collapse
 
thefern profile image
Fernando B 🚀

Check out my git jekyll blog takes less than a few minutes to setup.

Jekyll

Collapse
 
protium profile image
protium

Hey!
It's been almost 3 years since my comment. I ended up building this github action: github.com/protiumx/blogpub/

And here the article I wrote about it protiumx.dev/blog/posts/publish-yo...

Also how I use it for my blog
github.com/protiumx/blogp/

Collapse
 
michaelbrooks profile image
Michael Brooks

I've literally just moved my Blog from WP to VuePress and publishing it over to Netlify with NetlifyCMS integrated. I'm going to try and integrate this into workflow and see if it works. Thank you for this blog post.

Collapse
 
maxime1992 profile image
Maxime

Hey Michael,

Glad you're up to give it a go, let me know how it goes!

Collapse
 
louis profile image
Louis Augry

Good job ! Thank's you for sharing this with us !

Collapse
 
maxime1992 profile image
Maxime

Thanks for the kind words Louis!

Collapse
 
shijiezhou profile image
Shijie Zhou

this way seems like an extra step that you need to make before the post. You always need to get the draft id before it posts.

Collapse
 
maxime1992 profile image
Maxime

It doesn't seem like it is. It clearly is 🙄. Unfortunately it's the best I could come up with as dev.to do not use UUIDs. Otherwise it'd have been easy to generate one 🤷‍♂️ here the only way to automate that part would be to correlate the blog post title but it'd be an issue if you update it (which is obviously not great). As it's a one time thing for an article, I think it's not too bad either though

Collapse
 
fyodorio profile image
Fyodor

Maxime, first of all, thanks for the cool idea 👍
I have a couple of questions/suggestions:

  1. (on Jay's concern) Why not try to use dev.to API's POST request and get an article ID with the response?
  2. Didn't you try to replace Travis with Github Actions? This way one gets the opportunity to use the workflow with a private repo
Thread Thread
 
maxime1992 profile image
Maxime

Hi Fyodor, thanks :)!

1) It'd be great for sure to have something in command line and we've got an issue here github.com/maxime1992/dev-to-git/i... if you have further ideas on that please share there

2) I did not as I'm not yet familiar with github actions. I'd be happy to have a PR if you feel like it though! :) Could you please open an issue first there github.com/maxime1992/dev-to-git/i... so we can discuss it and then we can talk about a PR

Thanks

Thread Thread
 
fyodorio profile image
Fyodor

Thanks for the coordination Maxime! Zak's ideas on id handling look comprehensive, they just need to be implemented) As for github actions, I'm not very familiar with that too, need to research, and I would be happy to contribute if I have enough time, you know. Added the issue to discuss further 👌

Collapse
 
saulsilver profile image
Hatem Houssein

Thank you very much!

I was just thinking about it a month ago. Create my blog posts on my website (using NetlifyCMS using Git workflow) then a CD/CI tool (CircleCi) would publish them on Dev.io too. 🎊

Collapse
 
sheldonhull profile image
Sheldon

This is pretty cool. Can you help me understand the use case for this vs using Hugo and jeykll? Is this an alternative to creating your own static content and instead leveraging dev.to for hosting it all? Is there any advantage over rss feeds for integration for those of us who have our own site?

Collapse
 
maxime1992 profile image
Maxime

Hi, sure thing. It is instead to leverage dev.to to host it. As you're aware, a lot of people are publishing on dev.to. Maybe for the audience and visibility, maybe because they don't want to have to learn how to use Hugo and jekyll, or any other reason. But the point is, for those people I'm pretty sure it's hard to:

  • ask for a review before publishing
  • let someone somehow fix things in the article
  • keep track of changes if the article evolves
  • have a backup in case they mess up the article (failed save for e.g.)

With this solution, they can be setup in 2mn to use git and continuous integration to deploy on dev.to 😊

I hope it makes sense

Collapse
 
piyukore06 profile image
Priyanka Kore

Best thing ever!! Thank you so much for sharing 🙌🏻🙌🏻

Collapse
 
maxime1992 profile image
Maxime

Thanks for the kind words Priyanka 😊!

Collapse
 
crisarji profile image
crisarji

Hey sir! awesome post, just started posting on my own and I am following this approach.

Something that happened to me, and I want to share it here(I was looking among comments but did not find the same issue) was that the very first post worked like a charm in TravisCI!, but the second started to complain, I kept receiving this error message in TravisCI job log:

0.92s$ if [ "$TRAVIS_BRANCH" = "master" -a "$TRAVIS_PULL_REQUEST" = "false" ]; then DEV_TO_GIT_TOKEN=$DEV_TO_GIT_TOKEN yarn run dev-to-git; fi
yarn run v1.3.2
(node:6600) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
warning package.json: No license field
$ dev-to-git
[PUBLISHED] Article "Authentication with Vue(x)+Firebase" is already up to date
[DRAFT] Article "Adding roles to the authentication with Vue(x)+Firebase" encountered an error:
Error name: "HTTPError"
Error message: "Response code 422 (Unprocessable Entity)"
Error stack: "HTTPError: Response code 422 (Unprocessable Entity)
    at EventEmitter.emitter.on (..../blogs-dev.to/node_modules/dev-to-git/bin/dev-to-git.umd.js:7080:23)
    at processTicksAndRejections (internal/process/task_queues.js:86:5)"
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Done. Your build exited with 0.
Enter fullscreen mode Exit fullscreen mode

The PUBLISHED was a success every single time, the DRAFT kept showing that error(odd, with a 0 exited, so it was ok(?), or at least not affecting the status) till I manually set the published: true, then the next build the error was gone.

Just wanted to share in case that this could be relevant for anyone else.

Collapse
 
toonarmycaptain profile image
toonarmycaptain

I'm having some issues with this. My github action was passing, but not posting, there were 422 errors in the log, then when I update the dependencies the action fails with log, 429 and 422 errors.

Any ideas?
github.com/toonarmycaptain/toonarm...
TIA.

Collapse
 
maxime1992 profile image
Maxime

Have a look here: github.com/maxime1992/dev-to-git/i... no fix so far but someone explained how he found the root cause at least

Collapse
 
toonarmycaptain profile image
toonarmycaptain

I'm not sure that's the issue - I have blank/empty cover image fields, since I haven't used one?

Collapse
 
maelingcodes profile image
Maeling (she/her)

Thanks for creating this template! I am trying to implement it but I'm a little unsure on how to actually push the updates I make in my repo to dev.to. I tried to copy the file structures and updated the dev-to-git.json file with the draft post id and relative path, but when I make changes to the blog post .md file, I don't see the changes being made when I visit the post draft link on dev.to. Am I going about this the wrong way?

Do you mind providing a little more guidance on the steps after creating the blog post file?

FYI: I just started using git this month, so I'm a noob when it comes to using GitHub

Here's a link to my repo: github.com/maelingmurphy/my-dev.to

Thanks!

Collapse
 
maxime1992 profile image
Maxime

Hi Maeling, sure I'll help you out.

I've created an issue on your repo to avoid continuing the discussion here as it's probably not the best place :)

github.com/maelingmurphy/my-dev.to...

Collapse
 
maelingcodes profile image
Maeling (she/her)

Thanks Maxime! Checking it out now

Collapse
 
0xdonut profile image
Mr F. • Edited

This is a great article. thanks for sharing Maxime.

I'm having trouble with my Travis CI build. It keeps failing when it gets to yarn:check

any ideas?

Collapse
 
maxime1992 profile image
Maxime

Hi, thanks for the kind words.

I've looked into your repo and apparently the latest commit is green on CI :). Is the issue gone?

Otherwise, can you please make sure to:

  • upgrade all the dependencies and dev dependencies on your project
  • compare your travis conf with github.com/maxime1992/my-dev.to/bl... as I've had to fix a few things I may have forgotten to fix on the template

Let me know how it goes

Collapse
 
gabbersepp profile image
Josef Biehler

Hey, I have one question regarding images that are used in posts. I have updated the image in section "2. Create a dev.to token". The PR already got merged. But the old image is still visible. I checked it in IE, too. As I never use IE, this browser can not have cached it.
So someone else must cache the image. I already stumbled across this problem when updating a cover image a few times. I had to rename it in order to see the changed image.
Do you know how this can be solved?

Collapse
 
maxime1992 profile image
Maxime

Hi Josef. Interesting. Can you please create an issue here github.com/maxime1992/dev-to-git ?

I think I've got an idea how we could fix this.

We could attach a param in the URL with the commit hash for ex that'd bust the cache :)

Collapse
 
gabbersepp profile image
Josef Biehler

[x] done

Maybe I try a fix if I find some time

Collapse
 
kvanrooyen profile image
Keagan Van Rooyen

I know this is an old post now, but I thought I would share in case anyone stumbles across this. I created a simple Python script to automate the creation of the blog post folder and markdown file. I plan on having the script get the ID of the post as well, but that is for the future. Check it out here.

Collapse
 
apayrus profile image
Rustam Apay • Edited

In the May I started to write a tutorial, I thought it will be 1 article, but it became 13 chapters :D
I don't want to publish and update them manually on site and on github. Thats how I found this article.
I didn't implement this idea yet, but I hope I can do that.

Collapse
 
jikuja profile image
Janne Kujanpää

The main advantage of Github Actions over Travis is that you can get 2000mn of free time if the repo is private (which should be more than enough!).

It should be noted here that private repository cannot host images for the article. User needs to use external image host or otherwise solve image upload to dev.to.

Collapse
 
codefrombasics_434b222334 profile image
Codefrombasics

Great post! Git has truly revolutionized version control, making collaboration so much smoother. I particularly appreciate how Git branching allows for experimentation without risking the main codebase. For those looking to dive deeper, I've found that understanding Git's internal data structure—like how commits are stored as a chain—really helps in mastering more advanced features like rebasing. I've also written about some lesser-known Git tips that can streamline your workflow. Keep up the great work! GIT Training in Chennai

Collapse
 
thefern profile image
Fernando B 🚀

I just started writing my articles on a repo and using Jekyll, with rss feed. Only drawback is once article is released on dev, and changed on repo, it won't update.

Collapse
 
rdewolff profile image
Rom

Nice, thanks for sharing!

Collapse
 
pan profile image
Pan Wangperawong

Great job! This allows you to have contributors and editors.

Collapse
 
maxime1992 profile image
Maxime

Definitely a good fit for that use case! 😁

Collapse
 
perigk profile image
Periklis Gkolias

Awesome. Just on time I was thinking to setup such thing.

Collapse
 
maxime1992 profile image
Maxime

Awesome Periklis, if you give it a go let me know if you found the setup easy or if there was any pain point 👌

Collapse
 
zex profile image
Zex

what i was thinking about😂 a repo of markdown

Collapse
 
futoase profile image
Keiji Matsuzaki

Good Job! Awesome!!!

Collapse
 
areahints profile image
Areahints

Wow! learn something new everyday!

Collapse
 
artydev profile image
artydev

Great, thank you very much

Collapse
 
jcoelho profile image
José Coelho

What a great idea Maxime! And also a great way to build up your GitHub profile in case you're low on contributions (if some recruiters are looking at your profile)

Collapse
 
michaelquisido profile image
Michael M. Quisido III

Nice One! Thanks for sharing.

Collapse
 
carlillo profile image
Carlos Caballero

Thanks @maxime1992 , good job!

Collapse
 
maxime1992 profile image
Maxime

Much appreciated Carlos 🙏 thanks!

Collapse
 
osde8info profile image
Clive Da

can you HELP im getting prettier dev-to-git.json errors !

full bug report here dev.to/osde8info/devto-autoposting...

Collapse
 
maxime1992 profile image
Maxime

Sure thing. I did reply on your post.

 
mandarvaze profile image
Mandar Vaze

My blog also based on hugo.

Collapse
 
maxime1992 profile image
Maxime

I'm sorry I might be missing something but I do not understand what you mean, could you be more specific?

Collapse
 
boniw profile image
BoniW

thats very awesome article,,
blog.boniw.io

Collapse
 
fred1102 profile image
Frederik Declercq

where are you from

 
mandarvaze profile image
Mandar Vaze

The option you suggested seems great but seems buggy. Only part of my blog post is "imported" (in the drafts)