-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
2,394 additions
and
1,187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
name: 部署 (预览环境) 后处理 | ||
|
||
on: | ||
workflow_run: | ||
workflows: | ||
- 部署预览 | ||
types: | ||
- completed | ||
|
||
env: | ||
PR_NUM: 0 | ||
|
||
jobs: | ||
on-success: | ||
name: 推送到 Netlify | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pull-requests: write | ||
if: ${{ github.event.workflow_run.conclusion == 'success' }} | ||
steps: | ||
- name: 下载工作流信息 | ||
uses: dawidd6/action-download-artifact@v6 | ||
with: | ||
workflow_conclusion: success | ||
run_id: ${{ github.event.workflow_run.id }} | ||
name: pr-num | ||
path: pr-num | ||
allow_forks: true | ||
|
||
- name: 获取 PR 编号 | ||
id: pr-num | ||
run: | | ||
echo "PR_NUM=$(cat pr-num/pr_num)" >> $GITHUB_ENV | ||
- name: 下载构建内容 | ||
uses: dawidd6/action-download-artifact@v6 | ||
with: | ||
workflow_conclusion: success | ||
run_id: ${{ github.event.workflow_run.id }} | ||
name: build-result | ||
allow_forks: true | ||
path: dist | ||
|
||
- name: 推送到 Netlify | ||
id: netlify | ||
uses: nwtgck/actions-netlify@v3.0 | ||
with: | ||
publish-dir: "dist" | ||
deploy-message: "Deploy from GitHub Actions" | ||
production-deploy: false | ||
alias: deploy-preview-${{ env.PR_NUM }} | ||
enable-commit-comment: false | ||
enable-pull-request-comment: false | ||
enable-commit-status: false | ||
enable-github-deployment: false | ||
env: | ||
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | ||
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} | ||
timeout-minutes: 1 | ||
|
||
- name: 查找评论 ID | ||
uses: peter-evans/find-comment@v3 | ||
id: fc | ||
with: | ||
issue-number: ${{ env.PR_NUM }} | ||
comment-author: "github-actions[bot]" | ||
body-includes: <!-- auto message --> | ||
|
||
- name: 创建或更新评论 | ||
uses: peter-evans/create-or-update-comment@v4 | ||
with: | ||
comment-id: ${{ steps.fc.outputs.comment-id }} | ||
issue-number: ${{ env.PR_NUM }} | ||
body: | | ||
## ✅ 成功部署预览! | ||
| 类型 | 链接 | | ||
|:-----------:|:----------------------------------------------------------------------------------------------------:| | ||
| 预览地址 | ${{ steps.netlify.outputs.deploy-url }} | | ||
| 最新提交 | ${{ github.sha }} | | ||
| 部署日志 | [${{ github.event.workflow_run.name }} #${{ github.event.workflow_run.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}) | | ||
<!-- auto message --> | ||
edit-mode: replace | ||
|
||
on-failure: | ||
name: 提示构建预览失败 | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pull-requests: write | ||
if: ${{ github.event.workflow_run.conclusion == 'failure' }} | ||
steps: | ||
- name: 下载构建内容 (工作流信息) | ||
uses: dawidd6/action-download-artifact@v6 | ||
with: | ||
workflow_conclusion: success | ||
run_id: ${{ github.event.workflow_run.id }} | ||
name: pr-num | ||
path: pr-num | ||
allow_forks: true | ||
|
||
- name: 获取 PR 编号 | ||
id: pr-num | ||
run: | | ||
echo "PR_NUM=$(cat pr-num/pr_num)" >> $GITHUB_ENV | ||
- name: 查找评论 ID | ||
uses: peter-evans/find-comment@v3 | ||
id: fc | ||
with: | ||
issue-number: ${{ env.PR_NUM }} | ||
comment-author: "github-actions[bot]" | ||
body-includes: <!-- auto message --> | ||
|
||
- name: 创建或更新评论:失败 | ||
uses: peter-evans/create-or-update-comment@v4 | ||
with: | ||
comment-id: ${{ steps.fc.outputs.comment-id }} | ||
issue-number: ${{ env.PR_NUM }} | ||
body: | | ||
## ❌ 部署预览失败 | ||
| 类型 | 链接 | | ||
|:-----------:|:----------------------------------------------------------------------------------------------------:| | ||
| 预览地址 | 部署失败,请查看工作流运行日志。 | | ||
| 最新提交 | ${{ github.sha }} | | ||
| 部署日志 | [${{ github.event.workflow_run.name }} #${{ github.event.workflow_run.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}) | | ||
<!-- auto message --> | ||
edit-mode: replace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Git Submodule | ||
src/wiki | ||
src/styles/detail | ||
# src/plugins/backend | ||
|
||
# Auto generated files | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import type { Plugin } from "vite"; | ||
|
||
export function MarkdownTransform(): Plugin { | ||
return { | ||
name: "zotero-chinese-md-transform", | ||
enforce: "pre", | ||
async transform(code, id) { | ||
if (!id.match(/\.md\b/)) return null; | ||
|
||
// convert links to relative | ||
code = code.replaceAll( | ||
/https?:\/\/zotero-chinese\.com\/user-guide\//g, | ||
"/user-guide/", | ||
); | ||
|
||
// CSL 样式部分 | ||
if (id.match(/styles\/detail\/.*\.md/)) { | ||
// 为详情页增加 md 前言 | ||
code = | ||
`--- | ||
sidebar: false | ||
comments: false | ||
--- | ||
` + code; | ||
|
||
// CSL 详情页的头部块 | ||
code = code.replace( | ||
"<!-- PLACEHOLDER FOR WEBSITE - BEFORE FILE -->", | ||
`<StyleDetailCard />`, | ||
); | ||
|
||
// CSL 详情页的折叠块 | ||
code = code | ||
.replaceAll( | ||
"<!-- PLACEHOLDER FOR WEBSITE - BEFORE RESULT -->", | ||
"::: details\n\n", | ||
) | ||
.replaceAll( | ||
"<!-- PLACEHOLDER FOR WEBSITE - AFTER RESULT -->", | ||
":::\n\n", | ||
); | ||
} | ||
|
||
return code; | ||
}, | ||
}; | ||
} | ||
|
||
function replaceAsync( | ||
str: string, | ||
match: RegExp, | ||
replacer: (substring: string, ...args: any[]) => Promise<string>, | ||
) { | ||
const promises: Promise<string>[] = []; | ||
str.replace(match, (...args) => { | ||
promises.push(replacer(...args)); | ||
return ""; | ||
}); | ||
return Promise.all(promises).then((replacements) => | ||
str.replace(match, () => replacements.shift()!), | ||
); | ||
} |
Oops, something went wrong.