Skip to content

Commit

Permalink
Update Vitepress config to add search functionality for multiple lang…
Browse files Browse the repository at this point in the history
…uages
  • Loading branch information
Leetfs committed Sep 7, 2024
1 parent 3d348f1 commit a3e3640
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 20 deletions.
42 changes: 22 additions & 20 deletions .github/workflows/cf.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
name: 部署到 Cloudflare Pages
name: 部署到Cloudflare Pages

# 当推送到 main 分支时触发
on:
push:
branches:
- 'main'
- 'main' # 监听 main 分支的推送

jobs:
deploy:
runs-on: ubuntu-latest
build:
runs-on: ubuntu-22.04 # 选择 Ubuntu 22.04 作为运行环境

steps:
# 第一步:检出代码
- name: 检出代码
uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0 # 完整检出代码历史

# 第二步:安装 pnpm
- name: 安装 pnpm
uses: pnpm/action-setup@v3
- uses: pnpm/action-setup@v3
with:
version: latest # 安装最新版本的 pnpm

# 第三步:安装依赖
# 第三步:设置 Node.js 环境并启用 pnpm 缓存
- uses: actions/setup-node@v4
with:
cache: pnpm # 启用 pnpm 缓存,加快依赖安装速度

# 第四步:安装依赖
- name: 安装依赖
run: pnpm install # 使用 pnpm 安装依赖

# 第四步:构建项目
# 第五步:构建项目
- name: 构建项目
run: pnpm run docs:build # 构建 VitePress 项目

# 第五步:检查构建输出目录
- name: 检查构建输出
run: ls -alh docs/.vitepress/dist # 列出构建后的文件,确保生成正确
run: pnpm build # 构建 VitePress 文档
env:
NODE_OPTIONS: --max_old_space_size=4096 # 增加 Node.js 内存限制

# 第六步:发布到 Cloudflare Pages
- name: 发布到 Cloudflare Pages
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_PAGES_TOKEN }} # Cloudflare Pages API Token
accountId: ${{ secrets.CLOUDFLARE_PAGES_ACCOUNT }} # Cloudflare 账户 ID
projectName: study-wiki # 替换为你的 Cloudflare Pages 项目名称
directory: docs/.vitepress/dist # 确保这是构建后的输出目录
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} # 在 GitHub Secrets 中配置你的 Cloudflare API Token
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} # 在 GitHub Secrets 中配置你的 Cloudflare Account ID
projectName: study-wiki # Cloudflare Pages 项目名称
directory: docs/.vitepress/dist # 替换为 VitePress 构建输出的目录
74 changes: 74 additions & 0 deletions docs/.vitepress/config/shared.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { defineConfig } from 'vitepress'
import { search as zhSearch } from './zh'


export const shared = defineConfig({
title: 'VitePress',

rewrites: {
'en/:rest*': ':rest*'
},

lastUpdated: true,
cleanUrls: true,
metaChunk: true,

markdown: {
math: true,
codeTransformers: [
// We use `[!!code` in demo to prevent transformation, here we revert it back.
{
postprocess(code) {
return code.replace(/\[\!\!code/g, '[!code')
}
}
]
},

sitemap: {
hostname: 'https://vitepress.dev',
transformItems(items) {
return items.filter((item) => !item.url.includes('migration'))
}
},

/* prettier-ignore */
head: [
['link', { rel: 'icon', type: 'image/svg+xml', href: '/vitepress-logo-mini.svg' }],
['link', { rel: 'icon', type: 'image/png', href: '/vitepress-logo-mini.png' }],
['meta', { name: 'theme-color', content: '#5f67ee' }],
['meta', { property: 'og:type', content: 'website' }],
['meta', { property: 'og:locale', content: 'en' }],
['meta', { property: 'og:title', content: 'VitePress | Vite & Vue Powered Static Site Generator' }],
['meta', { property: 'og:site_name', content: 'VitePress' }],
['meta', { property: 'og:image', content: 'https://vitepress.dev/vitepress-og.jpg' }],
['meta', { property: 'og:url', content: 'https://vitepress.dev/' }],
['script', { src: 'https://cdn.usefathom.com/script.js', 'data-site': 'AZBRSFGG', 'data-spa': 'auto', defer: '' }]
],

themeConfig: {
logo: { src: '/vitepress-logo-mini.svg', width: 24, height: 24 },

socialLinks: [
{ icon: 'github', link: 'https://github.com/vuejs/vitepress' }
],

search: {
provider: 'algolia',
options: {
appId: '8J64VVRP8K',
apiKey: 'a18e2f4cc5665f6602c5631fd868adfd',
indexName: 'vitepress',
locales: {
...zhSearch,
...ptSearch,
...ruSearch,
...esSearch,
...koSearch
}
}
},

carbonAds: { code: 'CEBDT27Y', placement: 'vuejsorg' }
}
})

0 comments on commit a3e3640

Please sign in to comment.