DEV Community

Cover image for I completely rewrote my personal website using Dev.to as a CMS

I completely rewrote my personal website using Dev.to as a CMS

James Wallis on February 03, 2021

The final weekend of January 2021 was uneventful in comparison with other years - in the UK we were in full lockdown due to the Coronavirus. It was...
Collapse
 
juliang profile image
Julian Garamendy

Hi! I'm doing something very similar.
dev.to/juliang/using-dev-to-as-cms...

I'm using disk cache to solve the 429 error "Too many requests".

I would love to know what you think.

Collapse
 
jameswallis profile image
James Wallis

Hi Julian! Our solutions are extremely similar. I had a look through your article, good read - I could have used diagrams like yours to make mine a bit clearer!

AFAIK the main difference between yours and mine is that for getStaticProps I'm calling the Dev.to API that returns the information for a specific article (/articles/:id) whereas you would call get all articles (if not for the cache) (my API call for a single article).

I do this so that I am able to use the pre-rendered HTML that Dev.to supplies (body_html in the article object), for some reason it isn't included when you query all your published articles - I saw you're parsing the provided article markdown. I wanted to use the supplied HTML so that I didn't need to parse Markdown just to see if it was viable/make the website simpler.

I think if I was to refactor my implementation to make fewer requests I would save the data returned from the get all articles to a cache file in the getStaticPaths file, and in the getStaticProps file read the data directly from the cache rather than querying the Dev.to API. I already use a cache file to map the page slug to an article ID. The getStaticPaths function writes the cache with a minified array which is then read by the getStaticProps function to find the article ID for a page.

Collapse
 
juliang profile image
Julian Garamendy • Edited

Yes. I'm "fetching" all the articles every time (but caching) because I had these two requirements:

  • custom slugs (which you solve with the cache in getStaticPaths)
  • no rebuilds / no redeployments (I can add an article to dev any time and my blog will pick it up without having to regenerate, because it's using Incremental Static Regeneration)
Thread Thread
 
jameswallis profile image
James Wallis

Nice one, yeah I opted to use the Webhook calling Vercel Deploy hook on an article create/update rather than using Incremental Static Regeneration so that I don’t call the API when no changes have been made. The only downside with the webhook is that even if I edit and save without any changes, a deployment is kicked off.

I think in the near future (perhaps this weekend) I’ll change my website to call the API once to get all the articles, cache them, then convert the cached markdown and display - should solve my ‘429’ error! Thanks for the help

Thread Thread
 
prnvbirajdar profile image
Pranav Birajdar • Edited

I was just wondering why dev.to API has different route options to display same data and you guys answered it for me! I am building my website and it's my first time using getStaticProps and getStaticPaths.

Thank you for clarifying some things for me!

Thread Thread
 
jameswallis profile image
James Wallis

Happy I could help!

Collapse
 
yoursunny profile image
Junxiao Shi

This is a risky direction.
In 2035, Dev.to is bankrupt and no longer exists. You still have your Markdowns but you lose the uploaded pictures.

I have a few blog posts written around 2008 where images were uploaded to third party hosting services. In 2017, I discovered that the images hosting service was closed and all these images disappeared.
I had to dig out the original files of these blog posts and re-export the images. The files were in Kingsoft WPS 97 format, and I had to download that application in order to open the files.

I'm still mourning the loss of a few videos from 2006 that I uploaded to now-defunct third party hosting and no longer have a backup myself.

Collapse
 
jameswallis profile image
James Wallis • Edited

I disagree.
There is nothing wrong or risky in leveraging Dev.to as a CMS, as long as you back up your data.

It would be pretty trivial to set up a service/app to save your articles each day using the Dev.to API and performing a download of any images you've used in your articles.

Why not take advantage of the free platform Dev.to is providing? Just take backups of your data.

Collapse
 
foolhardy21 profile image
Vinay

loved your website!

Collapse
 
jameswallis profile image
James Wallis

Thanks Vinay!

Collapse
 
abrahamlawson profile image
Lawson

Also love next.js <3

Collapse
 
teamallnighter profile image
Chris Connelly

looks amazing dude! great work

Collapse
 
jameswallis profile image
James Wallis

Cheers!

Collapse
 
z2lai profile image
z2lai

Genius.

Collapse
 
judecodes profile image
Cool

Hi first time loading the site and it was super fast! Can you do an article of how you did it?

Collapse
 
jameswallis profile image
James Wallis

Yes I’m working on one at the moment!