Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
book-open

GitHub Action

blogpub

v0.3.4

blogpub

book-open

blogpub

Create blog posts using Medium and Dev.to APIs. Upload automatically all images

Installation

Copy and paste the following snippet into your .yml file.

              

- name: blogpub

uses: protiumx/blogpub@v0.3.4

Learn more about this action in protiumx/blogpub

Choose a version

blogpub

CI

Github action to publish your blog articles to Medium or Dev.to

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 folder blogs.

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.1.8
        with:
          devto_api_key: ${{ secrets.DEVTO_API_KEY }}
          gh_token: ${{ secrets.GH_TOKEN }}
          medium_token: ${{ secrets.MEDIUM_TOKEN }}
          medium_user_id: 1f3b633f149233c057af77f0016a9421fa520b9a59f97f5bd07201c2ca2a4a6bc

Check blogpub-test for more examples or my personal blog source

Inputs

  • gh_token: Github token. Required
  • articles_folder: Folder to look for new articles. Default: blogs
  • medium_token: Your Medium integration token. Required
  • medium_base_url: Medium base URL to post articles. Default: https://api.medium.com/v1
  • medium_user_id: Your Medium user ID. Required. See medium api docs
  • devto_api_key: Your Dev.to API Key. Required

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 images from the repository

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

## External Images

![meme.jpg](https://sources.com/meme.jpg)

## Requirements

...

Outputs

  • medium_url: URL of the published article to Medium
  • devto_url: URL of the published article to Dev.to

Articles configuration

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

The following arguments can be set:

  • title: [string] The title of the article. If not specified, the first H1 heading will be used.
  • description: [string] Description for dev.to API.
  • tags: [string] Comma separated tags. Note: Medium allows up to 5 tags whereas Dev.to only 4.
  • license: [string] Medium license type. Refer to Medium API Docs. Default: public-domain
  • published: [boolean]. Default: true

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 Images

To use images contained in the same folder of the blog articles use @ as source path. @ will be parsed as the URL to the repository/<articles_folder>. E.g.

![image](@/img1.png)

<img src="@/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

  • Test action with custom medium base url.
  • Remove axios in favor of node's https
  • Sanitize inputs
  • Support publishing to only 1 platform
  • Support edition and auto update of articles
  • Support multiple articles
  • Upload relative images