Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/Mr-Destructive/crossposter

Crosspost your articles to dev.to, codenewbie.org, medium.com and hashnode.com with a single shellscript / python package
https://github.com/Mr-Destructive/crossposter

bash blogging crossposting markdown python-cli shell-script

Last synced: 3 months ago
JSON representation

Crosspost your articles to dev.to, codenewbie.org, medium.com and hashnode.com with a single shellscript / python package

Awesome Lists containing this project

README

        

## Crossposter

> Crosspost your articles to dev.to/medium.com/hashnode.com from the command line

- Crossposter is a script(Python/BASH) to automate crossposting to platforms like dev.to, medium.com and hashnode.com. The script takes in markdown version of your post with a few inputs from you and posts it to those platforms. You would require a token/key for each of those platforms to post it from the command line.

There are two versions of the script:

- [Python](#crossposter-python-script)
- [Shellscript](#crossposter-shell-script) (BASH)

The actual script is still not perfect (has a few bugs). Though it posts on `dev.to` and `medium.com` easily, the `hashnode.com` is buggy as it parses the raw markdown into the post and doesn't render as desired. So, **its a under-development script**, fell free to raise any issues or PRs on the official GitHub repo.

## Crossposter Python Script

The python script initially is now a python package. You can essily install and configure it as per your requirements.

[![PyPI version](https://badge.fury.io/py/crossposter.svg)](https://pypi.org/project/crossposter/)

Dependencies for the python script:

- [requests](https://docs.python-requests.org/en/latest/user/install/#install)
- [pyyaml](https://pypi.org/project/PyYAML/)
- [python-frontmatter](https://pypi.org/project/python-frontmatter/)
- [rich](https://pypi.org/project/rich/)

Running the script:

Make sure you install the python package with pip or any other package manager like pipenv or poetry you would like:

```
pip install crossposter

# OR

pipenv install crossposter

# OR

poetry install crossposter

# OR

pipx install crossposter

```

### Configuration

- Create a config file `config.json` for customization
- Create a folder for the output files

Inside the config file, you can specify the two attributes for the working of the script. The first is for generating the `canonical_url` for the post and the next is the output folder for the generated files for different platforms.

```json
{
"blog_link": "https://www.meetgor.com/",
"output_folder": "crossout"
}

```

One it is installed, you can then specify the markdown file which you want to use as a post with:

```
crosspost .md

# OR with pipx

pipx run crossposter

```

This will prompt you for a few things, if not provided in the frontmatter of the command. There will be need of inputs like `title`, `description`, `tags`, `status`, `cover-image`, etc. If you provide it in the frontmatter, there will be no input prompt. Once the input is taken or the frontmatter is picked, it will set those frontmatter for various publications automatically.

```
# post to dev.to

crosspost .md --dev

# post to codenewbie.org

crosspost .md --cdb

# post to medium.com

crosspost .md --med
```

![image](https://user-images.githubusercontent.com/40317114/180605810-99a5616a-3524-4a10-97c4-e118763d9464.png)

![image](https://user-images.githubusercontent.com/40317114/180605864-cbb83793-1944-4bfb-b95f-ef609e3e48e5.png)

For further help on CLI command, you can get the help argument

```
crosspost --h
```

**ShellScript is no longer developed because of content parsing issues, it has been converted to a python package**

Though some basic functions will work in shell script like simple frontmatter, devto and medium posting.

## Crossposter Shell Script

The crossposter shell script is a file to be used from a linux/unix command line in a shell environment. The procedure to execute the file is as follows:

Run the script on a bash interpreter with the command:

```
bash crosspost.sh
```

OR

```
bash crosspost.sh file_name.md
```

For posting the article you need to provide the following details:

## Front-Matter

### Meta data about the post

- Title of Post
- Subtitle of Post
- Publish status of post(`true` or `false`)
- Tags for the post (comma separated values)
- Canonical Url (original url of the post)
- Cover Image (URL of the post's image/thumbnail)

This information is a must for `dev.to` especially the `title`. This should be provide in the same order as given below:

```
---
title: The title of the post
subtitle: The description of your article
published: true
tags: programming, anythingelse
canonical url: url of your original blog
cover_image: coverimage_url
---
```

There is no need to enclose any of them with quotation marks. `Published` argument will be `true` if you want to publish it and `false` if you want to keep it in your Drafts.

In the demonstrations, we just need to enter the tokens once. The tokens will be stored locally in the `keys.txt` file and retrieved later within the script.

### Posting on **dev.to**:

Posting on dev.to requires their `API key` which can be generated by going on the [Dev Community API Keys](https://dev.to/settings/account/). From there you can generate a new key with any name you like. You just need to enter the key to CLI once or manually enter in the `keys.txt` file with the format `dev.to:key` on the first line. This will be used for the future cross-posting whenever you execute the shell script(`bash crosspost.sh`)

You can provide the [front matter](#front-matter) manually in your markdown file or you will be prompted for the input. So, that is all you will require for posting on dev.to from the Command line.

Lets see the script in action

![dev.to](https://gitlab.com/MR_DESTRUCTIVE/tblog-img/-/raw/main/devto.gif)

If you want to add in more stuff to the post, you can check out the [DEV.to API docs](https://developers.forem.com/api#operation/createArticle) which is powered by [Forem](https://www.forem.com/), there a ton of options you can hook to the front-matter in the shellscript.