Looking for Senior AWS Serverless Architects & Engineers?
Let's TalkWrite a script to clean the HTML of your article and repost it elsewhere
As of 2017, Medium no longer offers Custom Domains. They have an API and a few SDKs for publishing to Medium. What if you want to repost your entire Medium content on your personal domain in one batch?
One way is to download your entire content as a .zip file. The API doesn’t seem to let you do such a large export.
After downloading, the parsing can be done in many ways. The way covered here has a Node.js script in AWS Lambda cleaning HTML uploaded to S3.
You could do this transformation locally, but if you want to repeat this parsing process on a schedule, you may want the reliability and automation of cloud services such as AWS Lambda and CloudWatch Events cron rules.
Steps to downloading your content
- Click on your profile picture in the top right corner.
- Click on Settings.
3. Scroll down and click on “Download your information.”
4. Click “Download .zip”
5. Read the explanation and click “Export.”
Medium’s explanation of downloads:
Download your information
You can request a .zip file containing HTML files of your Medium posts and drafts, info that you have shared on your profile, stories you’ve clapped on, and more.
We’ll email you at elonmusk@gmail.com with a link to the .zip file when it’s ready. The link will be available for 24 hours after you receive the email. If you wish to use a different email address, you may change it on the settings page.
By initiating the process to receive these files you are representing that you have all necessary rights and permissions to receive the content included in the file.
Upload to S3
The short version:
- Create an AWS account.
- Unzip your Medium export locally.
- Create an S3 bucket, click upload, and drop your articles folder in there.
The long version: https://docs.aws.amazon.com/AmazonS3/latest/user-guide/upload-objects.html
Parse, filter, clean, save
Once an object is in S3, you can manipulate it in all kinds of ways. If you just want to strip out Medium’s CSS so you can use your own website’s CSS, you could just do a few Regex replacements, as we did with an AWS Lambda function and a Serverless template for Serverless Guru website’s blog.
The replace statements in this script are fragile in that they depend on Medium’s HTML style to stay the same, but it gets the job done for now of porting over dozens of articles all at once while maintaining our own CSS.
Careful: If you use that particular script, it overwrites the contents of the bucket you point it to.
You can either run the function manually by clicking Test in the Lambda console or do it programmatically with CloudWatch Events.