Publish a local markdown file to sites at once by Java, Usage

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

·

3 min read

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

GITHUB_TOKEN=<enter your github token here>
DEV_TO_TOKEN=<enter your dev to api key here>
MEDIUM_TOKEN=<enter your medium token here>

You can see find the guide after expanding the following:

image.png

  • Install Java 17 on your PC (place java in environment variable)

If you install it correctly, you should see the following:

image.png

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 NameData TypeDescription
markdown file pathstringrequired, markdown file path
titlestringrequired, the blog's title
seriesstringrequired, the series, which you would like to put your blog to
sitesstringrequired, the sites (DEVTO, MEDIUM), which you would like put your blog to, separated by ","
canonicalUrlstringoptional, the original link of the blog (if exists)
tagsstringoptional, tags, separated by ","
imageUrlstringoptional, cover image URL
subtitlestringoptional, 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

image.png

DEV Community

image.png

Medium

image.png

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.

image.png

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:

Did you find this article valuable?

Support Ivan Yu by becoming a sponsor. Any amount is appreciated!