Publish a local markdown file to sites at once by Java, Usage
Usage explanation of a Java program, which tidies up the format and publishes to different blog sites by API
1. Introduction
When I tried to paste the local markdown file to the blog sites, like DEV Community and Medium, the formatting may be lost and the code block may not be properly indented nor properly highlighted (especially Medium😢) and it takes more than a few minutes to fix it.
After googling for some while, there is no easy method to solve this instead of using the blog site API.
I asked myself this question, can I write an application to solve the above problem and at the same time, publish the local markdown file to several sites as a draft so I do not need to paste it one by one?🤔
I turn out to write a Java program, which I will introduce below, to solve the above problem.
2. Usage
We will first talk about how to use the program.
2.1. Setup
Download the zip file
Input the tokens in
tokens.properties
GITHUB_TOKEN=<enter your github token here>
DEV_TO_TOKEN=<enter your dev to api key here>
MEDIUM_TOKEN=<enter your medium token here>
In case you do not know where to find the token,
You can see find the guide after expanding the following:
- Install Java 17 on your PC (place
java
in environment variable)
If you install it correctly, you should see the following:
2.2. Run
- Run the following command in cmd:
java -jar publisher-0.0.1-SNAPSHOT.jar <markdown file path> --title <The blog's title> --canonicalUrl <original blog link> --series <series> --sites <sites you wanted to publish to, DEVTO and MEDIUM> --tags <tags> --imageUrl <cover image url> --subtitle <The blog's subtitle>
Parameter Name | Data Type | Description |
markdown file path | string | required, markdown file path |
title | string | required, the blog's title |
series | string | required, the series, which you would like to put your blog to |
sites | string | required, the sites (DEVTO, MEDIUM), which you would like put your blog to, separated by "," |
canonicalUrl | string | optional, the original link of the blog (if exists) |
tags | string | optional, tags, separated by "," |
imageUrl | string | optional, cover image URL |
subtitle | string | optional, the blog's subtitle |
Remark:
- All the parameter value is RECOMMENDED to be surrounded by
"
2.2.1. Example
java -jar publisher-0.0.1-SNAPSHOT.jar "C:\Git\...\sample.md" --title "Sample Title" --canonicalUrl https://ivanyu2021.hashnode.dev/correct-steps-to-setup-basic-environment-for-python --series "Python" --sites "DEVTO,MEDIUM" --tags "Python,Other" --imageUrl "https://ivanyu2021.hashnode.dev/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1626249332587%2FK6qFAif_l.png%3Fw%3D1600%26h%3D840%26fit%3Dcrop%26crop%3Dentropy%26auto%3Dcompress%2Cformat%26format%3Dwebp&w=1920&q=75" --subtitle "Sample Subtitle"
Result
DEV Community
Medium
2.3. Log
The program's log is printed in cmd windows or can be found under log
folder, which will be created after execution once.
2.4. Next Post
Here are all the things about using this program. 👏
The next post will explain in detail about:
Project Setup
Detail Configuration
Compare different methods of importing a markdown file to the blog sites, DEV Community & Medium and the reason we used API
Way to enhance functionality of the program
Please see: