DEV Community

Cover image for Create a static mirror of your DEV blog
Dimitrios Kechagias
Dimitrios Kechagias

Posted on • Originally published at blogs.perl.org

2

Create a static mirror of your DEV blog

I started using DEV at the suggestion of Perl Weekly, and I was quite pleased with it - until I discovered that links to dev.to are effectively "shadowbanned" on several major platforms (Reddit, Hacker News, etc.). Posts containing DEV URLs would simply not be shown to users, making it impossible to share content effectively.

To work around this, I thought I would need a way to publish my DEV articles on my own domain so I could freely share them. There are some DEV tutorials out there that explain how to consume the API using frontend frameworks like React, however I don't enjoy frontend at all and I did not want to spend much time on that.

My solution was to get a simple Perl script that builds static versions of the articles, along with an index page. A Perl 5 script will run anywhere, including an old shared linux hosting account I still keep on IONOS, and I really like the speed of static sites.

I thought this is an ideal task to start with ChatGPT. Indeed, after 10-15 mins in a few prompts I had a sort-of working solution without having to open up the API documentation, nor writing any CSS. I then spent an hour or two fixing bugs, refactoring some of the ancient-looking code and tweaking / adding features (e.g. tag index pages) - tasks that I enjoy.

Here is the result. You can find the Perl script and assets in this repo.

It will run on pretty much any Perl 5 version (tested down to 5.10) with some basic CPAN modules (LWP::UserAgent, JSON, Path::Tiny).

To use it, check the project out from the repo and change 2 lines in dev_to_static.pl with your username and your desired blog name:

my $username = 'your_dev_to_username';
my $blogname = "your_blog_name";
Enter fullscreen mode Exit fullscreen mode

Generate the static site to a target_directory:

perl dev_to_static.pl target_directory
Enter fullscreen mode Exit fullscreen mode

You can run it on your web host, or run locally and copy the resulting directory to your host.

A nightly cron can update the site with new articles.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (2)

Collapse
 
szabgab profile image
Gabor Szabo

You might also want to set the canonical_url on DEV to point to the article on your site.

Collapse
 
dkechag profile image
Dimitrios Kechagias

I intentionally go the other way around. I like to post on DEV, I do not want to have to maintain a CMS myself, so the mirror is only for sharing in places DEV is not welcome. In fact, if my topic is Perl, I make a blogs.perl post as well and have that be the canonical_url here. The static mirror sets the canonical to whatever DEV lists (so it's either dev.to or blogs.perl in my case).

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay