更新 Dockerfile 和 docker-entrypoint.sh,動態替換 index.html 的標題與 favicon,改善社群爬蟲抓取效果
This commit is contained in:
parent
30a632fd0c
commit
d0a9aec12a
@ -33,8 +33,8 @@ COPY --from=builder /app/dist /usr/share/nginx/html
|
||||
# 暴露 Nginx 預設的 80 端口
|
||||
EXPOSE 80
|
||||
|
||||
# 2025-08-20
|
||||
LABEL changelog="2025-08-20: 動態設定網頁標題與 favicon與logo與預設build_img,標題由 VITE_APP_TITLE 環境變數控制,favicon、logo、build_img.jpg 由 VITE_FILE_API_BASEURL 動態插入,docker-entrypoint.sh 寫入 env.js 供前端讀取。"
|
||||
# 2025-08-21
|
||||
LABEL changelog="2025-08-21: index.html 的 <title> 及 favicon 由 docker-entrypoint.sh 啟動時根據環境變數直接替換,社群爬蟲可正確抓取,env.js 仍供前端 JS 讀取其他動態參數。"
|
||||
|
||||
# Nginx 已經預設啟動,所以不需要 CMD 指令
|
||||
COPY docker-entrypoint.sh /docker-entrypoint.sh
|
||||
|
@ -1,3 +1,5 @@
|
||||
#!/bin/sh
|
||||
echo "window.env = { VITE_API_BASEURL: '${VITE_API_BASEURL}', VITE_FILE_API_BASEURL: '${VITE_FILE_API_BASEURL}', VITE_MQTT_BASEURL: '${VITE_MQTT_BASEURL}', VITE_APP_TITLE: '${VITE_APP_TITLE}' };" > /usr/share/nginx/html/env.js
|
||||
sed -i "s|<title>.*</title>|<title>${VITE_APP_TITLE}</title>|g" /usr/share/nginx/html/index.html
|
||||
sed -i "s|<link rel=\"icon\" href=\".*\"|<link rel=\"icon\" href=\"${VITE_FILE_API_BASEURL}/upload/favicon.ico\"|g" /usr/share/nginx/html/index.html
|
||||
exec "$@"
|
14
index.html
14
index.html
@ -11,19 +11,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Cvilux EMS</title>
|
||||
<script src="/env.js"></script>
|
||||
<script>
|
||||
// 動態設定 favicon
|
||||
if (window.env && window.env.VITE_FILE_API_BASEURL) {
|
||||
var link = document.createElement("link");
|
||||
link.rel = "icon";
|
||||
link.href = window.env.VITE_FILE_API_BASEURL + "/upload/favicon.ico";
|
||||
document.head.appendChild(link);
|
||||
}
|
||||
// 動態設定網頁標題
|
||||
if (window.env && window.env.VITE_APP_TITLE) {
|
||||
document.title = window.env.VITE_APP_TITLE;
|
||||
}
|
||||
</script>
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.7.1.js"></script>
|
||||
<script src="https://code.jquery.com/ui/1.13.3/jquery-ui.js"></script>
|
||||
<!-- <script type="text/javascript" src="/requirejs/config.js"></script> -->
|
||||
|
Loading…
Reference in New Issue
Block a user