Skip to content

Commit

Permalink
Merge branch 'main' into feat/rss
Browse files Browse the repository at this point in the history
  • Loading branch information
northword committed Jun 20, 2024
2 parents 29f6ce9 + 0188449 commit 561408b
Show file tree
Hide file tree
Showing 46 changed files with 2,394 additions and 1,187 deletions.
2 changes: 1 addition & 1 deletion .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:recommended",
"schedule:weekly",
"schedule:monthly",
"group:allNonMajor",
":prHourlyLimitNone",
":prConcurrentLimitNone"
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/fetch-data.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const data_list = [

const tasks = data_list.map(async (d) => {
const data = await (await fetch(d.remote_url)).json();
fs.writeJSONSync(path.resolve(d.local_path), data);
fs.outputJSONSync(path.resolve(d.local_path), data);
console.log(`Download ${d.local_path} success!`);
});

Expand Down
104 changes: 10 additions & 94 deletions .github/workflows/ci-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,100 +13,16 @@ jobs:
name: 构建文档
uses: ./.github/workflows/build.yml

deploy:
name: 部署预览
needs:
- build
upload:
name: 上传运行信息
runs-on: ubuntu-latest
permissions:
pull-requests: write
if: github.repository == 'zotero-chinese/website' && github.event_name == 'pull_request'
steps:
- name: 下载构建内容
uses: actions/download-artifact@v4
- name: 保存 PR 编号
run: |
echo "${{ github.event.number }}" > pr_num
- name: 上传 PR 编号
uses: actions/upload-artifact@v4
with:
name: build-result
path: dist

# - name: 解压构建文件
# run: |
# tar -xvf dist.tar dist
# # ls -R -a

- 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-${{ github.event.number }}
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: 3

- name: 查找评论 ID
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.number }}
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: ${{ github.event.number }}
body: |
## ✅ 成功部署预览!
| 类型 | 链接 |
|:-----------:|:----------------------------------------------------------------------------------------------------:|
| 预览地址 | ${{ steps.netlify.outputs.deploy-url }} |
| 最新提交 | ${{ github.sha }} |
| 部署日志 | [${{ github.workflow }} #${{ github.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) |
<!-- auto message -->
edit-mode: replace

on-failure:
name: 提示部署结果
runs-on: ubuntu-latest
permissions:
pull-requests: write
needs:
- build
- deploy
if: ${{ failure() }}
steps:
- name: 查找评论 ID
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.number }}
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: ${{ github.event.number }}
body: |
## ❌ 部署预览失败
| 类型 | 链接 |
|:-----------:|:----------------------------------------------------------------------------------------------------:|
| 预览地址 | 部署失败,请查看工作流运行日志。 |
| 最新提交 | ${{ github.sha }} |
| 部署日志 | [${{ github.workflow }} #${{ github.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) |
<!-- auto message -->
edit-mode: replace
name: pr-num
path: ./pr_num
132 changes: 132 additions & 0 deletions .github/workflows/deploy-preview.yml
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
path = src/wiki
url = https://github.com/zotero-chinese/wiki.git
branch = main
[submodule "src/styles/detail"]
path = src/styles/detail
url = https://github.com/zotero-chinese/styles.git
1 change: 1 addition & 0 deletions .prettierignore
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
Expand Down
4 changes: 3 additions & 1 deletion .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { head } from "./config/head.config";
import vite from "./config/vite.config";

export default defineConfig({
title: `Zotero 中文社区`,
title: "Zotero 中文社区",
description: "Zotero 非官方中文维护小组",
lang: "zh-CN",

Expand All @@ -17,6 +17,7 @@ export default defineConfig({

rewrites: {
"wiki/:id+": ":id+",
"styles/detail/src/:id+": "styles/:id+",
},
cleanUrls: true,

Expand Down Expand Up @@ -108,6 +109,7 @@ export default defineConfig({
// buildEnd,

vite,
metaChunk: true,

sitemap: {
hostname: "https://zotero-chinese.com",
Expand Down
3 changes: 3 additions & 0 deletions .vitepress/config/sidebar.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { sidebar as wikiSideBar } from "../../src/wiki/.vitepress/config/sidebar

export const sidebar: DefaultTheme.Sidebar = {
...wikiSideBar,
// "/styles/detail/": (() => {
// return [];
// })(),
"/": [
{ text: "关于我们", link: "/about" },
{ text: "贡献者名单", link: "/contributors" },
Expand Down
6 changes: 6 additions & 0 deletions .vitepress/config/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ import {
GitChangelog,
GitChangelogMarkdownSection,
} from "@nolebase/vitepress-plugin-git-changelog/vite";
import { MarkdownTransform } from ".vitepress/plugins/markdownTransform";

import { RssPlugin } from "vitepress-plugin-rss";

export default defineConfig({
define: {
// 启用生产环境构建下激活不匹配的详细警告
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: "true",
},
plugins: [
Inspect(),
VueDevTools(),
Expand All @@ -25,6 +30,7 @@ export default defineConfig({
Components({
resolvers: [ElementPlusResolver()],
}),
MarkdownTransform(),

RssPlugin({
title: "Zotero 中文社区",
Expand Down
62 changes: 62 additions & 0 deletions .vitepress/plugins/markdownTransform.ts
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()!),
);
}
Loading

0 comments on commit 561408b

Please sign in to comment.