Skip to content

Commit 9502f2c

Browse files
committed
pages测试
1 parent 66b8b31 commit 9502f2c

4 files changed

Lines changed: 16 additions & 8 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ jobs:
2929
run: npm ci
3030
- name: Build
3131
run: npm run build
32+
env:
33+
GITHUB_PAGES: true
3234
- name: Upload artifact
3335
uses: actions/upload-pages-artifact@v3
3436
with:

app/page.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,12 @@ const RandomNamePickerContent = () => {
9090
);
9191

9292
const handleShareList = () => {
93-
// 自动检测当前URL的路径前缀,兼容不同部署环境
94-
const url = `${window.location.origin}${window.location.pathname.split('/').slice(0, -1).join('/')}/?list=${encodeURIComponent(names.join(','))}`;
93+
// 检测是否在 GitHub Pages 环境
94+
const isGitHubPages = window.location.hostname.includes('github.io');
95+
// 根据环境生成基础路径
96+
const basePath = isGitHubPages ? '/RandomChoice.NextJS' : '';
97+
// 生成完整的分享链接
98+
const url = `${window.location.origin}${basePath}/?list=${encodeURIComponent(names.join(','))}`;
9599
navigator.clipboard.writeText(url);
96100
alert('分享链接已复制到剪贴板!');
97101
};

next.config.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ const withPWA = require('next-pwa')({
44
skipWaiting: true,
55
});
66

7-
// 简化配置,针对 Netlify 部署环境
8-
const config = {
7+
// 设置 GitHub Pages 的基础路径
8+
const basePath = '/RandomChoice.NextJS';
9+
10+
module.exports = withPWA({
911
reactStrictMode: true,
1012
output: 'export',
1113
distDir: 'out',
1214
trailingSlash: true, // 有助于静态部署
13-
};
14-
15-
module.exports = withPWA(config);
15+
basePath: basePath,
16+
assetPrefix: basePath,
17+
});

public/sw.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)