Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 17 additions & 48 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,72 +9,41 @@ permissions:
id-token: write
pages: write

env:
INSTANCE: 'Writerside/xd'
ARTIFACT: 'webHelpXD2-all.zip'
DOCKER_VERSION: '241.18775'

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Comment thread
PythonSmall-Q marked this conversation as resolved.
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Build docs using Writerside Docker builder
uses: JetBrains/writerside-github-action@v4
with:
instance: ${{ env.INSTANCE }}
artifact: ${{ env.ARTIFACT }}
docker-version: ${{ env.DOCKER_VERSION }}

- name: Save artifact with build results
uses: actions/upload-artifact@v4
with:
name: docs
path: |
artifacts/${{ env.ARTIFACT }}
artifacts/report.json
retention-days: 7
test:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
name: docs
path: artifacts
node-version: 20
cache: npm

- name: Test documentation
uses: JetBrains/writerside-checker-action@v1
with:
instance: ${{ env.INSTANCE }}
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
needs: [build, test]
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: docs
- name: Install dependencies
run: npm ci

- name: Unzip artifact
run: unzip -O UTF-8 -qq '${{ env.ARTIFACT }}' -d dir
- name: Build docs
run: npm run docs:build
Comment thread
PythonSmall-Q marked this conversation as resolved.

- name: Setup Pages
uses: actions/configure-pages@v4

- name: Package and upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: dir
path: .vitepress/dist

deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
needs: build
runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

29 changes: 29 additions & 0 deletions .github/workflows/preview-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: PR preview cleanup

on:
pull_request:
types: [closed]

permissions:
contents: read

jobs:
cleanup:
name: Delete FTP preview
runs-on: ubuntu-latest
steps:
- name: Install lftp
run: sudo apt-get install -y lftp
Comment thread
PythonSmall-Q marked this conversation as resolved.

- name: Remove preview directory from FTP
env:
FTP_USERNAME: ${{ secrets.FTP_USERNAME }}
FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
lftp -c "
set ftp:ssl-allow no;
Comment thread
PythonSmall-Q marked this conversation as resolved.
open -u $FTP_USERNAME,$FTP_PASSWORD ftpupload.net;
rm -rf pr-$PR_NUMBER/;
bye
"
83 changes: 83 additions & 0 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: PR preview

on:
pull_request:
types: [opened, synchronize, reopened]

permissions:
contents: read
pull-requests: write

jobs:
preview:
name: Build & deploy preview
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm

- name: Install dependencies
run: npm ci
Comment thread
PythonSmall-Q marked this conversation as resolved.

- name: Build docs
run: npm run docs:build

- name: Deploy to FTP
uses: SamKirkland/FTP-Deploy-Action@v4.3.5
with:
server: ftpupload.net
port: 21
username: ${{ secrets.FTP_USERNAME }}
password: ${{ secrets.FTP_PASSWORD }}
local-dir: .vitepress/dist/
Comment thread
PythonSmall-Q marked this conversation as resolved.
server-dir: pr-${{ github.event.pull_request.number }}/
Comment thread
PythonSmall-Q marked this conversation as resolved.
Outdated

- name: Comment on PR
uses: actions/github-script@v7
with:
script: |
const prNumber = context.payload.pull_request.number;
const previewUrl = `http://xmoj-docs.infinityfreeapp.com/pr-${prNumber}/`;
const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const body = [
'## 📖 文档预览',
'',
`构建成功!点击下方链接在线预览文档(PR 关闭后自动删除)。`,
'',
`**[🔗 在线预览](${previewUrl})**`,
'',
`> 预览地址:\`${previewUrl}\``,
`> 构建运行:[#${context.runNumber}](${runUrl})`,
].join('\n');

const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});

const botComment = comments.find(
c => c.user.type === 'Bot' && c.body.includes('## 📖 文档预览')
);
Comment thread
PythonSmall-Q marked this conversation as resolved.

if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Test build

on:
push:
branches-ignore:
- master
pull_request:

permissions:
contents: read

jobs:
build:
name: Build docs
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm

- name: Install dependencies
run: npm ci
Comment thread
PythonSmall-Q marked this conversation as resolved.

- name: Build docs
run: npm run docs:build
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.vitepress/dist
.vitepress/cache
150 changes: 150 additions & 0 deletions .vitepress/config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import { defineConfig } from 'vitepress'

export default defineConfig({
title: '小明的OJ增强脚本',
description: '小明的OJ增强脚本用户帮助文档',
lang: 'zh-CN',

head: [
['link', { rel: 'icon', href: '/logo.png' }],
],

themeConfig: {
logo: '/logo.png',

nav: [
{ text: '首页', link: '/' },
{ text: '安装指南', link: '/guide/installation' },
{
text: '功能介绍',
items: [
{ text: '功能总览', link: '/features/' },
{ text: '用户评分', link: '/features/rating' },
{ text: '图床', link: '/features/image-hosting' },
{ text: '获取测试点数据', link: '/features/get-data' },
{ text: '自动提交当年代码', link: '/features/auto-handin' },
],
},
{
text: '社区',
items: [
{ text: '徽章/Tag', link: '/community/badges' },
{ text: '贡献指南', link: '/community/contributing' },
],
},
{
text: '配套应用',
items: [
{ text: '短消息在线看', link: '/apps/messages' },
{ text: 'ELXMOJ 桌面客户端', link: '/apps/elxmoj' },
],
},
{
text: '更多',
items: [
{ text: '常见问题', link: '/qa/discussion' },
{ text: '用户协议', link: '/legal/eula' },
],
},
],

sidebar: [
{
text: '快速开始',
items: [
{ text: '安装指南', link: '/guide/installation' },
],
},
{
text: '功能介绍',
items: [
{ text: '功能总览', link: '/features/' },
{ text: '用户评分', link: '/features/rating' },
{ text: '图床', link: '/features/image-hosting' },
{ text: '获取测试点数据', link: '/features/get-data' },
{ text: '自动提交当年代码', link: '/features/auto-handin' },
],
},
{
text: '配套应用',
items: [
{ text: '短消息在线看', link: '/apps/messages' },
{ text: 'ELXMOJ 桌面客户端', link: '/apps/elxmoj' },
],
},
{
text: '社区',
items: [
{ text: '徽章/Tag', link: '/community/badges' },
{ text: '贡献指南', link: '/community/contributing' },
],
},
{
text: '更多',
items: [
{ text: '常见问题', link: '/qa/discussion' },
{ text: '用户协议', link: '/legal/eula' },
],
},
],

socialLinks: [
{ icon: 'github', link: 'https://github.com/XMOJ-Script-dev/XMOJ-Script' },
],

footer: {
message: '基于 GPLv3 许可证发布',
copyright: 'Copyright © XMOJ-Script-dev',
},

editLink: {
pattern: 'https://github.com/XMOJ-Script-dev/docs/edit/master/:path',
text: '在 GitHub 上编辑此页',
},

lastUpdated: {
text: '最后更新于',
},

docFooter: {
prev: '上一页',
next: '下一页',
},

outline: {
level: [2, 3],
label: '本页目录',
},

returnToTopLabel: '回到顶部',
sidebarMenuLabel: '菜单',
darkModeSwitchLabel: '主题',
lightModeSwitchTitle: '切换到浅色模式',
darkModeSwitchTitle: '切换到深色模式',

search: {
provider: 'local',
options: {
locales: {
root: {
translations: {
button: {
buttonText: '搜索文档',
buttonAriaLabel: '搜索文档',
},
modal: {
noResultsText: '无法找到相关结果',
resetButtonTitle: '清除查询条件',
footer: {
selectText: '选择',
navigateText: '切换',
closeText: '关闭',
},
},
},
},
},
},
},
},
})
4 changes: 4 additions & 0 deletions .vitepress/theme/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import DefaultTheme from 'vitepress/theme'
import './style.css'

export default DefaultTheme
Loading
Loading