Update: added stats page public or private option in siteconfig

This commit is contained in:
Wayne Sutton
2025-12-28 22:26:05 -08:00
parent 29d38eeced
commit 1e055c76fb
4 changed files with 63 additions and 2 deletions

View File

@@ -61,7 +61,10 @@ function App() {
element={<Home />}
/>
)}
<Route path="/stats" element={<Stats />} />
{/* Stats page route - only enabled when statsPage.enabled is true */}
{siteConfig.statsPage?.enabled && (
<Route path="/stats" element={<Stats />} />
)}
{/* Unsubscribe route for newsletter */}
<Route path="/unsubscribe" element={<Unsubscribe />} />
{/* Blog page route - only enabled when blogPage.enabled is true */}

View File

@@ -104,6 +104,10 @@ export default function Layout({ children }: LayoutProps) {
// Add hardcoded nav items (React routes like /stats, /write)
if (siteConfig.hardcodedNavItems && siteConfig.hardcodedNavItems.length > 0) {
siteConfig.hardcodedNavItems.forEach((item) => {
// Skip stats nav item if stats page is disabled
if (item.slug === "stats" && !siteConfig.statsPage?.enabled) {
return;
}
// Only add if showInNav is true (defaults to true)
if (item.showInNav !== false) {
navItems.push({

View File

@@ -154,6 +154,13 @@ export interface NewsletterAdminConfig {
showInNav: boolean; // Show link in navigation (hidden by default for security)
}
// Stats page configuration
// Controls access to the /stats route for viewing site analytics
export interface StatsPageConfig {
enabled: boolean; // Global toggle for stats page
showInNav: boolean; // Show link in navigation (controlled via hardcodedNavItems)
}
// Newsletter notifications configuration
// Sends developer notifications for subscriber events
// Uses AGENTMAIL_CONTACT_EMAIL or AGENTMAIL_INBOX as recipient
@@ -284,6 +291,9 @@ export interface SiteConfig {
// Newsletter admin configuration (optional)
newsletterAdmin?: NewsletterAdminConfig;
// Stats page configuration (optional)
statsPage?: StatsPageConfig;
// Newsletter notifications configuration (optional)
newsletterNotifications?: NewsletterNotificationsConfig;
@@ -558,6 +568,14 @@ Created by [Wayne](https://x.com/waynesutton) with Convex, Cursor, and Claude Op
showInNav: false, // Hide from navigation for security
},
// Stats page configuration
// Controls access to the /stats route for viewing site analytics
// Set enabled: false to make stats page private (route still accessible but shows disabled message)
statsPage: {
enabled: true, // Global toggle for stats page
showInNav: true, // Show link in navigation (also controlled via hardcodedNavItems)
},
// Newsletter notifications configuration
// Sends developer notifications for subscriber events via AgentMail
newsletterNotifications: {

View File

@@ -1,6 +1,6 @@
import { useState, useEffect } from "react";
import { useQuery } from "convex/react";
import { useNavigate } from "react-router-dom";
import { useNavigate, Link } from "react-router-dom";
import { api } from "../../convex/_generated/api";
import {
ArrowLeft,
@@ -37,6 +37,42 @@ export default function Stats() {
const navigate = useNavigate();
const stats = useQuery(api.stats.getStats);
// Check if stats page is enabled
if (!siteConfig.statsPage?.enabled) {
return (
<div className="stats-page-wide">
<div
style={{
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
minHeight: "60vh",
gap: "1rem",
padding: "2rem",
textAlign: "center",
}}
>
<h1 style={{ fontSize: "1.5rem", marginBottom: "0.5rem" }}>
Site Statistics
</h1>
<p style={{ color: "var(--text-secondary)", marginBottom: "1rem" }}>
Stats page is disabled in site configuration.
</p>
<Link
to="/"
style={{
color: "var(--link-color)",
textDecoration: "underline",
}}
>
Back to Home
</Link>
</div>
</div>
);
}
// GitHub stars state
const [githubStars, setGithubStars] = useState<number | null>(null);