首先 fork 此项目https://github.com/wschenk/issue-blog,我fork
后的项目地址是https://github.com/briteming/wib
,然后访问https://github.com/briteming/wib/settings,勾选issues. 新建一些issues.
然后,访问https://github.com/briteming/wib/settings/pages。在Build and deployment处,source的值选择github actions. 在项目https://github.com/briteming/wib 页面的左上角的 main 处,创建gh-pages分支。稍等2分钟,即可打开https://briteming.github.io/wib/
编辑 _config.yml文件- https://github.com/briteming/wib/blob/main/_config.yml ,把第6行的baseurl的值改为 /wib 。
创建新 issue(标题必须为英文或其他基于26个字母的西方语言) 后,就会自动触发"Issue to Post" action (马上访问https://github.com/briteming/wib/actions/workflows/issue_to_post.yml,即可看到。),待"Issue to Post" action完成(即 issue的标题的前面出现
)后,就会自动触发Build and Deploy(马上访问https://github.com/briteming/wib/actions/workflows/deploy_to_pages.yml,即可看到),待"deploy" action完成(即 deploy的前面出现
)后,帖子就发表成功了。
演示网站:https://briteming.github.io/wib/
项目地址: https://github.com/wschenk/issue-blog
https://github.com/briteming/wib
虽然静态博客程序wib也是基于github actions,但生成的博客中的帖子还是按创建issue 的时间顺序排列的,难得!不像ib(https://briteming.blogspot.com/2025/02/github-issueib.html),
nb(https://briteming.blogspot.com/2025/02/github-issuenb.html)和静态博客程序 Issue_Blog 那样所生成的博客中的帖子是乱排列的。
------------------------------------------------------------------------------------------------
Building a blog using github issues
what else can we do with github actions
I wanted to see if I could write blog posts using github issues, and
have them be published on the web. You can!
cd $(mktemp -d)
bundle init
bundle add jekyll
bundle exec jekyll new issue-blog
cursor issue-blog
|
Then inside
bundle add jekyll-compose
bundle
jekyll s
|
git init
git add .
git commit -m "initial commit"
gh repo create wschenk/issue-blog --public
gh repo edit -d "Playground to make posts and comments from github issues"
git remote add origin https://github.com/wschenk/issue-blog
git push origin main
|
gh auth token | gh secret set AUTH_TOKEN
|
Issue to Post workflow
When you open or edit and issue, we check out the repo, and then
create a file in the _posts
directory can fill in the information
Once that's done, we trigger a deploy
action using
peter-evans/repository-dispatch
to trigger the second build action.
name: Issue to Post
on:
workflow_dispatch:
issues:
types:
- opened
- edited
permissions: write-all
jobs:
create_post:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Create post file
run: |
POST_FILENAME="_posts/$(date +%Y-%m-%d)-$(echo -n ${{github.event.issue.title}} | tr '[A-Z]' '[a-z]' | tr -c 'a-z' '-' ).md"
echo "POST_FILENAME: ${POST_FILENAME}"
echo --- > ${POST_FILENAME}
echo title: "${{github.event.issue.title}}" >> ${POST_FILENAME}
echo layout: post >> ${POST_FILENAME}
echo date: $(date +"%Y-%m-%d %H:%M %z") >> ${POST_FILENAME}
echo --- >> ${POST_FILENAME}
echo >> ${POST_FILENAME}
echo "${{github.event.issue.body}}" >> ${POST_FILENAME}
- name: Commit and push changes
run: |
git config --global user.email "readme-bot@example.com"
git config --global user.name "README-bot"
git add .
git commit -m "Create post for issue #${{ github.event.issue.number }}"
git push
env:
GITHUB_TOKEN: ${{ secrets.AUTH_TOKEN }}
- name: Trigger deploy action
uses: peter-evans/repository-dispatch@v3
with:
event-type: deploy
|
Deploy to pages
Here we check out the code and deploy it to github pages. We replace
the baseurl
with the base_path
that we get from configure-pages
, so
its smart enough to know if you have it on a custom domain or as a
subdirectory.
name: "Build and Deploy"
on:
repository_dispatch:
types: [deploy]
push:
branches:
- main
- master
paths-ignore:
- .gitignore
- README.md
- LICENSE
- .github/
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
# Allow one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Pages
id: pages
uses: actions/configure-pages@v4
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3
bundler-cache: true
- name: Replace baseurl
run: |
sed -i 's|baseurl: ""|baseurl: "${{ steps.pages.outputs.base_path }}"|' _config.yml
- name: Build site
run: bundle exec jekyll b -d "_site${{ steps.pages.outputs.base_path }}"
env:
JEKYLL_ENV: "production"
- name: Upload site artifact
uses: actions/upload-pages-artifact@v3
with:
path: "_site${{ steps.pages.outputs.base_path }}"
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
|
Check it out
You can see it in action:
from https://willschenk.com/howto/2024/building_a_blog_using_github_issues/
No comments:
Post a Comment