44
55namespace Flow \Website \Controller ;
66
7- use Flow \Website \Model \Documentation \Module ;
7+ use Flow \Website \Model \Documentation \{ Module , Page } ;
88use Flow \Website \Service \Documentation \{DSLDefinitions , Pages };
99use Flow \Website \Service \Examples ;
10+ use Flow \Website \Service \Manifest \PackageMeta ;
1011use Symfony \Bundle \FrameworkBundle \Controller \AbstractController ;
1112use Symfony \Component \HttpFoundation \Response ;
1213use Symfony \Component \Routing \Attribute \Route ;
@@ -17,6 +18,7 @@ public function __construct(
1718 private readonly Pages $ pages ,
1819 private readonly DSLDefinitions $ dslDefinitions ,
1920 private readonly Examples $ examples ,
21+ private readonly PackageMeta $ packageMeta ,
2022 ) {
2123 }
2224
@@ -78,6 +80,7 @@ public function dslFunction(string $module, string $function) : Response
7880 'definition ' => $ definition ,
7981 'examples ' => $ examples ,
8082 'types ' => $ this ->dslDefinitions ->types (),
83+ 'searchFacets ' => $ this ->dslFacets ($ module ),
8184 ]);
8285 }
8386
@@ -91,6 +94,7 @@ public function dslModule(string $module = 'core') : Response
9194 'modules ' => $ modules ,
9295 'definitions ' => $ this ->dslDefinitions ->fromModule (Module::fromName ($ module )),
9396 'types ' => $ this ->dslDefinitions ->types (),
97+ 'searchFacets ' => $ this ->dslFacets ($ module ),
9498 ]);
9599 }
96100
@@ -111,14 +115,18 @@ public function example(string $topic, string $example) : Response
111115 'description ' => $ this ->examples ->description ($ currentTopic , $ currentExample ),
112116 'documentation ' => $ this ->examples ->documentation ($ currentTopic , $ currentExample ),
113117 'code ' => $ this ->examples ->code ($ currentTopic , $ currentExample ),
118+ 'searchFacets ' => ['type ' => 'Example ' ],
114119 ]);
115120 }
116121
117122 #[Route('/documentation ' , name: 'documentation ' , options: ['sitemap ' => true ])]
118123 public function index () : Response
119124 {
125+ $ page = $ this ->pages ->get ('introduction.md ' );
126+
120127 return $ this ->render ('documentation/page.html.twig ' , [
121- 'page ' => $ this ->pages ->get ('introduction.md ' ),
128+ 'page ' => $ page ,
129+ 'searchFacets ' => $ this ->pageFacets ($ page ),
122130 ]);
123131 }
124132
@@ -144,8 +152,47 @@ public function navigationRight(string $currentPath = '') : Response
144152 #[Route('/documentation/{path} ' , name: 'documentation_page ' , requirements: ['path ' => '.* ' ], priority: -100 )]
145153 public function page (string $ path ) : Response
146154 {
155+ $ page = $ this ->pages ->get ($ path );
156+
147157 return $ this ->render ('documentation/page.html.twig ' , [
148- 'page ' => $ this ->pages ->get ($ path ),
158+ 'page ' => $ page ,
159+ 'searchFacets ' => $ this ->pageFacets ($ page ),
149160 ]);
150161 }
162+
163+ /**
164+ * @return array{type?: string, component?: string}
165+ */
166+ private function dslFacets (string $ module ) : array
167+ {
168+ $ facets = ['type ' => 'DSL ' ];
169+
170+ $ component = $ this ->packageMeta ->forDslModule ($ module );
171+
172+ if ($ component !== null ) {
173+ $ facets ['component ' ] = $ component ;
174+ }
175+
176+ return $ facets ;
177+ }
178+
179+ /**
180+ * @return array{type?: string, component?: string}
181+ */
182+ private function pageFacets (Page $ page ) : array
183+ {
184+ $ packageName = $ page ->package ();
185+
186+ if ($ packageName === null ) {
187+ return [];
188+ }
189+
190+ $ meta = $ this ->packageMeta ->forPackage ($ packageName );
191+
192+ if ($ meta === null ) {
193+ return [];
194+ }
195+
196+ return $ meta ;
197+ }
151198}
0 commit comments