#首先上自動化安裝命令:
#/home/wwwroot/newblog/application/api/controller/V2爲需要生成的文件的目錄需根據需求自己替換
#apiword.xxxx.com爲己經解析好的網站域名需根據需要自己替換
wget -P /root/apiword https://babyrita.oss-cn-beijing.aliyuncs.com/apiword/apiword.zip
&& cd apiword
&& unzip apiword.zip
&& chmod +x *.sh
&& ./shell.sh apiword.xxxx.com
&& ./autoApiWord.sh /home/wwwroot/newblog/application/api/controller/V2
資料如下圖所示:
#shell.sh
#把上面命令下載下來的文件根據需要進行處理
#!/bin/bash
mkdir -p /home/wwwroot/apiword
\cp index.php /home/wwwroot/apiword/index.php
\cp apiword.conf /usr/local/nginx/conf/vhost/apiword.conf
\cp jquery.js /home/wwwroot/apiword/jquery.js
\cp jquery.min.js /home/wwwroot/apiword/jquery.min.js
\cp model.html /home/wwwroot/apiword/model.html
sed -i "s/apiword.com/$(echo $1)/g" /usr/local/nginx/conf/vhost/apiword.conf
sed -i "s/apiword.com/$(echo $1)/g" /home/wwwroot/apiword/index.php
service nginx restart
#或者nginx -s reload 不影響正在運行的環境
chown -R www:www /home/wwwroot/apiword
#用軍哥lnmp自動安裝包就不用調整,主要代碼如下:
#/usr/local/nginx/conf/vhost/apiword.conf 代碼如下:
nginx配置文件模板
server
{
listen 80;
server_name apiword.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/apiword;
include enable-php-pathinfo.conf;
location /
{
if ( !-e $request_filename)
{
rewrite ^/(.*)$ /index.php?s=$1 last;
break;
}
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
}
#/home/wwwroot/apiword/index.php代碼如下:
#遍歷當前目錄並返回結果
<?php
function readDirs($path) {
$dir_handle = openDir($path);
while(false !== $file=readDir($dir_handle)) {
if ($file=='.' || $file=='..') continue;
//輸出該文件
if(is_file($file) && $file !== 'index.php' && $file !== 'jquery.js' && $file !== 'jquery.min.js'&& $file !== 'model.html'){
echo '<a href="http://apiword.com/'.$file.'">'.$file.'</a><br>';
}
}
closeDir($dir_handle);
}
$path = '/home/wwwroot/apiword';
readDirs($path);
?>
#/root/apiword/autoApiWord.sh代碼如下:
#本代碼目的爲根據自己定義的特殊字符(代碼註釋)來查找內容
#!/bin/bash
#根據獲取的$1路徑進入相應目錄
cd $1
#循環找出來的php文件
find -name "*.php" | while read i
do
#對查找出來的結果進行處理
file=${i##*/}
echo > ${file%.*}.html
#強制複製文件到當前目錄並命令
\cp /root/apiword/model.html ${file%.*}.html
#查找區間內容
sed -n '/++++++++++start++++++++++/,/++++++++++end++++++++++/'p $i >> linshi.html
#計算指定字符出來的行數
start=($(sed -n '/++++++++++start++++++++++/=' linshi.html))
end=($(sed -n '/++++++++++end++++++++++/=' linshi.html))
#雙重for循環
for((j=0;j<${#start[@]};j++))
do
a=${start[j]}
b=${end[j]}
echo "<div>" >> linshi2.html
sed -n "$a,$b p" linshi.html >> linshi2.html
echo "</div>" >> linshi2.html
done
#把linshi.html裏面的值加到${file%.*}的第30行開始
sed -i '30r linshi2.html' ${file%.*}.html
#清空文件
echo > linshi.html
echo > linshi2.html
#強制複製或者覆蓋到指定文件
\cp ${file%.*}.html /home/wwwroot/apiword/${file%.*}.html
done
#/home/wwwroot/model.html代碼如下:
#接口文檔頁html模板
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>api文檔頁面</title>
<style type="text/css">
*{margin:0;padding:0;}
div{
width:700px;
height:100%;
margin:100px auto;
font-size:1.3em;
line-height:200%;
background: black;
font-family:'微軟雅黑';
color:ghostwhite;
padding-left: 20px;
}
abbr{text-decoration:none;
color:#52f7f2;
}
p{line-height:70px;
font-size:14px;
}
img{margin:40px 0;}
h1{font-family:'楷體';}
</style>
</head>
<body style='background: #C0C0C0;'>
</body>
<script src="./jquery.min.js"></script>
<script src="./jquery.js"></script>
<script>
$("div").each(function (index, element) {
$(this).html($(this).text().replace(/\*/g, '<br>'));
})
</script>
</html>
#jquery.min.js與jquery.js這個就不用說了,懂代碼都明白!會用就好!
最終結果的根目錄如下圖:
點擊Login.html如下圖:(手機模式)pc端展示也不錯
#可配合在線視頻觀看:
#https://v.qq.com/x/page/u30701qqxbh.html
#有問題可以問我!
一行命令生成api接口文檔網站(一)