Here is another yet article about automation of the blogging process with a self-hosted website.
Today we’re going to explore the medium API and take a look at GitHub action, which copies your website’s blog post to the medium in no pain.
The following code snippet publishes a blog post written in markdown using Github Actions directly to Medium.
You may ask “How this could be applied in the real world?”
It really could if you automate your blog with Github Actions.
Here are a couple of examples of where to use it:
MEDIUM_ACCESS_TOKEN="generated token"
Here is a quick example:
name: publish-to-medium
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- id: files
uses: jitterbit/get-changed-files@v1
- id: posts
name: Detecting posts from the changes
run: |
i=0
for changed_file in ${{ steps.files.outputs.added_modified }}; do
echo "Do something with ${changed_file}."
if [[ "${changed_file}" == "content/posts"* ]];
then
echo "File ${changed_file} matched post."
echo "::set-output name=post${i}::${changed_file}"
((i=i+1))
fi
done
- if: steps.posts.outputs.post0
name: Publish to medium
uses: infraway/post-medium-action@main
with:
app_id: ${{ secrets.MEDIUM_APP_ID }}
app_secret: ${{ secrets.MEDIUM_APP_SECRET }}
access_token: ${{ secrets.MEDIUM_ACCESS_TOKEN }}
markdown_file: ${{ steps.posts.outputs.post0 }}
base_url: https://andrew.red
post_url: https://andrew.red/posts
Find more useful DevOps automation tools at:
Of course, all the source code is open-sourced.
Any feedback, contribution, or help is highly appreciated.
Thanks for your time and have a nice coding! 👋