Skip to content

Repository files navigation

c4Lab Website

c4Lab 實驗室網站,使用 Vite + React + TypeScript 建構的純靜態 SPA。

所有內容(成員、論文、部落格等)都寫在 TypeScript 資料檔裡,不需要資料庫或 CMS。 改完檔案、push 上來、server 上 rebuild 就會更新。

更新網站內容

流程

1. 編輯 src/data/mock/ 裡的資料檔
2. (選配)放圖片到 public/images/ 對應資料夾
3. git add / commit / push
4. 到 server 上執行:
git pull
docker compose up --build -d

我要改什麼,改哪個檔案?

我想要...編輯的檔案備註
新增論文publications.ts加到對應年份的 items,或新增一個年份 group
新增/畢業成員members.ts新增加到 memberRecords;畢業改 status: "alumni"yearLabel
更新教授資訊members.ts編輯 featuredMember
新增部落格文章卡片blog.ts加到 blogPosts,圖片放 public/images/blog/
新增首頁 timeline 事件home.ts加到 timelineEntries,圖片放 public/images/timeline/
新增首頁專案卡片home.ts加到 projectHighlights
改首頁介紹文字home.ts編輯 homeHero
改聯絡資訊/地址site.ts編輯 siteContact
改導覽列連結site.ts編輯 primaryNavutilityNav
改研究方向research.ts編輯或新增 researchTracks
改 Galaxy 說明galaxy.ts編輯 galaxySectionsgalaxySupport

所有資料檔都在 src/data/mock/ 目錄下。

圖片放哪裡?

圖片放在 public/images/,資料檔裡用 /images/... 路徑引用。

目錄用途命名慣例
public/images/全站共用hero-bg.png, prof-chen.png
public/images/blog/部落格封面圖blog-NN-描述.ext(如 blog-01-i2ai.webp
public/images/timeline/首頁 timeline 縮圖YYYY-描述.ext(如 2024-ai-multiomics.jpg

圖片不會自動壓縮或轉檔,放什麼就 serve 什麼。

常見範例

新增一篇 2026 年的論文

src/data/mock/publications.ts 找到(或新增)year "2026" 的 group,加一筆:

{id: "pub_077",year: "2026",dateLabel: "15 Mar 2026",title: "Your Paper Title",venue: "Nature Methods",authors: "Author A, Author B, Chien-Yu Chen*",href: "https://doi.org/10.xxxx/xxxxx"}

成員畢業

src/data/mock/members.ts 找到該成員,改兩個欄位:

status: "alumni",// 原本是 "current"yearLabel: "2022 - 2026"// 原本是 "2022 ~"

新增部落格卡片

  1. 把封面圖放到 public/images/blog/blog-18-topic.png
  2. src/data/mock/blog.tsblogPosts 陣列加一筆:
{id: "blog-18",title: "文章標題",author: "作者名",summary: "一兩句摘要...",imageUrl: "/images/blog/blog-18-topic.png",sourceHost: "Medium",href: "https://medium.com/...",ctaLabel: "Read on Medium"}

本地開發

環境需求

  • Node.js 22+
  • npm(隨 Node 附帶)

起手

git clone git@github.com:c4lab/c4lab-webiste-rebuild.git
cd c4lab-webiste-rebuild
npm install
npm run dev

Dev server 會跑在 http://localhost:5173,支援 hot reload——改任何 .ts/.tsx/.css 檔案都會即時反映在瀏覽器上,不需要手動重新整理。

常用指令

指令作用
npm run dev啟動開發 server(http://localhost:5173)
npm run buildProduction build,輸出到 dist/
npm run preview本地預覽 production build 的結果
npm test跑 Vitest 測試

典型開發流程

1. npm run dev ← 開 dev server
2. 編輯程式碼 ← 瀏覽器自動 hot reload
3. npm test ← 確認測試通過
4. npm run build ← (選配)確認 production build 沒問題
5. git add / commit / push

專案結構

src/
├── app/ ← 頁面元件和路由(App.tsx)
├── components/ ← 共用 UI 元件
├── data/mock/ ← 所有網站內容資料(改內容改這裡)
├── types/ ← TypeScript 型別定義
└── main.tsx ← 進入點
public/
└── images/ ← 靜態圖片(build 時原封不動複製)

部署架構

外層 nginx (TLS + domain routing)
└─ proxy_pass → localhost:10001
└─ Docker container (nginx:alpine, serve 靜態檔)
└─ Vite build output (dist/)
  • 內層 container 只負責 serve 靜態檔,不管 TLS、不管 domain
  • 外層 nginx 負責 c4lab.tw / c4lab.bime.ntu.edu.tw 的 TLS 和轉發
  • SEO canonical domain 已切換為 https://c4lab.github.iocanonicalsitemap.xmlrobots.txt 皆以此為準)
  • SPA 路由靠 try_files $uri $uri/ /index.html 處理

Server 上的操作

Docker(或 Podman):

git pull
docker compose up --build -d

如果用 Podman 且沒有 podman compose

git pull
podman build -t c4lab-web .
podman stop c4lab-web && podman rm c4lab-web
podman run -d --name c4lab-web --restart always -p 10001:80 c4lab-web

相關檔案

檔案用途
DockerfileMulti-stage build(Node build → nginx serve)
docker-compose.yml一行 service,10001:80
nginx.confSPA fallback + assets cache header
.dockerignore排除 node_modules、dist、.git

技術棧

  • Framework: React 19 + TypeScript
  • Build: Vite
  • Styling: Tailwind CSS
  • Router: react-router-dom v7(BrowserRouter)
  • Testing: Vitest + jsdom

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages