Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CI

on:
push:
pull_request:

permissions:
contents: read

jobs:
verify:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22.x
cache: npm

- name: Install dependencies
run: npm ci

- name: Install Playwright browser
run: npx playwright install --with-deps chromium

- name: Verify project
run: npm run verify
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

# test output
test-results/
playwright-report/
blob-report/

# environment variables
.env
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ npm run build
npm run preview
```

## 质量检查

首次运行端到端测试前安装 Playwright 浏览器:

```bash
npx playwright install chromium
```

```bash
npm run check
npm test
npm run verify
```

- `npm run check`:执行 Astro 与 TypeScript 检查
- `npm test`:构建站点并运行移动端、桌面端 Playwright 测试
- `npm run verify`:依次执行类型检查、端到端测试和依赖安全审计

## 项目结构

```text
Expand All @@ -49,6 +67,7 @@ src/
components/ 可复用组件
layouts/ 页面布局
pages/ 路由页面与文章内容
tests/ Playwright 端到端测试
public/ 静态资源
```

Expand Down
29 changes: 24 additions & 5 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import sitemap from '@astrojs/sitemap';

const postsLayout = '../../layouts/PostsLayout.astro';

/** @param {unknown} value */
function stringifyDateValue(value) {
if (value instanceof Date) {
return value.toISOString().slice(0, 10);
Expand All @@ -16,8 +17,26 @@ function stringifyDateValue(value) {
return value;
}

/** @param {unknown} node */
function containsMath(node) {
if (!node || typeof node !== 'object') {
return false;
}

if ('type' in node && (node.type === 'code' || node.type === 'inlineCode')) {
return false;
}

if ('type' in node && node.type === 'text' && 'value' in node && typeof node.value === 'string') {
return /\$\$[\s\S]*?\$\$/.test(node.value) || /(?<!\\)\$[^$\n]+(?<!\\)\$/.test(node.value);
}

return 'children' in node && Array.isArray(node.children) && node.children.some(containsMath);
}

/** @type {import('@astrojs/markdown-remark').RemarkPlugin} */
function autoPostsLayout() {
return function (_, file) {
return function (tree, file) {
const path = String(file.path ?? '');
if (!path.includes('/src/pages/posts/') && !path.includes('\\src\\pages\\posts\\')) {
return;
Expand All @@ -26,10 +45,7 @@ function autoPostsLayout() {
file.data.astro ??= {};
file.data.astro.frontmatter ??= {};
file.data.astro.frontmatter.layout ??= postsLayout;

const raw = String(file.value ?? '');
file.data.astro.frontmatter.math =
/\$\$[\s\S]*?\$\$/.test(raw) || /(?<!\\)\$[^$\n]+(?<!\\)\$/.test(raw);
file.data.astro.frontmatter.math ??= containsMath(tree);

for (const [key, value] of Object.entries(file.data.astro.frontmatter)) {
if (key === 'layout') {
Expand All @@ -48,6 +64,9 @@ export default defineConfig({
plugins: [tailwindcss()]
},
markdown: {
shikiConfig: {
theme: 'github-dark-high-contrast',
},
processor: unified({
remarkPlugins: [remarkBreaks, autoPostsLayout],
}),
Expand Down
Loading
Loading