Skip to content

Commit cb15590

Browse files
Oliver0804claude
andcommitted
feat: add Google Analytics, 民眾之窗 link, embed-basic plugin with custom modifications
- Add Google Analytics tracking (G-NRX9V3TDXX) to both SSR and CSR pages - Add 民眾之窗 link to footer in both React components and Go templates - Remove X-Frame-Options headers to allow iframe embedding - Integrate embed-basic plugin using ANSWER_MODULE approach - Document plugin integration solution in PLUGIN_INTEGRATION_SOLUTION.md - Update plugin list to only include embed-basic - Compile cross-platform Linux binary for cloud deployment 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 9fdeca6 commit cb15590

File tree

312 files changed

+513619
-86
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

312 files changed

+513619
-86
lines changed

Dockerfile.official

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
FROM apache/answer as answer-builder
2+
3+
FROM golang:1.23-alpine AS golang-builder
4+
5+
COPY --from=answer-builder /usr/bin/answer /usr/bin/answer
6+
7+
RUN apk --no-cache add \
8+
build-base git bash nodejs npm go && \
9+
npm install -g [email protected]
10+
11+
RUN answer build \
12+
--with github.com/apache/answer-plugins/connector-basic \
13+
--with github.com/apache/answer-plugins/storage-s3 \
14+
--with github.com/apache/answer-plugins/search-elasticsearch \
15+
--with github.com/apache/answer-plugins/embed-basic \
16+
--output /usr/bin/new_answer
17+
18+
FROM alpine
19+
LABEL maintainer="[email protected]"
20+
21+
ARG TIMEZONE
22+
ENV TIMEZONE=${TIMEZONE:-"Asia/Shanghai"}
23+
24+
RUN apk update \
25+
&& apk --no-cache add \
26+
bash \
27+
ca-certificates \
28+
curl \
29+
dumb-init \
30+
gettext \
31+
openssh \
32+
sqlite \
33+
gnupg \
34+
tzdata \
35+
&& ln -sf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime \
36+
&& echo "${TIMEZONE}" > /etc/timezone
37+
38+
COPY --from=golang-builder /usr/bin/new_answer /usr/bin/answer
39+
COPY --from=answer-builder /data /data
40+
COPY --from=answer-builder /entrypoint.sh /entrypoint.sh
41+
RUN chmod 755 /entrypoint.sh
42+
43+
VOLUME /data
44+
EXPOSE 80
45+
ENTRYPOINT ["/entrypoint.sh"]

PLUGIN_INTEGRATION_SOLUTION.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Answer 插件整合解決方案
2+
3+
## 問題描述
4+
5+
使用 Answer 官方的 `build --with` 命令添加插件時,會從官方代碼庫重新構建,導致自定義修改(Google Analytics、民眾之窗連結、X-Frame-Options 移除)丟失。
6+
7+
## 解決方案
8+
9+
使用 `ANSWER_MODULE` 環境變量指定本地已修改的源碼作為基礎來構建插件版本。
10+
11+
### 步驟
12+
13+
1. 確保本地源碼包含所有自定義修改
14+
2. 使用以下命令構建插件版本:
15+
16+
```bash
17+
ANSWER_MODULE=$(pwd) ./answer build --with github.com/apache/answer-plugins/embed-basic@latest --output ./answer-final-complete
18+
```
19+
20+
### 關鍵要點
21+
22+
- `ANSWER_MODULE=$(pwd)` 告訴 Answer build 命令使用當前目錄(包含我們修改的源碼)作為基礎
23+
- 構建過程會自動執行 `go mod edit -replace github.com/apache/answer=/path/to/local/source`
24+
- 這樣既保留了自定義修改,又成功集成了官方插件
25+
26+
### 驗證方法
27+
28+
1. 檢查插件是否成功集成:
29+
```bash
30+
./answer-final-complete plugin
31+
```
32+
33+
2. 啟動服務測試:
34+
```bash
35+
./answer-final-complete run -C ./data/
36+
```
37+
38+
3. 檢查網頁是否包含:
39+
- Google Analytics 代碼 (G-NRX9V3TDXX)
40+
- 民眾之窗連結
41+
- embed-basic 插件功能
42+
- 可嵌入 iframe(X-Frame-Options 已移除)
43+
44+
## 自定義修改內容
45+
46+
### 1. Google Analytics 集成
47+
- 檔案:`ui/template/header.html``ui/public/index.html`
48+
- 追蹤代碼:G-NRX9V3TDXX
49+
50+
### 2. 民眾之窗連結
51+
- 檔案:`ui/src/components/Footer/index.tsx``ui/template/footer.html`
52+
- 連結:https://flash.justice-tw.org/grassway
53+
54+
### 3. 移除 X-Frame-Options
55+
- 檔案:
56+
- `internal/router/ui.go:134`
57+
- `internal/controller/template_controller.go:626`
58+
- `internal/base/middleware/auth.go:216`
59+
60+
### 4. 插件集成
61+
- embed-basic@latest(支援多種嵌入格式:YouTube、Twitter、GitHub Gist 等)
62+
63+
## 雲端部署編譯
64+
65+
對於雲端部署(Ubuntu 22.04.5 LTS),使用以下命令進行交叉編譯:
66+
67+
```bash
68+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 ANSWER_MODULE=$(pwd) ./answer build --with github.com/apache/answer-plugins/embed-basic@latest --output ./answer-linux-final
69+
```
70+
71+
## 構建成功確認
72+
73+
執行以下命令確認構建成功:
74+
- `./answer-final-complete plugin` - 確認插件已集成
75+
- 啟動服務後檢查網頁源碼包含 Google Analytics
76+
- 檢查頁腳是否有民眾之窗連結
77+
- 測試是否可嵌入 iframe
78+
79+
## 注意事項
80+
81+
1. 必須在包含自定義修改的源碼目錄中執行構建命令
82+
2. `ANSWER_MODULE` 環境變量必須指向當前修改的源碼路徑
83+
3. 構建過程會創建臨時目錄,完成後自動清理
84+
4. 此方法適用於所有官方插件的集成
85+
86+
日期:2025-08-02

0 commit comments

Comments
 (0)