Refactor Oribi Sync settings: remove pages folder option and enhance case-insensitive directory handling
This commit is contained in:
@@ -384,21 +384,23 @@ function oribi_sync_fetch_file( string $api_base, string $branch, string $file_p
|
||||
|
||||
/**
|
||||
* Filter tree entries to only those under a given directory prefix.
|
||||
* Matching is case-insensitive so Pages/, pages/, PAGES/ etc. all work.
|
||||
*
|
||||
* @param array $tree Tree from oribi_sync_fetch_tree().
|
||||
* @param string $prefix Directory prefix (e.g. 'pages/').
|
||||
* @param string $prefix Directory prefix (e.g. 'Pages').
|
||||
* @param bool $recursive Whether to include files in subdirectories (default: false).
|
||||
*
|
||||
* @return array Filtered entries (blobs only).
|
||||
*/
|
||||
function oribi_sync_filter_tree( array $tree, string $prefix, bool $recursive = false ): array {
|
||||
$prefix = rtrim( $prefix, '/' ) . '/';
|
||||
$plen = strlen( $prefix );
|
||||
$out = [];
|
||||
|
||||
foreach ( $tree as $entry ) {
|
||||
if ( $entry['type'] !== 'blob' ) continue;
|
||||
if ( strpos( $entry['path'], $prefix ) !== 0 ) continue;
|
||||
$relative = substr( $entry['path'], strlen( $prefix ) );
|
||||
if ( strncasecmp( $entry['path'], $prefix, $plen ) !== 0 ) continue;
|
||||
$relative = substr( $entry['path'], $plen );
|
||||
// Skip sub-directory files unless recursive is enabled
|
||||
if ( ! $recursive && strpos( $relative, '/' ) !== false ) continue;
|
||||
$out[] = $entry;
|
||||
|
||||
Reference in New Issue
Block a user