類似gitbook的wiki選擇

eyunshu發表於2018-09-06

一直以來,都使用xwiki作為團隊內部的文件管理工具,但一直想換一個比較輕量級的系統。團隊成員普遍對gitbook風格有好感,於是先後試用了mdwiki、dokuwiki、hexo、mindoc、wikitten。

mdwiki:純粹用AJAX寫的,部署最簡單,但是目錄只能兩級;

dokuwiki:PHP寫的,沒有資料庫,有不少外掛。一直在這個和wikitten中猶豫,最後還是選擇了wikitten,主要還是介面風格,wikitten比較簡潔;

hexo:採用node.js開發的,也是因為這個才知道wikitten。因為伺服器上已經有PHP的環境了,不想再增加node.js,所以放棄了,否則是很好的選擇;

mindoc:golang開發的,這個其實也不錯,但我只要一本書,他卻提供了一個書櫃;

wikitten:PHP寫的,沒有資料庫,沒有外掛,文件也少。但介面一眼看中了,就這樣了。

到github下載,解壓。網上說PHP需要fileinfo元件,其實還需要json元件,這個需要注意了。由於我使用nginx,並且沒法安裝到站點根目錄下,所以一直有問題。

location ~* ^/static/(css|js|img|fonts)/.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt|swf|pdf|txt|bmp|eot|svg|ttf|woff|woff2)$ {
    access_log off;
    expires max;
}
location /wiki/ {
    rewrite ^(.*)$ /wiki/index.php last;
}

主要是location /wiki/ 這段,如果沒有,頁面解析正常,但左側tree的連結不正常,因為偽靜態的原因,可以理解。但如果加上這一段,則頁面解析不正常了,主要是static這個目錄訪問不到了。對PHP不怎麼熟悉,並且還可以用php -S 0.0.0.0:8000 route.php執行,在nginx裡配置一個proxy_pass就好,所以也就懶得折騰了,用這種方式來做吧。

補記:

經過除錯比對apache下的配置,發現問題出在apache有這麼一句:

RewriteCond %{THE_REQUEST} !^GET /.*?static/(css|js|img)

經過在https://segmentfault.com/q/1010000014633581討教,終於知道了原因:

!^GET /.*?static/(css|js|img)表示排除/static/(css|js|img)這些路徑的請求
nginx沒有對應的排除的方法
可以用變通的方法
先給location /一個try_files,然後優先匹配/static/(css|js|img),匹配到的不配置try_files

location / {
    try_files $uri $uri/ /index.php;
}

location ~* ^/.*static/(css|js|img)/ {
    expires 1d;
}

參考以上的內容修改

 location / {
            root   /usr/local/www/nginx;
            index  index.html index.htm index.php;
            # Wikitten
            try_files $uri $uri/ /wiki/index.php;
        }


location ~* ^/static/(css|js|img|fonts)/.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt|swf|pdf|txt|bmp|eot|svg|ttf|woff|woff2)$ {
    access_log off;
    expires max;
}

完美的解決了問題。

其它注意要點:

如果APP_NAME要用中文,那麼config.php一定要轉成UTF8儲存,否則沒法正常顯示。

<?php
// Example configuration file for Wikitten. To use it,
// first rename it to `config.php`.

// Custom name for your wiki:
define(`APP_NAME`, `這裡用中文`);

// Set the filename of the automatic homepage here
define(`DEFAULT_FILE`, `index.md`);

// Custom path to your wiki`s library:
// define(`LIBRARY`, `/path/to/wiki/library`);

// Enable editing files through the interface?
// NOTE: There`s currently no authentication built into Wikitten, controlling
// who does what is your responsibility.
// define(`ENABLE_EDITING`, true);

// Enable JSON page data?
// define(`USE_PAGE_METADATA`, true);

// Enable the dark theme here
// define(`USE_DARK_THEME`, true);

// Disable the Wikitten logo here
define(`USE_WIKITTEN_LOGO`, false);

// Enable PasteBin plugin ?
// define(`ENABLE_PASTEBIN`, true);
// define(`PASTEBIN_API_KEY`, ``);

 


相關文章