如何把Issue博客自动同步到github page中

本文介绍如何配置GitHub Actions,以便在创建或编辑Issue时,自动将Issue内容同步到GitHub项目的blog分支,转化为Markdown文件并更新GitHub Page。通过设定工作流程,将Issue的标题、日期、内容等信息整合到新的Markdown文件,并触发网站更新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这个问题我问了chatgpt:

问题1

生成一段github的workflows配置文档,当有新issue的时候,自动将issue的内容同步到该GitHub项目的blog分支的content/post文件夹中的新Markdown文件中。文件名为"{YYYYMMDD}-{Title}.md",其中{YYYYMMDD}为issue的日期,"{Title}"为issue的标题。文件开头加上

---
title: 
data: 
lastmod:
draft: false
tags:
---

它给我回复了一个GitHub Workflows 配置文档

name: Sync Issue to Blog

on:
  issues:
    types: [opened, edited]

jobs:
  sync-issue-to-blog:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout Code
        uses: actions/checkout@v2

      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v2
        with:
          hugo-version: "latest"

      - name: Create Blog Post
        id: create_post
        run: |
          issue_title=$(echo "${
   
   { github.event.issue.title }}" | sed 's/[[:space:]]/-/g')
          issue_date=$(echo "${
   
   { github.event.issue.created_at }}" | cut -c1-10 | sed 's/-//g')
          post_path="content/post/${issue_date}-${issue_title}.md"
          post_date=$(echo "${
   
   { github.event.issue.created_at }}" | cut -c1-10)
          post_title=$(echo "${
   
   { github.event.issue.title }}" | sed 's/"/\\"/g')
          post_body=$(echo "${
   
   { github.event.issue.body }}" | sed 's/"/\\"/g')
          echo "---" > "${post_path}"
          echo "title: \"${post_title}\"" >> "${post_path}"
          echo "date: \"${post_date}\"" >> "${post_path}"
          echo "lastmod: \"${post_date}\"" >> "${post_path}"
          echo "draft: false" >> "${post_path}"
          echo "tags:" >> "${post_path}"
          echo "---" >> "${post_path}"
          echo "${post_body}" >> "${post_path}"

      - name: Commit and Push Changes
        run
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

M2kar

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值