1- import Link from "next/link" ;
1+ import { buttonVariants } from "fumadocs-ui/components/ui/button" ;
2+ import type { LucideProps } from "lucide-react" ;
23import {
34 Activity ,
45 ArrowRight ,
@@ -15,33 +16,123 @@ import {
1516 Terminal ,
1617 Zap ,
1718} from "lucide-react" ;
18- import { cn } from "@/lib/cn" ;
19- import { buttonVariants } from "fumadocs-ui/components/ui/button" ;
20- import type { LucideProps } from "lucide-react" ;
19+ import Link from "next/link" ;
2120import type { ComponentType } from "react" ;
21+ import { cn } from "@/lib/cn" ;
2222
2323/* ─── Syntax highlight helpers ─── */
2424
25- function Kw ( { children } : { children : React . ReactNode } ) {
26- return < span className = "font-semibold text-fd-primary" > { children } </ span > ;
27- }
25+ const tokenStyles : Record < string , string > = {
26+ keyword : "font-semibold text-fd-primary" ,
27+ string : "text-emerald-600 dark:text-emerald-400" ,
28+ comment : "italic text-fd-muted-foreground/60" ,
29+ function : "text-violet-600 dark:text-violet-400" ,
30+ } ;
2831
29- function Str ( { children } : { children : React . ReactNode } ) {
30- return (
31- < span className = "text-emerald-600 dark:text-emerald-400" > { children } </ span >
32- ) ;
33- }
32+ const goRules : [ RegExp , string ] [ ] = [
33+ [ / ( \/ \/ .* ) $ / gm, "comment" ] ,
34+ [ / ( " (?: [ ^ " \\ ] | \\ .) * " ) / g, "string" ] ,
35+ [ / \b ( p a c k a g e | i m p o r t | f u n c | v a r | c o n s t | t y p e | r e t u r n | i f | e l s e | f o r | r a n g e | d e f e r | g o | c h a n | m a p | s t r u c t | i n t e r f a c e ) \b / g, "keyword" ] ,
36+ [ / \b ( [ A - Z ] \w * ) \s * [ ( { ] / g, "function" ] ,
37+ [ / \. ( [ A - Z ] \w * ) \s * \( / g, "function" ] ,
38+ ] ;
3439
35- function Cm ( { children } : { children : React . ReactNode } ) {
36- return < span className = "italic text-fd-muted-foreground/60" > { children } </ span > ;
37- }
40+ function highlightGo ( code : string ) : React . ReactNode [ ] {
41+ const lines = code . split ( "\n" ) ;
3842
39- function Fn ( { children } : { children : React . ReactNode } ) {
40- return (
41- < span className = "text-violet-600 dark:text-violet-400" > { children } </ span >
42- ) ;
43+ return lines . map ( ( line , i ) => {
44+ const segments : { start : number ; end : number ; style : string ; group : number } [ ] = [ ] ;
45+
46+ for ( const [ re , style ] of goRules ) {
47+ re . lastIndex = 0 ;
48+ let m : RegExpExecArray | null = null ;
49+
50+ while ( ( m = re . exec ( line ) ) !== null ) {
51+ const group = style === "function" ? 1 : 1 ;
52+ const text = m [ group ] ?? m [ 0 ] ;
53+ const start = m . index + ( m [ 0 ] . indexOf ( text ) ) ;
54+
55+ segments . push ( { start, end : start + text . length , style, group } ) ;
56+ }
57+ }
58+
59+ segments . sort ( ( a , b ) => a . start - b . start ) ;
60+
61+ // Remove overlaps — earlier rules win
62+ const filtered : typeof segments = [ ] ;
63+
64+ for ( const seg of segments ) {
65+ if ( filtered . every ( ( f ) => seg . start >= f . end || seg . end <= f . start ) ) {
66+ filtered . push ( seg ) ;
67+ }
68+ }
69+
70+ filtered . sort ( ( a , b ) => a . start - b . start ) ;
71+
72+ const parts : React . ReactNode [ ] = [ ] ;
73+ let cursor = 0 ;
74+
75+ for ( const seg of filtered ) {
76+ if ( seg . start > cursor ) {
77+ parts . push ( line . slice ( cursor , seg . start ) ) ;
78+ }
79+
80+ parts . push (
81+ < span key = { `${ i } -${ seg . start } ` } className = { tokenStyles [ seg . style ] } >
82+ { line . slice ( seg . start , seg . end ) }
83+ </ span > ,
84+ ) ;
85+ cursor = seg . end ;
86+ }
87+
88+ if ( cursor < line . length ) {
89+ parts . push ( line . slice ( cursor ) ) ;
90+ }
91+
92+ return (
93+ < span key = { i } >
94+ { parts }
95+ { i < lines . length - 1 ? "\n" : null }
96+ </ span >
97+ ) ;
98+ } ) ;
4399}
44100
101+ const codeExample = `package main
102+
103+ import (
104+ "log"
105+
106+ "github.com/xraph/forge"
107+
108+ "github.com/xraph/ctrlplane/app"
109+ "github.com/xraph/ctrlplane/extension"
110+ "github.com/xraph/ctrlplane/provider/docker"
111+ "github.com/xraph/ctrlplane/store/memory"
112+ )
113+
114+ func main() {
115+ // Create a Forge app with OpenAPI docs
116+ forgeApp := forge.New(
117+ forge.WithAppName("ctrlplane"),
118+ forge.WithAppVersion("0.1.0"),
119+ )
120+
121+ // Register Ctrl Plane as an extension
122+ cpExt := extension.New(
123+ extension.WithStore(
124+ app.WithStore(memory.New()),
125+ ),
126+ extension.WithProvider(
127+ "docker",
128+ docker.New(docker.Config{}),
129+ ),
130+ )
131+
132+ forgeApp.RegisterExtension(cpExt)
133+ log.Fatal(forgeApp.Run())
134+ }` ;
135+
45136/* ─── Data ─── */
46137
47138const features : {
@@ -278,75 +369,7 @@ export default function HomePage() {
278369 </ div >
279370 < div className = "overflow-x-auto p-5" >
280371 < pre className = "font-mono text-[13px] leading-relaxed text-fd-foreground/90" >
281- < code >
282- < Kw > package</ Kw > main{ "\n" }
283- { "\n" }
284- < Kw > import</ Kw > ({ "\n" }
285- { " " }
286- < Str > "log"</ Str >
287- { "\n" }
288- { "\n" }
289- { " " }
290- < Str > "github.com/xraph/forge"</ Str >
291- { "\n" }
292- { "\n" }
293- { " " }
294- < Str > "github.com/xraph/ctrlplane/app"</ Str >
295- { "\n" }
296- { " " }
297- < Str > "github.com/xraph/ctrlplane/extension"</ Str >
298- { "\n" }
299- { " " }
300- < Str >
301- "github.com/xraph/ctrlplane/provider/docker"
302- </ Str >
303- { "\n" }
304- { " " }
305- < Str > "github.com/xraph/ctrlplane/store/memory"</ Str >
306- { "\n" } ){ "\n" }
307- { "\n" }
308- < Kw > func</ Kw > < Fn > main</ Fn > () { "{" }
309- { "\n" }
310- { " " }
311- < Cm > // Create a Forge app with OpenAPI docs</ Cm >
312- { "\n" }
313- { " " } forgeApp := forge.
314- < Fn > New</ Fn > ({ "\n" }
315- { " " } forge.
316- < Fn > WithAppName</ Fn > (< Str > "ctrlplane"</ Str > ),{ "\n" }
317- { " " } forge.
318- < Fn > WithAppVersion</ Fn > (< Str > "0.1.0"</ Str > ),{ "\n" }
319- { " " } ){ "\n" }
320- { "\n" }
321- { " " }
322- < Cm > // Register Ctrl Plane as an extension</ Cm >
323- { "\n" }
324- { " " } cpExt := extension.
325- < Fn > New</ Fn > ({ "\n" }
326- { " " } extension.
327- < Fn > WithStore</ Fn > ({ "\n" }
328- { " " } app.
329- < Fn > WithStore</ Fn > (memory.
330- < Fn > New</ Fn > ()),{ "\n" }
331- { " " } ),{ "\n" }
332- { " " } extension.
333- < Fn > WithProvider</ Fn > ({ "\n" }
334- { " " }
335- < Str > "docker"</ Str > ,{ "\n" }
336- { " " } docker.
337- < Fn > New</ Fn > (docker.Config{ "{}" } ) ,{ "\n" }
338- { " " } ),{ "\n" }
339- { " " } ){ "\n" }
340- { "\n" }
341- { " " } forgeApp.
342- < Fn > RegisterExtension</ Fn > (cpExt)
343- { "\n" }
344- { " " } log.
345- < Fn > Fatal</ Fn > (forgeApp.
346- < Fn > Run</ Fn > ())
347- { "\n" }
348- { "}" }
349- </ code >
372+ < code > { highlightGo ( codeExample ) } </ code >
350373 </ pre >
351374 </ div >
352375 </ div >
0 commit comments