当前位置: 首页 > news >正文

搭建基于Gitee文档笔记自动发布

搭建基于Gitee文档笔记自动发布

由于现在gitee不支持代理静态页面,并且github.io需要VPN,实际使用的话gitee更为方便。

一、为服务器和个人PC添加免密push和pull

参考链接:https://help.gitee.com/base/account/SSH%E5%85%AC%E9%92%A5%E8%AE%BE%E7%BD%AE

二、创建webhooks

创建webhooks目的是用于监听gitee仓库的push事件,自动触发服务器端pull更新代码和文档笔记。
在这里插入图片描述

三、创建服务监听

1、创建监听脚本文件
vim gitee-hook.sh
#!/bin/bash#Git 仓库所在目录,即执行 git pull 的工作目录
WORK_DIR="/root/helloops/"
#日志文件路径,记录脚本执行过程和结果
LOG_FILE="/root/gitee-hooks/hook.log"#将带时间戳的日志信息追加到 LOG_FILE
#示例输出:[20250630-143000] Starting git pull...
log() {echo "[$(date '+%Y%m%d-%H:%M:%S')] $1" >> $LOG_FILE
}#切换到工作目录并执行 git pull,将执行过程逐行记录到日志
execute_git_pull() {log "start git pull..."cd $WORK_DIR || { log "not cd workdir"; exit 1; }/usr/bin/git pull 2>&1 | while read line; dolog "git pull: $line"donelog "git pull started..."
}#解析 Gitee Webhook 发送的 HTTP 请求,验证 Token 并执行更新
parse_request(){while read -r line; do#根据自己设置的密码进行更换if [[ $line == "X-Gitee-Token: 123456" ]]; then VALID_TOKEN=truefiif [ -z "$line" ]; thenbreakfidonebody=$(cat)log "input gitee hook requests,Body size: ${#body}"execute_git_pull
}parse_request
2、创建监听服务文件
sudo cat > /lib/systemd/system/gitee-hook.service << 'EOF'
[Unit]
Description=Gitee Webhook Listener
After=network.target[Service]
Type=simple
ExecStart=/usr/bin/socat TCP-LISTEN:8080,fork EXEC:"/root/gitee-hook.sh"
WorkingDirectory=/root/gitee-hooks
User=root
Group=root
Restart=on-failure
RestartSec=5s
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=gitee-hook[Install]
WantedBy=multi-user.target
EOF#创建日志存储目录并授权脚本
sudo mkdir -p /root/gitee-hooks
sudo chmod +x /root/gitee-hook.sh#检查 socat 是否安装
which socat || sudo apt-get install socat -y  # Debian/Ubuntu
which socat || sudo yum install socat -y       # CentOS/RHEL#重载 systemd 配置并启动
sudo systemctl daemon-reload
sudo systemctl start gitee-hook#设置开机启动并查看状态
sudo systemctl enable gitee-hook
sudo systemctl status gitee-hook

四、测试操作

1、安装pandoc
apt -y install pandoc
2、整个流程操作
pandoc sources/md/KL-Ubuntu/搭建基于Gitee文档笔记自动发布.md -s -o html/KL-Ubuntu/搭建基于Gitee文档笔记 自动发布.htmlgit add . git status git commit -m "add **"git push

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

五、Nginx配置参考以及目录结构参考

server {charset utf-8;server_name abc.cn www.abc.cn;client_max_body_size 1024m;gzip on;location / {alias /root/helloops/html/; autoindex on;}location /yaml {alias /root/helloops/yaml/;autoindex on;}location /windos {alias /root/helloops/sources/windos/;autoindex on;auth_basic "Restricted Access";auth_basic_user_file /etc/nginx/.htpasswd;add_header Cache-Control "no-cache, no-store, must-revalidate";add_header Pragma "no-cache";add_header Expires 0;}location /sources/images {alias /root/helloops/sources/images/;autoindex on;}listen 443 ssl; # managed by Certbotssl_certificate /etc/letsencrypt/live/helloops.cn/fullchain.pem; # managed by Certbotssl_certificate_key /etc/letsencrypt/live/helloops.cn/privkey.pem; # managed by Certbotinclude /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbotssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
} 
server {if ($host = www.helloops.cn) {return 301 https://$host$request_uri;} # managed by Certbotif ($host = helloops.cn) {return 301 https://$host$request_uri;} # managed by Certbotlisten 80;server_name abc.cn www.abc.cn;}

目录结构

root@helloops# tree -d
.
├── html
│   ├── k8s
│   └── KL-Ubuntu
├── sources
│   ├── images
│   ├── md
│   │   ├── k8s
│   │   └── KL-Ubuntu
│   └── windos
└── yaml10 directories
http://www.dtcms.com/a/282924.html

相关文章:

  • 达梦数据库配置兼容MySQL
  • Vue + Element UI 实现单选框
  • [特殊字符] 第1篇:什么是SQL?数据库是啥?我能吃吗?
  • LeafletJS 进阶:GeoJSON 与动态数据可视化
  • UI测试平台TestComplete:关键字驱动测试技巧
  • 【ArcGISPro】修改conda虚拟安装包路径
  • Mybatis的SQL编写—XML方式
  • 无人机EIS增稳技术要点分析
  • 牛客:HJ26 字符串排序[华为机考][map]
  • web:js提示框、询问框、输入框的使用
  • React 条件渲染完全指南
  • 题解:P13256 [GCJ 2014 #2] Data Packing
  • 新版本Cursor中配置自定义MCP服务器教程,附MCP工具开发实战源码
  • 棱镜观察|比亚迪“全责兜底”智能泊车!“减配”风潮接踵而至
  • realsense应用--rs-distance(距离测量)
  • 中国旅行社协会在京召开“文旅人工智能应用研讨会”,助力文旅创新发展
  • 分块(chunked) vs 滑动窗口(windowed)
  • 【25-cv-07929】Keith携Lisa Audit向日葵画作发案
  • 性能测试过程中监控linux服务器资源情况
  • c语言常用的字符串函数简介概括
  • 【基于飞浆训练车牌识别模型】
  • 2.库操作
  • cookie和session、favicon.ico
  • 管家婆辉煌ERP登录报错:HTTP 错误 404.2
  • 嵌入式下快速傅里叶变换(FFT)C语言库kissfft
  • 图机器学习(9)——图正则化算法
  • 2. nth-child 和 nth-of-type 区别
  • xss-labs通关
  • k8s之持久化存储流程
  • 小架构step系列16:代码文档