Skip to content

Commit 8ff644b

Browse files
committed
fix: stabilize audio, GH Pages preview, and build workflow
1 parent 26be166 commit 8ff644b

File tree

12 files changed

+237
-145
lines changed

12 files changed

+237
-145
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
node_modules
22
dist
3+
gh-pages-preview
34
.expo
45
.git
56
.github

.github/workflows/build-apk.yml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,22 @@ jobs:
4343
id: build
4444
run: |
4545
echo "::group::Starting EAS Build"
46-
BUILD_JSON=$(eas build --platform android --profile preview --non-interactive --json 2>&1) || {
46+
# 运行 eas build,将 stderr 重定向到文件以便调试
47+
eas build --platform android --profile preview --non-interactive --json > build_output.json 2> build_stderr.txt || {
4748
echo "::error::EAS build command failed"
48-
echo "$BUILD_JSON"
49+
cat build_stderr.txt
50+
cat build_output.json
4951
exit 1
5052
}
51-
echo "$BUILD_JSON"
52-
BUILD_ID=$(echo "$BUILD_JSON" | jq -r '.[0].id // empty')
53+
54+
# 显示输出用于调试
55+
echo "Build stderr:"
56+
cat build_stderr.txt || true
57+
echo "Build output:"
58+
cat build_output.json
59+
60+
# 解析 JSON 获取 build ID
61+
BUILD_ID=$(jq -r '.[0].id // empty' build_output.json)
5362
if [ -z "$BUILD_ID" ]; then
5463
echo "::error::Failed to extract build ID from response"
5564
exit 1
@@ -86,7 +95,7 @@ jobs:
8695
continue
8796
fi
8897
89-
STATUS=$(echo "$BUILD_INFO" | jq -r '.status // "unknown"')
98+
STATUS=$(echo "$BUILD_INFO" | jq -r '.status // "unknown"' | tr '[:upper:]' '[:lower:]')
9099
echo "Current status: $STATUS"
91100
92101
case "$STATUS" in
@@ -128,7 +137,7 @@ jobs:
128137
else
129138
VERSION="dev-$(date +%Y%m%d-%H%M%S)"
130139
fi
131-
FILENAME="gojuon-${VERSION}.apk"
140+
FILENAME="gojuon-${VERSION}-universal.apk"
132141
echo "filename=$FILENAME" >> $GITHUB_OUTPUT
133142
echo "APK will be saved as: $FILENAME"
134143

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ node_modules/
55
.expo/
66
dist/
77
web-build/
8+
gh-pages-preview/
89

910
# Native builds
1011
android/

App.tsx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import Constants from 'expo-constants';
1010
import { audioService } from './src/utils/audio';
1111

1212
// 获取 baseUrl(用于 GitHub Pages 等子路径部署)
13-
const baseUrl = Constants.expoConfig?.web?.baseUrl || '';
13+
const rawBaseUrl = Constants.expoConfig?.web?.baseUrl || '';
14+
const normalizedBaseUrl = rawBaseUrl.endsWith('/') ? rawBaseUrl.slice(0, -1) : rawBaseUrl;
15+
const baseUrl = resolveBaseUrl();
1416

1517
import { StudyProvider } from './src/contexts/StudyContext';
1618
import { ThemeProvider, useTheme } from './src/contexts/ThemeContext';
@@ -39,7 +41,7 @@ type RootStackParamList = {
3941

4042
// Linking configuration with proper typing
4143
const linking: LinkingOptions<RootStackParamList> = {
42-
prefixes: [baseUrl],
44+
prefixes: baseUrl ? [baseUrl] : [],
4345
config: {
4446
screens: {
4547
Main: {
@@ -56,12 +58,26 @@ const linking: LinkingOptions<RootStackParamList> = {
5658
},
5759
};
5860

59-
// Tab 图标配置
61+
function resolveBaseUrl(): string {
62+
if (Platform.OS !== 'web') return '';
63+
if (!normalizedBaseUrl) return '';
64+
if (typeof window === 'undefined') return normalizedBaseUrl;
65+
66+
const path = window.location.pathname || '';
67+
if (path === normalizedBaseUrl || path.startsWith(`${normalizedBaseUrl}/`)) {
68+
return normalizedBaseUrl;
69+
}
70+
71+
// 当部署在根路径时,不应用 baseUrl
72+
return '';
73+
}
74+
75+
// Tab 图标配置 - 使用日语汉字
6076
const TAB_CONFIG: Record<string, { icon: string }> = {
61-
Home: { icon: '' },
62-
Browse: { icon: '' },
63-
Stats: { icon: '' },
64-
Settings: { icon: '' },
77+
Home: { icon: '' }, // 学習 - 学习
78+
Browse: { icon: '' }, // 五十音表 - 图表
79+
Stats: { icon: '' }, // 成績 - 成绩
80+
Settings: { icon: '' }, // 設定 - 设置
6581
};
6682

6783
// 自定义浮动 TabBar 组件

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ docker-compose up -d
4949
- **导航**:React Navigation (stack + bottom-tabs)
5050
- **状态管理**:React Context API
5151
- **存储**:AsyncStorage 本地存储
52-
- **音频**:expo-av (本地 MP3) + expo-speech (TTS 备用)
52+
- **音频**:expo-av (104个预生成 MP3 文件)
5353
- **构建**:EAS Build (Android) / GitHub Actions (Web + Docker)
5454

5555
## 开发指南
@@ -95,6 +95,22 @@ eas build --platform android --profile preview
9595
npx expo export --platform web
9696
```
9797

98+
### 本地预览 GH Pages 路径
99+
100+
Expo 导出的 `index.html` 默认使用根路径(例如 `/_expo/...`),而 GitHub Pages 部署在 `/<repo>` 子路径下。
101+
为了避免本地预览 404,使用下面的脚本会自动重写 `index.html` 的资源路径到 `/<repo>`
102+
103+
```bash
104+
# 生成 GH Pages 预览目录并修正资源路径
105+
npm run preview:gh-pages
106+
107+
# 启动本地静态服务器(任选其一)
108+
py -m http.server 4175 --directory gh-pages-preview --bind 127.0.0.1
109+
# 或 npx serve gh-pages-preview
110+
```
111+
112+
打开 `http://127.0.0.1:4175/gojuon/` 查看效果。
113+
98114
## 项目结构
99115

100116
```
@@ -154,7 +170,6 @@ gojuon/
154170

155171
- 使用 Google Cloud TTS (Wavenet 日语女声) 预生成 104 个高质量发音文件
156172
- Web 端自动加载 MP3 文件,原生端使用预打包资源
157-
- 支持 TTS 实时合成作为备用方案
158173
- 播放速度 0.85x,发音更清晰
159174

160175
## 许可证

eas.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"cli": {
3-
"version": ">= 7.0.0"
3+
"version": ">= 7.0.0",
4+
"appVersionSource": "local"
45
},
56
"build": {
67
"development": {

package-lock.json

Lines changed: 3 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"start": "expo start",
77
"android": "expo start --android",
88
"ios": "expo start --ios",
9-
"web": "expo start --web"
9+
"web": "expo start --web",
10+
"export:web": "expo export --platform web",
11+
"preview:gh-pages": "npm run export:web && node scripts/gh-pages-preview.mjs"
1012
},
1113
"dependencies": {
1214
"@react-native-async-storage/async-storage": "^2.2.0",
@@ -21,7 +23,6 @@
2123
"expo-clipboard": "~8.0.8",
2224
"expo-linear-gradient": "^15.0.8",
2325
"expo-notifications": "~0.32.15",
24-
"expo-speech": "~14.0.8",
2526
"expo-status-bar": "~3.0.9",
2627
"react": "19.1.0",
2728
"react-dom": "19.1.0",

0 commit comments

Comments
 (0)