Code Monkey home page Code Monkey logo

blogpub's Introduction

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/[email protected]
        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

  • 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 paths from the repository

![ci-meme.jpg](./assets/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 | string[]] Comma separated tags or yaml list. 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
  • canonicalUrl: [string] The canonical URL of the post (supported in both Medium and Dev.to)

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="../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

  • Relative paths to github raw server
  • 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 per job run

blogpub's People

Contributors

protiumx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

blogpub's Issues

Not able to add ./ for bash code in markdown

Hi @protiumx, I saw there is a relative path feature from README.md for adding media files.

Nevertheless, I realized maybe because of this, I couldn't add ./ for bash code in markdown as it would be converted to github urls.

For example, when I tried to add these in markdown file

$ cd build/bin
$ ./my_executable

It would be published as

$ cd build/bin
$ https://raw.githubusercontent.com/<my_relative_path>/my_executable

May I know how to resolve this issue?

Request for adding support for Images : Very important

@protiumx first of all this is a great project, thanks a lot for developing this and open sourcing this. I have been researching about such automated tools and could not find one. You can easily make a decent business out of it my friend and i can bring you some customers :)

I have used your instructions and I am happy to report that they work flawlessly.

To make this production-ready (i mean to be ready to use by the public), it currently lacks support to images

  • Images on the cover page of a blog
  • Images in the markdown body of the blog

I am not a TS/JS developer, otherwise, i could have sent you a PR. I can only request you to kindly prioritize adding the support for images and it would be ready to by the broader audience.

Other features that could be interesting are

  • incremental updates to existing blogs
  • adding support to hashnode would be awesome too
  • adding support to publish only one blog

I am happy to contribute in promoting / documentation / bragging about this tool if not with Code. Hope this helps.

Medium does not respect Title provided in markdown

Hi @protiumx This is a minor issue

When we publish the blog using Markdown on both dev.to and medium.

The medium blog does not respect the title provided in the markdown. Below is my real blog post i published on medium using GHA

---
title: Increase timeout of OpenShift Web Terminal 
description: Learn how to increase the timeout of OpenShift Web Terminal from 15 minutes to any time you want.
tags: 'openshift,web,terminal'
cover_image: ./assets/cat.jpeg
canonical_url: null
published: true
---

image

Add support for Hashnode

Description

Add support for publication using the hashnode API

Describe the solution you'd like

Allow this action to publish posts to hashnode as well as medium and dev.io

Describe alternatives you've considered

Using another action that will handle the publication for hashnode and pass the canonical URL to this action once #23 is implemented

Add support for canonical URL

Description

As we're handling cross-posting here there is an SEO penalty that we have to pay, to avoid one (or both) of the published articles should have the canonical URL from the main published site.

Describe the solution you'd like

There should be a new optional flag with the canonical URL, and an option to set it to either one of both of the blogging systems (e.g. in my case my main system is hashnode)

A better option would be to select the main account, so if in the future there are more blog systems you can automatically set the canonical URL to all non-main accounts

Describe alternatives you've considered

At this moment the only alternative is to run the action in draft mode and manually alter the outcome after each post-publication

Additional context

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.