protiumx / blogpub

Github action to publish your blog articles from Markdown to Medium or Dev.to
Apache License 2.0
30 stars 6 forks source link
blog ci devto markdown medium-article

blogpub

CI

Github action to publish your blog articles to Medium or Dev.to using their respective REST APIs. The action searches for markdown files in the commit of the push event and uses first md file that finds.

Updating articles

Currently it's not supported to update the articles on the different platforms. If the markdown file found in the push event already exists on the commit before, the action will skip it. This avoids publishing the article again.

Pre-requisites

In order to interact with both platforms API's you will need:

Usage

The action will grab an markdown file from a push event to a branch. The following workflow configuration will publish articles that are committed to the main branch:

on:
  push:
    branches:
      - 'main'
    paths:
      - 'articles/*'

Note: we only want to trigger this action when files are added to the articles folder.

You can define your job as follows:

jobs:
  publish:
    name: publish new article
    runs-on: ubuntu-latest    
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: blogpub
        uses: protiumx/blogpub@v0.6.0
        with:
          devto_api_key: ${{ secrets.DEVTO_API_KEY }}
          gh_token: ${{ secrets.GH_TOKEN }}
          medium_token: ${{ secrets.MEDIUM_TOKEN }}
          medium_user_id: 1f3b633f149233c057af77f0016a9421fa520b9a59f97f5bd07201c2ca2a4a6bc

Check my personal blog source as example of usage

Inputs

Example:

---
title: New Article
description: Some description
tags: test, ci
license: public-domain
---
# This is my new Article

In this article we will learn how to setup with `blogpub`

## Relative paths from the repository

![ci-meme.jpg](./assets/meme.jpg)

## Requirements

...

Outputs

Articles configuration

blogpub will search for metadata surrounded by section markers ---. The metadata should be a yml section.

The following arguments can be set:

Template Support

blogpub supports handlebars templates. It provides the following context

{
  medium: boolean;
  devto: boolean;
}

Usage:

{{#if medium}}
This is only for Medium
{{/if}}

Relative Paths

You can use relative paths to use any media files hosted in the same repository as the article files. All relative paths will be resolved using the github raw content URL.

Example:

![image](./img1.png)
<img src="https://github.com/protiumx/blogpub/raw/main/./assets/img2.jpg" />

Will be parsed as

![image](https://raw.githubusercontent.com/<owner>/<repo>/<articles_folder>/img1.png)
<img src="https://raw.githubusercontent.com/<owner>/<repo>/assets/img2.jpg" />

Developing

Run tests

yarn test

Run build

yarn build

Testing action locally

If you want to test the action locally you could clone blogpub-test and use act to run the action.

Contributing

Please submit a PR with any contribution. Refer to the list of TODO's or open issues.

TODO