Skip to content

Commit be13006

Browse files
committed
Add checks for file blueprints in subfolders to add them to the list of available options and writing the correct value back into the content file.
1 parent f0ccc5f commit be13006

File tree

3 files changed

+39
-30
lines changed

3 files changed

+39
-30
lines changed

classes/CheckFiles.php

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,37 @@ public function findImagesWithoutContentOrTemplate(): array
4848
];
4949
}
5050
}
51-
5251
return $images;
5352
}
5453

5554
public function availableFileTemplates(): array
5655
{
5756
$templates = [];
5857
$filesPath = kirby()->root('blueprints') . '/files';
58+
$blueprintFiles = Dir::index($filesPath, true);
59+
60+
// debug: log all found blueprint file paths
61+
// foreach ($blueprintFiles as $path) {
62+
// $this->log('debug', 'Found blueprint: ' . $path);
63+
// }
5964

60-
foreach (glob($filesPath . '/*.yml') as $file) {
61-
$name = pathinfo($file, PATHINFO_FILENAME);
65+
foreach ($blueprintFiles as $relativePath) {
66+
if (pathinfo($relativePath, PATHINFO_EXTENSION) !== 'yml') {
67+
continue;
68+
}
69+
$name = pathinfo($relativePath, PATHINFO_FILENAME);
6270

63-
// skip the 'default' template
71+
// skip 'default.yml' regardless of folder depth
6472
if ($name === 'default') {
6573
continue;
6674
}
6775

68-
$label = ucfirst(str_replace(['-', '_'], ' ', $name));
76+
$parts = explode('/', $relativePath);
77+
$label = implode(' / ', array_map(fn($part) => ucfirst(str_replace(['-', '_'], ' ', pathinfo($part, PATHINFO_FILENAME))), $parts));
78+
$value = str_replace('.yml', '', $relativePath);
79+
6980
$templates[] = [
70-
'value' => $name,
81+
'value' => $value,
7182
'text' => $label
7283
];
7384
}
@@ -76,19 +87,18 @@ public function availableFileTemplates(): array
7687
return $templates;
7788
}
7889

79-
// --------------------------------------------------------------------------
80-
// logging
81-
// implements custom logging to /site/logs/debug.log
82-
public function log(string $level, string $message): void
83-
{
84-
$timestamp = date('Y-m-d H:i:s');
85-
$logDir = kirby()->root('logs');
86-
$logFile = $logDir . '/debug.log';
87-
88-
// ensure log directory exists
89-
Dir::make($logDir);
90-
$entry = Str::unhtml("[$timestamp][$level] $message") . PHP_EOL;
91-
F::append($logFile, $entry);
92-
}
93-
90+
// --------------------------------------------------------------------------
91+
// logging
92+
// implements custom logging to /site/logs/debug.log
93+
public function log(string $level, string $message): void
94+
{
95+
$timestamp = date('Y-m-d H:i:s');
96+
$logDir = kirby()->root('logs');
97+
$logFile = $logDir . '/template-checker.log';
98+
99+
// ensure log directory exists
100+
Dir::make($logDir);
101+
$entry = Str::unhtml("[$timestamp][$level] $message") . PHP_EOL;
102+
F::append($logFile, $entry);
103+
}
94104
}

index.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
} catch (Exception $e) {
9797
throw new Exception('Update failed: ' . $e->getMessage(), 500);
9898
}
99-
10099
}
101100
]
102101
]

src/components/ImageList.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ export default {
3939
};
4040
},
4141
watch: {
42-
templateDrawer(open) {
43-
// console.log('templateDrawer changed:', open);
44-
}
45-
},
42+
templateDrawer(open) {
43+
// console.log('templateDrawer changed:', open);
44+
}
45+
},
4646
computed: {
4747
items() {
4848
@@ -89,14 +89,14 @@ export default {
8989
});
9090
9191
panel.view.reload(); // reload view
92-
})
93-
.catch(() => {
92+
})
93+
.catch(() => {
9494
panel.notification.error({
9595
message: 'An error occurred',
9696
timeout: 4000
9797
});
98-
});
99-
},
98+
});
99+
},
100100
101101
openTemplateSelector(image) {
102102
// console.log('Opening Drawer with File ID:', image.id);

0 commit comments

Comments
 (0)