huangwb8 / m2w

Automatically upload and update local markdown to WordPress via Python
https://pypi.org/project/m2w/
MIT License
42 stars 14 forks source link
markdown python vscode wordpress

English | 简体中文

m2w: Markdown to WordPress

Automatically upload and update local markdown to WordPress based on REST API/Password via Python

:star2::star2::star2: Welcome m2w 2.5!

Chinese tutorial: Docker系列 WordPress系列 WordPress上传或更新Markdown的最佳实践-m2w 2.0

Table of Contents

Background

m2w is a tool for automatically uploading or updating local Markdown to WordPress via Python, based on REST API (2.5+) or Password.

m2w has these features:

Install

Miniconda is recommended to manage Python version and related dependencies.

Here is the dependency:

# Python version
python_requires='>=3.7.6'

# Dependencies
install_requires=[
    "python-frontmatter>=1.0.0",
    "markdown>=3.3.6",
    "python-wordpress-xmlrpc>=2.3",
    "httpx>=0.24.0"
]

After 2022-12-10, m2w was uploaded onto PyPi. To install m2w, just run this code in your shell/conda environment:

pip install m2w

You can also directly download m2w from this repotory. The usage is exactly the same.

You can specify version or resource when installing m2w:

pip install -i https://pypi.org/simple m2w==2.5.13

Generally, the latest version of m2w is recommended.

Usage

Enable REST API

This step is needed only when you want to use the REST API mode.

WBrffVs5Ty

sq7kG7Vsqp

GddR0nP8mn

Use m2w

  1. Install m2w from PyPi or this Github repotory.
  2. Build a myblog.py file (or other names you like) in <path01>. Here is the demo. Create <path02>/config/user.json and set path_m2w as <path02> in myblog.py:
path_m2w = '<path02>' # Absolute path of m2w config folder
  1. Define <path02>/config/user.json. You can add many websites like web01! Please go to the demo for more details. Here are some interpretations:
    • user.json for REST API mode:
"web01": {
        "domain": "https://domain-01.com",
        "username": "username-01",
        "application_password": "password-01",
        "path_markdown": [
            "E:/Github/m2w/@test/main",
            "E:/Github/m2w/@test/main2"
        ],
        "post_metadata": {
            "category": ["test"],
            "tag": ["test"],
            "status": "publish"
        },
        "path_legacy_json": "/config/legacy"
    }
"web01": {
        "domain": "https://domain-01.com",
        "username": "username-01",
        "password": "password-01",
        "path_markdown": [
            "E:/Github/m2w/@test/main",
            "E:/Github/m2w/@test/main2"
        ],
        "post_metadata": {
            "category": ["test"],
            "tag": ["test"],
            "status": "publish"
        },
        "path_legacy_json": "/config/legacy"
    }
  1. Run myblog.py like:
python <path01>/myblog.py

Demo

This demo is conducted in Win10 with VScode.

As shown in the following GIF, all changed or brand-new markdowns can be automatically updated/upload via just a simple command python myblog.py!

image-20230609173358533

LOG

TO-DO

title: I Love You
tags:
  - You
  - I
  - Love
categories:
  - Note
date: 2023-11-08 16:38:31
update: 2023-11-08 16:40:31
--

Related Efforts

Maintainers

Contributing

Feel free to dive in! Open an issue or submit PRs. m2w follows the Contributor Covenant Code of Conduct.

License

This software depends on other packages that may be licensed under different open source licenses.

m2w is released under the MIT license. See LICENSE for details.

FOSSA Status

More

Applications similar to m2w