powershell-將org文件通過命令行轉成html

腳本要求

  1. 將已存在的org轉成html
  2. 把html復制到nginx的代理目錄形成可查看的鏈接
  3. 把nginx的鏈接和最新的git提交信息發(fā)送給釘釘通知群

腳本內容

#!/bin/bash
ls -l target
datetime=`date +'%%Y%%m%%d%%H%%M%%S'`
reportname=batch-api-test-rpt-$datetime.zip
emacs -batch -l  ~/.emacs.d/elpa-29.2/htmlize-20210825.2150/htmlize.el target/Batch測試報告.org -f org-html-export-to-html --kill

# 切換到目標目錄
cd target || { echo "Directory not found: chutian-front/target"; exit 1; }

# zip -r $reportname *
mv Batch測試報告.html index.html
report_link="http://192.168.0.134:8110/batch/api/$datetime/index.html"

html_head='
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Batch-API測試報告</title>
<meta name="author" content="青島紅創(chuàng)-Batch" />
<meta name="generator" content="Org Mode" />
<link rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" />
<script src="https://hcapplet.3vyd.com/org-theme/src/lib/js/jquery.min.js"></script>
<script src="https://hcapplet.3vyd.com/org-theme/src/lib/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://hcapplet.3vyd.com/org-theme/src/lib/js/jquery.stickytableheaders.min.js"></script>
<script type="text/javascript" src="https://hcapplet.3vyd.com/org-theme/src/readtheorg_theme/js/readtheorg.js"></script>
</head>
'

# 將新文本寫入臨時文件
echo "$html_head" > temp_file.html

# 將原文件內容追加到臨時文件后
cat index.html >> temp_file.html

# 用臨時文件替換原文件
mv temp_file.html index.html

mkdir -p /Users/a123/Downloads/test-report/batch/api/$datetime
cp -r * /Users/a123/Downloads/test-report/batch/api/$datetime/

# 定義文件路徑
file_path="ding-msg.edn"

# 讀取文件內容并去掉首尾的雙引號
file_content=$(sed 's/^"\(.*\)"$/\1/' "$file_path")

# 拼接字符串
combined_content="${file_content}\n [點擊鏈接查看報告詳情](${report_link})"

# 打印拼接后的內容
echo -e "$combined_content"


# 發(fā)送消息到DingTalk
curl --location 'https://oapi.dingtalk.com/robot/send?access_token=43d9635c7a20220071dbf0cfee918f1baddaf08039719bd14190b9db0996450f' \
--header 'Content-Type: application/json' \
--data "{
    \"msgtype\": \"markdown\",
    \"at\": {\"isAtAll\": true},
    \"markdown\": {\"title\": \"楚天Batch API測試報告\",
                   \"text\": \"## 楚天Batch(API單元測試結果) \n ${combined_content}  \"}
}"

說明

  1. 通過emacs的org轉html要安裝emacs的插件,htmlize
  2. git的msg不是這個腳本獲取的,而是其他地方獲取后放在ding-msg.edn中的
  3. 效果截圖


    image.png
?著作權歸作者所有,轉載或內容合作請聯系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容