diff --git a/.github/workflows/deploy-website.yml b/.github/workflows/deploy-website.yml new file mode 100644 index 000000000..b4f05fd01 --- /dev/null +++ b/.github/workflows/deploy-website.yml @@ -0,0 +1,44 @@ +name: Deploy website + +on: + push: + branches: [main] + paths: + - 'packages/website/**' + - '.github/workflows/deploy-website.yml' + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: github-pages + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: oven-sh/setup-bun@v2 + - run: bun install --frozen-lockfile + - name: Build + run: | + cd packages/website + bun run check + bun run build + - uses: actions/upload-pages-artifact@v3 + with: + path: packages/website/dist + + deploy: + needs: build + runs-on: ubuntu-latest + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - id: deployment + uses: actions/deploy-pages@v4 diff --git a/packages/website/astro.config.mjs b/packages/website/astro.config.mjs index 6732d866f..1c57e8587 100644 --- a/packages/website/astro.config.mjs +++ b/packages/website/astro.config.mjs @@ -3,6 +3,9 @@ import { defineConfig } from 'astro/config'; import tailwindcss from '@tailwindcss/vite'; export default defineConfig({ + // GitHub Pages 项目页:https://cavinhuang.github.io/lume/ ;换自定义域名时清掉 base 即可 + site: 'https://cavinhuang.github.io', + base: '/lume', // 中文为默认语言(无前缀),英文挂 /en/ 前缀 i18n: { defaultLocale: 'zh', diff --git a/packages/website/src/components/Footer.astro b/packages/website/src/components/Footer.astro index e4f4ce7cc..26a0bc6a8 100644 --- a/packages/website/src/components/Footer.astro +++ b/packages/website/src/components/Footer.astro @@ -1,5 +1,5 @@ --- -import { REPO_URL } from '../lib/site'; +import { REPO_URL, withBase } from '../lib/site'; import { t, type Lang } from '../i18n/ui'; interface Props { @@ -7,11 +7,11 @@ interface Props { } const { lang } = Astro.props; -const base = Astro.url.pathname.startsWith('/en') ? '/en' : ''; +const langPrefix = lang === 'zh' ? '' : '/en'; const product = [ - { href: `${base}/download`, label: t(lang, 'nav.download') }, - { href: `${base}/docs`, label: t(lang, 'nav.docs') }, - { href: `${base}/changelog`, label: t(lang, 'nav.changelog') }, + { href: withBase(`${langPrefix}/download`), label: t(lang, 'nav.download') }, + { href: withBase(`${langPrefix}/docs`), label: t(lang, 'nav.docs') }, + { href: withBase(`${langPrefix}/changelog`), label: t(lang, 'nav.changelog') }, ]; --- @@ -19,7 +19,7 @@ const product = [
- Lume + Lume Lume

diff --git a/packages/website/src/components/LangSwitch.astro b/packages/website/src/components/LangSwitch.astro index 19523a907..898264400 100644 --- a/packages/website/src/components/LangSwitch.astro +++ b/packages/website/src/components/LangSwitch.astro @@ -1,14 +1,15 @@ --- import { counterpartPath, getLangFromUrl, languages, t } from '../i18n/ui'; +import { stripBase, withBase } from '../lib/site'; const lang = getLangFromUrl(Astro.url); -const target = counterpartPath(Astro.url.pathname); -// 链接文案是「你要切过去的语言」 const other = lang === 'zh' ? 'en' : 'zh'; + +// 链接文案是「你要切过去的语言」 ---