前提
阅读本文之前,需要已经正常搭建好 hexo 博客和语雀账号。同时我们需要准备:
-
一个 GitHub 账号
-
一个腾讯云账号
-
hexo 安装了 yuque-hexo 插件且能正常运行
实现思路:
利用语雀的webhook
触发腾讯云云函数
,云函数触发GitHub Action
,Github Action 执行 hexo 的一系列命令从而实现自动同步。具体步骤详见:https://yichen115.github.io/2020/07/16/gtb5ck/
注意
-
云函数是有免费额度的,正常使用不会超出。
-
日志服务是收费的,建议调试成功后删除日志资源。具体位置:点开具体函数后,在函数管理 > 函数配置的日志配置下,有日志集和日志主题,建议都删除掉。
2022 年 5 月 19 日更新:腾讯云函数要收费了,故将云函数迁移到私人云服务器上,下面附上 php 版云函数代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| <?php
function http_post_json($url, $jsonStr) { $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'User-Agent:curl/7.51.1', 'Accept:application/vnd.github.everest-preview+json', 'Authorization:token 填自己的', 'Content-Type: application/json;' ) ); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch);
return array($httpCode, $response); }
$url = "https://api.github.com/repos/填自己的仓库"; $jsonStr = json_encode(array("event_type"=> "run-it")); list($returnCode, $returnContent) = http_post_json($url, $jsonStr);
echo("ok");
?>
|