leidawt / blog_transformer

Tool for markdown blog migrate

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

blog_transformer

Tool for markdown blog migrate

Description

This tool do the things below:

  1. Input a markdown file, download all pictures from "![](https://xxx.xxx\)", saved as {%d}.xxx
  2. Modify the "![](https://xxx.xxx\)" to the request form(for example, {{<figure src = "{0}" title = "" lightbox = "true">}} which is required by Hugo)

For example:

Input markdown:

Output markdown:

In the same time, 0.png is downloaded into the path where Input markdown file exist.

Install

git clone this repo, add envionment variables(optional)

Usage

Use blog_transformer

python3 blog_transformer.py -f YorMarkdown.md

if envionment variables is set, the script can be run anywhere:

blog_transformer.py -f YorMarkdown.md

Or use it by import to python

from blog_transformer import BlogTransformer
bt = BlogTransformer()
md = bt.run(YOUR_FILE_NAME, save_path=YOUR_DIR, save=True)

Use pipeline

Pipeline tool based on blog_transformer, it is a tool for blog building with specified header templete (here "templete.md" is used), the header help blog generator like hugo to generate html correctly.

just run

python3 pipeline.py -f YorMarkdown.md -t YourTime

Then, a new floder which use the same name as "YorMarkdown.md" will be created and pics in "YorMarkdown.md" will be downloaded into it. "YorMarkdown.md" will be modified using the templete and finally saved as index.md. "YourTime" is the time when "YorMarkdown.md" is writed, YourTime should use YYYY-MM-DD format.

About

Tool for markdown blog migrate

License:MIT License


Languages

Language:Python 100.0%