命令行创建和发布 MarkDown 到 WordPress

2019-05-13 17:21:57 +08:00
 skywind3000

全球有 10% 的网站是用 WordPress 搭建的,虽然有很多 Hugo/Hexo 这类静态页面生成工具,但是功能比起 WordPress 弱太多了。之前用 WordPress 唯一的不爽就是没法离线在编辑器里用 MarkDown 写文章,然后一键发布,所以我写了一个小工具:

https://github.com/skywind3000/markpress

是用很简单,先创建一个 ~/.config/markpress/config.ini 文件:

[default]
tabsize=4

[0]
url=http://your-wordpress.com/
user=USERNAME
passwd=PASSWORD

然后用 markpress 命令创建一篇新文章:

markpress -n mypost.md

markpress 会链接 wordpress 服务器,请求一个唯一的文章编号 uuid,并且为你生成文件头部内容,比如:

---
uuid: 1234
title:
status: draft
categories:
tags:
---

然后用你喜欢的编辑器编辑 mypost.md 文件,比如填充一些内容:

---
uuid: 1234
title: How to use asyncio in python ?
status: publish
categories: Development
tags: python, server
---
# Why you need asyncio ?

- reason 1
- reason 2
- reason 3

# Principle behind the asyncio

...

现在上面信息栏填写了标题,分类和标签,然后把 status 从 draft 改为 publish,然后填写 markdown 的正文,当您编辑好了以后,一行命令就可以更新到 wordpress:

markpress -u mypost.md

成功的话,你会看到输出:

post uuid=1234 updated: mypost.md
https://www.xxxx.com/blog/?p=1234

用最后一行的 url 就可以访问你的日志了。

那么 markpress + wordpress 写日志比 hugo/hexo 强在哪里呢?

漂亮的语法高亮:

使用 highlight.js 插件,支持 185 种语言的高亮,可以选择 89 种主题,是目前最强的代码高亮解决方案。

页面细节基本尊崇 Github 规范:

此外还有很多比 Github 规范强的功能:

支持内嵌公式:

被 $ 符号包围的文字会被按照 latex 公式解析,输入:

$z=\sqrt{x^2 + \sqrt{y^2}}$

得到:

支持内嵌 GraphViz 图表:

使用三个反引号和 ```viz-{引擎名称} 开头的代码块,能够被提前渲染成 SVG,并将 SVG 的 XML 内容直接嵌入到 Markdown 生成的 html 里面,无需额外保存图片,也没有中间文件,比如,Markdown 里面的代码块:

```viz-dot 
digraph G {
   A -> B
   B -> C
   B -> D
}
```

会被解析成 SVG 适量:

Viz 后面的 dot 对应的是 GraphViz 的 dot 引擎,还有其他好几个可用引擎,比如 circo:

```viz-circo
digraph st2 {
 rankdir=TB;
 node [fontname = "Verdana", fontsize = 10, color="skyblue", shape="record"];
 edge [fontname = "Verdana", fontsize = 10, color="crimson", style="solid"];
 st_hash_type [label="{<head>st_hash_type|(*compare)|(*hash)}"];
 st_table_entry [label="{<head>st_table_entry|hash|key|record|<next>next}"];
 st_table [label="{st_table|<type>type|num_bins|num_entries|<bins>bins}"];
 st_table:bins -> st_table_entry:head;
 st_table:type -> st_hash_type:head;
 st_table_entry:next -> st_table_entry:head [style="dashed", color="forestgreen"];
}
```

上面代码块使用了 circo 引擎,得到图形如下:

GraphViz 是非常流行的描述语言绘制矢量图的工具,它有很多例子:Gallery

实际效果演示见我的博客文章: ​ www.skywind.me

---

有了这个命令行工具,可以配置在 Vim/VSCode 里面,比如 vscode tasks.json 里面配置下 markpress,就可以在编辑 markdown 的时候按 CTRL+SHIFT+B 一键调用 markpress 发布到 wordpress 上了,十分顺手。

3445 次点击
所在节点    Linux
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/563730

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX