写在前面
这是一篇有关如何使用 Logseq 将笔记和博客融合在一起的文章,笔记保持私有,博客保持公开。所有的笔记均保存在 Github 上,并通过 Github Action 来关联博客部署。
整体思路如下:
- 所有笔记保存在 Github 私有仓库,并通过
public属性设置可以公开的页面; - 通过 workflow 进行编译和 deploy 成静态 HTML,并存入到公开仓库中;
- 通过 Vercel 自动部署博客,并可添加域名;
配置流程
设置最小可访问 private repo 的 Github Token:
- Github 点击个人头像:
Setting -> Developer Settings -> Personal access tokens -> Tokens -> Generate new tokenExpiration选择无期限设置,Select scopes勾选第一个 repo 即可; - 复制生成的
Token,并配置到保存笔记的 private repo 设置:Settings -> Secrets and variables -> Actions -> New repository secret
配置 Token:name=ACCESS_TOKEN, value=xxxx - 在本地的笔记库中创建
.github/workflows目录,并添加publish.yml文件,内容如下:
name: CI
on:
push:
branches: [main] #要生成的logseq库分支名称
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-latest
name: Publish Logseq graph
steps:
- uses: actions/checkout@v3
- name: Logseq Publish 🚩
uses: logseq/publish-spa@v0.2.0 #生成html文件,并push到gh-pages分支
with:
theme-mode: dark
- name: add a nojekyll file #标记为非jekyll
run: touch $GITHUB_WORKSPACE/www/.nojekyll
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4
with:
repository-name: orangestara/logseq_publish # 公开的仓库地址
branch: main # The branch the action should deploy to.
folder: www # The folder the action should deploy. 临时目录名称
clean: true #始终覆盖更新
single-commit: true
trace: false
token: ${{ secrets.ACCESS_TOKEN }}新公共仓库默认没有工作流权限:
Settings --> Actions --> General,然后在工作流权限中,选择Read and write permissions
由于我设置了 Git 自动同步 Logseq 笔记,每次 push 都触发博客部署将太频繁。因此将触发动作设定为定时触发:
on:
schedule:
- cron: '0 */6 * * *' # 每 6 小时触发
env:
TZ: 'Asia/Shanghai'配置 publish 范围,修改 config.edn:
;; 如果想要全部公开,就设置为 true,否则就单文章进行 public 属性设置
:publishing/all-pages-public? false
:default-home {:page "README" :sidebar ["contents"]}部署到 Vercel
个人博客:https://www.ai4me.pro
