问题定位:
- novel.md 285KB 线上 Content-Type 被 nginx 默认识别为 application/octet-stream,gzip_types 无法命中,未压缩直传
- 用户网络慢时全本下载数秒甚至更久,一直'载入中 …'
- 附带问题:renderNovel 的 sections forEach idx 和 CHAPTERS 数组错位——'终章之后·当世界再次变聪明'这个非章节 ## heading 被 skip 掉后,之后所有第二部章节的 CHAPTERS[idx] 索引都偏移一位,映射到错误的章节图(不崩溃但显示错)
修复:
1. Dockerfile nginx conf 加 location = /novel.md 用 default_type 'text/markdown; charset=utf-8',覆盖默认 octet-stream,让 gzip_types 命中。gzip_comp_level 6 / gzip_min_length 512 / gzip_vary on。预计 285KB → ~90KB
2. renderNovel 里 ch 的解析从 CHAPTERS[idx] 改为 CHAPTERS.find(c => c.n === chN),按语义 n 精确匹配(主部 1-20 + 0 终章 / 第二部 -1 到 -8)。不再受 section 索引漂移影响
3. loadNovel 细化 loading 文案'正在下载全本 …' → '正在渲染章节 …';await setTimeout(0) 让浏览器先 paint;失败时补兜底直链'直接打开 novel.md'
4. imgPath 从 './images/${ch.img}' 加防守 (ch && ch.img),第二部 img=null 的章节不渲染 broken img src
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
42 lines
1.2 KiB
Docker
42 lines
1.2 KiB
Docker
FROM nginx:alpine
|
|
|
|
COPY . /usr/share/nginx/html/
|
|
|
|
RUN printf 'server {\n\
|
|
listen 80;\n\
|
|
server_name _;\n\
|
|
root /usr/share/nginx/html;\n\
|
|
index index.html;\n\
|
|
client_max_body_size 50M;\n\
|
|
\n\
|
|
# jpg / webp / png: long cache\n\
|
|
location ~* \\.(jpg|jpeg|png|webp|avif|svg|ico|woff2?)$ {\n\
|
|
expires 30d;\n\
|
|
add_header Cache-Control "public, max-age=2592000, immutable";\n\
|
|
access_log off;\n\
|
|
}\n\
|
|
\n\
|
|
# novel.md specifically — force text/markdown so gzip triggers\n\
|
|
location = /novel.md {\n\
|
|
default_type "text/markdown; charset=utf-8";\n\
|
|
add_header Cache-Control "public, max-age=0, must-revalidate";\n\
|
|
}\n\
|
|
\n\
|
|
# html / md catch-all: always revalidate\n\
|
|
location ~* \\.(html|md)$ {\n\
|
|
add_header Cache-Control "public, max-age=0, must-revalidate";\n\
|
|
}\n\
|
|
\n\
|
|
location / {\n\
|
|
try_files $uri $uri/ /index.html;\n\
|
|
}\n\
|
|
\n\
|
|
gzip on;\n\
|
|
gzip_comp_level 6;\n\
|
|
gzip_types text/plain text/markdown text/css application/javascript application/json image/svg+xml text/html;\n\
|
|
gzip_min_length 512;\n\
|
|
gzip_vary on;\n\
|
|
}\n' > /etc/nginx/conf.d/default.conf
|
|
|
|
EXPOSE 80
|