From b8df049b4e555a9c47fc797ee7f97ed9e67bd3a7 Mon Sep 17 00:00:00 2001
From: Marvin <52848568+mleem97@users.noreply.github.com>
Date: Fri, 10 Apr 2026 03:56:18 +0200
Subject: [PATCH] feat(homepage): add codeSnippetCaption to localization and
integrate snippet component
- Added 'codeSnippetCaption' to the English localization file for improved content clarity.
- Updated the homepage to include the GregCoreRandomSnippet component, enhancing user engagement with dynamic content.
This commit enriches the homepage experience by providing localized captions and integrating a new snippet feature.
---
src/components/GregCoreRandomSnippet.tsx | 61 ++++++++++++
src/data/gregCoreSnippets.ts | 118 +++++++++++++++++++++++
src/i18n/homepage/sharedLinks.ts | 1 +
src/i18n/homepage/types.ts | 2 +
src/pages/index.tsx | 35 +------
5 files changed, 186 insertions(+), 31 deletions(-)
create mode 100644 src/components/GregCoreRandomSnippet.tsx
create mode 100644 src/data/gregCoreSnippets.ts
diff --git a/src/components/GregCoreRandomSnippet.tsx b/src/components/GregCoreRandomSnippet.tsx
new file mode 100644
index 0000000..9ba16b8
--- /dev/null
+++ b/src/components/GregCoreRandomSnippet.tsx
@@ -0,0 +1,61 @@
+import React, {useMemo} from 'react';
+import BrowserOnly from '@docusaurus/BrowserOnly';
+import {GREG_CORE_SNIPPETS} from '../data/gregCoreSnippets';
+
+type Props = {
+ /** e.g. "Random sample from gregCore" */
+ caption: string;
+};
+
+/**
+ * Picks one snippet per client mount (stable for that visit; no SSR/CSR mismatch).
+ */
+function GregCoreRandomSnippetInner({caption}: Props): JSX.Element {
+ const snippet = useMemo(
+ () => GREG_CORE_SNIPPETS[Math.floor(Math.random() * GREG_CORE_SNIPPETS.length)],
+ [],
+ );
+
+ return (
+
+
+
+
+
{caption}
+
+ {snippet.title}
+ ·
+ {snippet.sourcePath}
+
+
+
+
+
+ {snippet.code.trimEnd()}
+
+
+
+ );
+}
+
+export function GregCoreRandomSnippet(props: Props): JSX.Element {
+ return (
+
+
+ Loading code sample…
+
+
+ }>
+ {() => }
+
+ );
+}
diff --git a/src/data/gregCoreSnippets.ts b/src/data/gregCoreSnippets.ts
new file mode 100644
index 0000000..54905af
--- /dev/null
+++ b/src/data/gregCoreSnippets.ts
@@ -0,0 +1,118 @@
+/**
+ * Short excerpts from gregCore (gregFramework monorepo) for the homepage.
+ * Kept in sync conceptually with Core/ and Hooks/ — adjust if APIs move.
+ */
+export type GregCoreSnippet = {
+ /** Short title for the card header */
+ title: string;
+ /** Path inside the gregFramework repo */
+ sourcePath: string;
+ code: string;
+};
+
+export const GREG_CORE_SNIPPETS: readonly GregCoreSnippet[] = [
+ {
+ title: 'GregHookName',
+ sourcePath: 'gregCore/Core/GregHookName.cs',
+ code: `public static string Create(GregDomain domain, string action)
+ => Create(domain, action, null);
+
+public static string Create(GregDomain domain, string action, string subject)
+{
+ if (string.IsNullOrWhiteSpace(action))
+ throw new ArgumentException("Action ist erforderlich.", nameof(action));
+ // → greg.PLAYER.MoneyChanged, greg.EMPLOYEE.Hired, …
+ var domainPart = DomainToSegment(domain);
+ // …
+}`,
+ },
+ {
+ title: 'GregDomain',
+ sourcePath: 'gregCore/Core/GregDomain.cs',
+ code: `public enum GregDomain
+{
+ Gameplay,
+ Player,
+ Employee,
+ Customer,
+ Server,
+ Rack,
+ Network,
+ Power,
+ Ui,
+ System
+}`,
+ },
+ {
+ title: 'GregEventDispatcher',
+ sourcePath: 'gregCore/Core/GregEventDispatcher.cs',
+ code: `public static void On(string hookName, Action