@@ -139,6 +139,7 @@ public function build()
139139 if ($ this ->issueLoggingEnabled ) {
140140 $ this ->updateIssues ();
141141 }
142+ $ this ->updateMetadataInFiles ($ this ->outputDir );
142143 }
143144
144145 private function updateHomepage (array $ services )
@@ -351,6 +352,7 @@ private function writeThemeFile($name, $contents)
351352 fwrite (STDOUT , "Writing file: {$ name }. \n" );
352353 $ updatedTemplate = str_replace ('index.html#top ' , $ name . '#top ' , $ this ->template );
353354 $ html = str_replace ('{{ contents }} ' , $ contents , $ updatedTemplate );
355+
354356 return (bool ) file_put_contents ("{$ this ->outputDir }/ {$ name }" , $ html );
355357 }
356358
@@ -364,6 +366,71 @@ private function replaceInner($name, $replace, $search = '{{ contents }}')
364366 file_put_contents ($ path , $ contents );
365367 }
366368
369+ /**
370+ * @param string $name
371+ * @param string $html
372+ *
373+ * @return void
374+ */
375+ private function updateMetadata (string $ name , string &$ html ): void
376+ {
377+ // Standardize file name to be capitalized and without .html
378+ $ normalizedName = implode (
379+ '- ' ,
380+ array_map ('ucfirst ' ,
381+ explode ('- ' ,
382+ str_replace (
383+ '. ' ,
384+ '- ' ,
385+ str_replace (
386+ '.html ' ,
387+ '' ,
388+ $ name
389+ )
390+ )
391+ )
392+ )
393+ );
394+ fwrite (STDOUT , "Adding metadata description to {$ name }. \n" );
395+ $ html = str_replace (
396+ '<meta name="description" content=""> ' ,
397+ "<meta name='description' content=' $ normalizedName'> " ,
398+ $ html
399+ );
400+ // Add title
401+ fwrite (STDOUT , "Adding title to {$ name }. \n" );
402+ $ html = str_replace (
403+ '<title></title> ' ,
404+ "<title> $ normalizedName - AWS SDK for PHP V3</title> " ,
405+ $ html
406+ );
407+ }
408+
409+ /**
410+ * @param string $outputDir
411+ *
412+ * @return void
413+ */
414+ public function updateMetadataInFiles (string $ outputDir ): void
415+ {
416+ $ dirIterator = new \DirectoryIterator ($ outputDir );
417+ $ filter = function ($ iterable , callable $ pred ) {
418+ foreach ($ iterable as $ value ) {
419+ if ($ pred ($ value )) {
420+ yield $ value ;
421+ }
422+ }
423+ };
424+ $ files = $ filter ($ dirIterator , function ($ file ) {
425+ return str_ends_with ($ file , '.html ' );
426+ });
427+ foreach ($ files as $ file ) {
428+ $ contents = file_get_contents ($ file ->getPathname ());
429+ $ this ->updateMetadata ($ file ->getFilename (), $ contents );
430+ file_put_contents ($ file ->getPathname (), $ contents );
431+ }
432+ }
433+
367434 private function gatherServiceVersions ()
368435 {
369436 $ manifest = __DIR__ . '/../../../src/data/manifest.json ' ;
0 commit comments