Refactor to use plugin system for language support Remove hardcoded language features from core Move language handling to plugin system Improve content file discovery Simplify context creation Add plugin system documentation Implement hook system for extensibility Add template variable hook Add context storage for plugins Improve error handling Refactor rendering logic Improve list view sorting Add support for custom list templates Improve metadata handling Add plugin system reference documentation
50 lines
1.3 KiB
PHP
50 lines
1.3 KiB
PHP
<?php
|
|
readonly class Templates {
|
|
public function __construct(
|
|
public string $base,
|
|
public string $page,
|
|
public string $list
|
|
) {}
|
|
}
|
|
|
|
class Context {
|
|
private array $data = [];
|
|
|
|
public function __construct(
|
|
public private(set) string $contentDir,
|
|
public private(set) Templates $templates,
|
|
public private(set) string $requestPath,
|
|
public private(set) bool $hasTrailingSlash
|
|
) {}
|
|
|
|
// Plugin data storage
|
|
public function set(string $key, mixed $value): void {
|
|
$this->data[$key] = $value;
|
|
}
|
|
|
|
public function get(string $key, mixed $default = null): mixed {
|
|
return $this->data[$key] ?? $default;
|
|
}
|
|
|
|
public function has(string $key): bool {
|
|
return isset($this->data[$key]);
|
|
}
|
|
|
|
// Allow magic property access for plugin data
|
|
public function __get(string $name): mixed {
|
|
return $this->data[$name] ?? null;
|
|
}
|
|
|
|
public function __set(string $name, mixed $value): void {
|
|
$this->data[$name] = $value;
|
|
}
|
|
|
|
// Computed properties
|
|
public array $navigation {
|
|
get => buildNavigation($this);
|
|
}
|
|
|
|
public string $homeLabel {
|
|
get => loadMetadata($this->contentDir)["slug"] ?? "Home";
|
|
}
|
|
}
|