@@ -209,6 +209,51 @@ function gen_cmd_pages( $cmd, $parent = array() ) {
209209 file_put_contents ( '_includes/internal-api-list.html ' , $ out );
210210});
211211
212+ desc ( 'Update the /docs/ page. ' );
213+ task ( 'doc-list ' , function ( $ app ){
214+ $ docs = array (
215+ 'Guides ' => array (),
216+ 'References ' => array (),
217+ 'Contributing ' => array (),
218+ 'Misc ' => array (),
219+ );
220+ foreach ( glob ( __DIR__ . '/docs/*/index.md ' ) as $ file ) {
221+ $ contents = file_get_contents ( $ file );
222+ $ parts = explode ( '--- ' , $ contents );
223+ $ header = $ parts [1 ];
224+ preg_match ( '#category:\s(.+)# ' , $ header , $ matches );
225+ if ( ! empty ( $ matches [1 ] ) && array_key_exists ( $ matches [1 ], $ docs ) ) {
226+ $ category = $ matches [1 ];
227+ } else {
228+ $ category = 'Misc ' ;
229+ }
230+ preg_match ( '#title:\s(.+)# ' , $ header , $ matches );
231+ $ title = ! empty ( $ matches [1 ] ) ? $ matches [1 ] : '' ;
232+ preg_match ( '#description:\s(.+)# ' , $ header , $ matches );
233+ $ description = ! empty ( $ matches [1 ] ) ? $ matches [1 ] : '' ;
234+ $ docs [ $ category ][] = array (
235+ 'path ' => basename ( dirname ( $ file ) ),
236+ 'title ' => $ title ,
237+ 'description ' => $ description ,
238+ );
239+ }
240+ $ out = '' ;
241+ foreach ( $ docs as $ category => $ cat_docs ) {
242+ $ out .= '<h3> ' . $ category . '</h3> ' . PHP_EOL . PHP_EOL ;
243+ $ out .= '<ul> ' . PHP_EOL ;
244+ foreach ( $ cat_docs as $ cat_doc ) {
245+ $ out .= '<li><a href="/docs/ ' . $ cat_doc ['path ' ] . '/"><strong> ' . $ cat_doc ['title ' ] . '</strong></a> ' ;
246+ if ( ! empty ( $ cat_doc ['description ' ] ) ) {
247+ $ out .= ' - ' . $ cat_doc ['description ' ];
248+ }
249+ $ out .= '</li> ' . PHP_EOL ;
250+ }
251+ $ out .= '</ul> ' . PHP_EOL . PHP_EOL ;
252+ }
253+
254+ file_put_contents ( '_includes/doc-list.html ' , $ out );
255+ });
256+
212257desc ( 'Build the site. ' );
213- task ( 'default ' , 'cmd-list ' , 'param-list ' , 'internal-api-list ' );
258+ task ( 'default ' , 'cmd-list ' , 'param-list ' , 'internal-api-list ' , ' doc-list ' );
214259
0 commit comments