From 10948aa2cacae0a9670dfc722bd01fa85e2a409a Mon Sep 17 00:00:00 2001 From: gbanyan Date: Mon, 17 Nov 2025 16:32:09 +0800 Subject: [PATCH] Add env-based site configuration --- .env.local.example | 8 ++++++++ app/page.tsx | 6 ++++-- components/site-footer.tsx | 5 +++-- components/site-header.tsx | 4 ++-- lib/config.ts | 12 +++++++----- 5 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 .env.local.example diff --git a/.env.local.example b/.env.local.example new file mode 100644 index 0000000..c201c55 --- /dev/null +++ b/.env.local.example @@ -0,0 +1,8 @@ +# Copy this file to `.env.local` and adjust values. +# All vars prefixed with NEXT_PUBLIC_ are exposed to the browser. + +NEXT_PUBLIC_SITE_NAME="Your Name" +NEXT_PUBLIC_SITE_TITLE="Your Personal Site" +NEXT_PUBLIC_SITE_DESCRIPTION="Personal homepage and blog." +NEXT_PUBLIC_SITE_URL="https://example.com" +NEXT_PUBLIC_SITE_AUTHOR="Your Name" diff --git a/app/page.tsx b/app/page.tsx index 1c43507..f25ce9b 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,5 +1,6 @@ import Link from 'next/link'; import { getAllPostsSorted } from '@/lib/posts'; +import { siteConfig } from '@/lib/config'; export default function HomePage() { const posts = getAllPostsSorted().slice(0, 5); @@ -7,7 +8,9 @@ export default function HomePage() { return (
-

你好,我是 Your Name

+

+ 你好,我是 {siteConfig.name} +

這裡是我的個人首頁與技術 Blog。

@@ -39,4 +42,3 @@ export default function HomePage() {
); } - diff --git a/components/site-footer.tsx b/components/site-footer.tsx index c8db8d4..9a8d826 100644 --- a/components/site-footer.tsx +++ b/components/site-footer.tsx @@ -1,8 +1,9 @@ +import { siteConfig } from '@/lib/config'; + export function SiteFooter() { return ( ); } - diff --git a/components/site-header.tsx b/components/site-header.tsx index 632c30c..15825dc 100644 --- a/components/site-header.tsx +++ b/components/site-header.tsx @@ -1,12 +1,13 @@ import Link from 'next/link'; import { ThemeToggle } from './theme-toggle'; +import { siteConfig } from '@/lib/config'; export function SiteHeader() { return (
- 個人首頁 + {siteConfig.title}
); } - diff --git a/lib/config.ts b/lib/config.ts index ba70afc..9d80f7f 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -1,7 +1,9 @@ export const siteConfig = { - name: 'Your Name', - title: 'Your Personal Site', - description: 'Personal homepage and blog.', - url: 'http://localhost:3000' + name: process.env.NEXT_PUBLIC_SITE_NAME || 'Your Name', + title: process.env.NEXT_PUBLIC_SITE_TITLE || 'Your Personal Site', + description: + process.env.NEXT_PUBLIC_SITE_DESCRIPTION || + 'Personal homepage and blog.', + url: process.env.NEXT_PUBLIC_SITE_URL || 'http://localhost:3000', + author: process.env.NEXT_PUBLIC_SITE_AUTHOR || 'Your Name' }; -