Skip to content

Commit afe840b

Browse files
authored
initial commit of docs (#31)
1 parent 030662a commit afe840b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+2028
-17
lines changed

composer.json

+6
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,11 @@
1717
"wp-coding-standards/wpcs": "^3.0",
1818
"phpcompatibility/phpcompatibility-wp": "^2.1",
1919
"sirbrillig/phpcs-changed": "^2.11"
20+
},
21+
"scripts": {
22+
"docs-manifest": "php docs/bin/generate-manifest.php",
23+
"docs": [
24+
"@docs-manifest"
25+
]
2026
}
2127
}

composer.lock

+21-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/bin/generate-manifest.php

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env php
2+
<?php
3+
/**
4+
* Generate a manifest of all documentation files.
5+
*
6+
* @package wordpress/secure-custom-fields
7+
*/
8+
9+
// phpcs:disable WordPress.WP.AlternativeFunctions -- Using native PHP functions as this is a CLI script.
10+
11+
$root = dirname( __DIR__ ); // docs directory
12+
$repo = 'wordpress/secure-custom-fields';
13+
14+
$manifest = array();
15+
$paths = array(
16+
$root . '/*.md',
17+
$root . '/*/*.md',
18+
$root . '/*/*/*.md',
19+
$root . '/*/*/*/*.md', // For deeper nesting like features/fields/accordion/
20+
);
21+
22+
// Files to exclude from manifest
23+
$excludes = array(
24+
$root . '/README.md',
25+
$root . '/bin/README.md',
26+
);
27+
28+
foreach ( $paths as $path_pattern ) {
29+
foreach ( glob( $path_pattern ) as $file ) {
30+
// Skip specified README.md files and all META.md files.
31+
if ( in_array( $file, $excludes, true ) || basename( $file ) === 'META.md' ) {
32+
continue;
33+
}
34+
35+
$slug = basename( $file, '.md' );
36+
// Get relative path from docs directory
37+
$key = str_replace( array( $root . '/', '.md' ), '', $file );
38+
39+
// Handle index.md files specially
40+
if ( 'index' === $slug ) {
41+
$bits = explode( '/', $key );
42+
array_pop( $bits ); // Remove 'index'
43+
$slug = end( $bits ); // Use parent directory name as slug
44+
$key = implode( '/', $bits ); // Remove /index from key
45+
}
46+
47+
$parent = null;
48+
if ( stripos( $key, '/' ) ) {
49+
$bits = explode( '/', $key );
50+
array_pop( $bits );
51+
$parent = implode( '/', $bits );
52+
}
53+
54+
$manifest[ $key ] = array(
55+
'slug' => $slug,
56+
'parent' => $parent,
57+
'markdown_source' => sprintf( 'https://github.com/%s/blob/trunk/docs/%s.md', $repo, $key . ( 'index' === basename( $key ) ? '' : '/index' ) ),
58+
);
59+
}
60+
}
61+
62+
file_put_contents( $root . '/bin/manifest.json', json_encode( (object) $manifest, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) );
63+
64+
$count = count( $manifest );
65+
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
66+
printf( 'Generated manifest.json of %d pages%s', $count, PHP_EOL );

0 commit comments

Comments
 (0)