2018-04-27

Apache Rivet and mod_actions

mod_actions


雖然 mod_actions 的文件是寫 CGI script,但是你可以使用 Apache Rivet, PHP 或者是類似的工具來撰寫。

下面是測試用的程式,用來將 markdown 檔案 (*.md) 轉換為 HTML 格式以後輸出:
package require Markdown

::rivet::load_env

if {[info exists ::request::env(PATH_TRANSLATED)]==0} {
    ::rivet::headers numeric 400
    return
}

if {[file exists $::request::env(PATH_TRANSLATED)]==0} {
    ::rivet::headers numeric 404
    return
}

set in [open $::request::env(PATH_TRANSLATED)]
set md [read $in]
close $in
set data [::Markdown::convert $md]

::rivet::headers type "text/html;charset=utf-8"
puts $data

再來加上設定(我加在 VirtualHost configure file):
Action markdown /mdhandler.tcl
AddHandler markdown .md

最後重開 Apache HTTP server 然後進行測試。我把程式放在 Github 上。

沒有留言: