openresty 直接解析markdown文件

原理

  1. 通过 openresty 的 body_filter 对 markdown 文件进行“包装”,添加html的外衣;

  2. marked.js 前端解析markdown为html格式。

使用方法

  1. 克隆或下载源码;

  2. enable-markdown.conf, rewrite/markdown.conf 文件放至openrestyconf目录,一般默认为/usr/local/openresty/nginx/conf

  3. 在自己的nginx.conf 或者 vhost 中加入如下代码:

server
    {
        listen 8003;
        listen [::]:8003;
        server_name default;
        index index.md home.md main.md;
        root  /path/to/your/markdown/files; #修改为自己的makdown文件夹路径
        
        include enable-markdown.conf;   # 为markdown文件加html壳
        include rewrite/markdown.conf;  # rewrite
    }
  1. openresty -s reload

  2. 浏览器打开 http://[::]:8090/your-markdown.mdhttp://127.0.0.1:8090/your-markdown.md 访问。

源码:github.com/mrasong/openresty-markdown

添加新评论