Add env-based site configuration

This commit is contained in:
2025-11-17 16:32:09 +08:00
parent 48521d6f5c
commit 10948aa2ca
5 changed files with 24 additions and 11 deletions

8
.env.local.example Normal file
View File

@@ -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"

View File

@@ -1,5 +1,6 @@
import Link from 'next/link'; import Link from 'next/link';
import { getAllPostsSorted } from '@/lib/posts'; import { getAllPostsSorted } from '@/lib/posts';
import { siteConfig } from '@/lib/config';
export default function HomePage() { export default function HomePage() {
const posts = getAllPostsSorted().slice(0, 5); const posts = getAllPostsSorted().slice(0, 5);
@@ -7,7 +8,9 @@ export default function HomePage() {
return ( return (
<section className="space-y-6"> <section className="space-y-6">
<div> <div>
<h1 className="text-3xl font-bold"> Your Name</h1> <h1 className="text-3xl font-bold">
{siteConfig.name}
</h1>
<p className="mt-2 text-gray-600 dark:text-gray-300"> <p className="mt-2 text-gray-600 dark:text-gray-300">
Blog Blog
</p> </p>
@@ -39,4 +42,3 @@ export default function HomePage() {
</section> </section>
); );
} }

View File

@@ -1,8 +1,9 @@
import { siteConfig } from '@/lib/config';
export function SiteFooter() { export function SiteFooter() {
return ( return (
<footer className="border-t py-4 text-center text-sm text-gray-500"> <footer className="border-t py-4 text-center text-sm text-gray-500">
© {new Date().getFullYear()} Your Name © {new Date().getFullYear()} {siteConfig.author}
</footer> </footer>
); );
} }

View File

@@ -1,12 +1,13 @@
import Link from 'next/link'; import Link from 'next/link';
import { ThemeToggle } from './theme-toggle'; import { ThemeToggle } from './theme-toggle';
import { siteConfig } from '@/lib/config';
export function SiteHeader() { export function SiteHeader() {
return ( return (
<header className="border-b bg-white/80 dark:bg-gray-950/80 backdrop-blur"> <header className="border-b bg-white/80 dark:bg-gray-950/80 backdrop-blur">
<div className="container mx-auto flex items-center justify-between px-4 py-3"> <div className="container mx-auto flex items-center justify-between px-4 py-3">
<Link href="/" className="font-semibold"> <Link href="/" className="font-semibold">
{siteConfig.title}
</Link> </Link>
<nav className="flex items-center gap-4 text-sm"> <nav className="flex items-center gap-4 text-sm">
<Link href="/blog">Blog</Link> <Link href="/blog">Blog</Link>
@@ -17,4 +18,3 @@ export function SiteHeader() {
</header> </header>
); );
} }

View File

@@ -1,7 +1,9 @@
export const siteConfig = { export const siteConfig = {
name: 'Your Name', name: process.env.NEXT_PUBLIC_SITE_NAME || 'Your Name',
title: 'Your Personal Site', title: process.env.NEXT_PUBLIC_SITE_TITLE || 'Your Personal Site',
description: 'Personal homepage and blog.', description:
url: 'http://localhost:3000' 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'
}; };