Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,11 @@
"wp-coding-standards/wpcs": "^3.0",
"phpcompatibility/phpcompatibility-wp": "^2.1",
"sirbrillig/phpcs-changed": "^2.11"
},
"scripts": {
"docs-manifest": "php docs/bin/generate-manifest.php",
"docs": [
"@docs-manifest"
]
}
}
38 changes: 21 additions & 17 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions docs/bin/generate-manifest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env php
<?php
/**
* Generate a manifest of all documentation files.
*
* @package wordpress/secure-custom-fields
*/

// phpcs:disable WordPress.WP.AlternativeFunctions -- Using native PHP functions as this is a CLI script.

$root = dirname( __DIR__ ); // docs directory
$repo = 'wordpress/secure-custom-fields';

$manifest = array();
$paths = array(
$root . '/*.md',
$root . '/*/*.md',
$root . '/*/*/*.md',
$root . '/*/*/*/*.md', // For deeper nesting like features/fields/accordion/
);

// Files to exclude from manifest
$excludes = array(
$root . '/README.md',
$root . '/bin/README.md',
);

foreach ( $paths as $path_pattern ) {
foreach ( glob( $path_pattern ) as $file ) {
// Skip specified README.md files and all META.md files.
if ( in_array( $file, $excludes, true ) || basename( $file ) === 'META.md' ) {
continue;
}

$slug = basename( $file, '.md' );
// Get relative path from docs directory
$key = str_replace( array( $root . '/', '.md' ), '', $file );

// Handle index.md files specially
if ( 'index' === $slug ) {
$bits = explode( '/', $key );
array_pop( $bits ); // Remove 'index'
$slug = end( $bits ); // Use parent directory name as slug
$key = implode( '/', $bits ); // Remove /index from key
}

$parent = null;
if ( stripos( $key, '/' ) ) {
$bits = explode( '/', $key );
array_pop( $bits );
$parent = implode( '/', $bits );
}

$manifest[ $key ] = array(
'slug' => $slug,
'parent' => $parent,
'markdown_source' => sprintf( 'https://github.com/%s/blob/trunk/docs/%s.md', $repo, $key . ( 'index' === basename( $key ) ? '' : '/index' ) ),
);
}
}

file_put_contents( $root . '/bin/manifest.json', json_encode( (object) $manifest, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) );

$count = count( $manifest );
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
printf( 'Generated manifest.json of %d pages%s', $count, PHP_EOL );
Loading