📦 Feature: Structure données JSON projets + Navigation rapide

- Ajout data/projects.json avec 3 projets de test
- Fonctions PHP: loadJsonData, getProjects, getProjectsByCategory, getProjectBySlug, getAllTechnologies
- Gestion erreurs fichier manquant/JSON invalide
- Section navigation rapide sur page d'accueil (Projets, Compétences, Me Découvrir)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-22 23:54:26 +01:00
parent e19c60c19b
commit a4a41933c4
3 changed files with 193 additions and 0 deletions

View File

@@ -13,3 +13,82 @@ function include_template(string $name, array $data = []): void
extract($data);
include __DIR__ . "/../templates/{$name}.php";
}
/**
* Charge et parse un fichier JSON
* @param string $filename Nom du fichier dans le dossier data/
* @return array Données décodées ou tableau vide en cas d'erreur
*/
function loadJsonData(string $filename): array
{
$path = __DIR__ . "/../data/{$filename}";
if (!file_exists($path)) {
error_log("JSON file not found: {$filename}");
return [];
}
$content = file_get_contents($path);
$data = json_decode($content, true);
if (json_last_error() !== JSON_ERROR_NONE) {
error_log("JSON parse error in {$filename}: " . json_last_error_msg());
return [];
}
return $data;
}
/**
* Récupère tous les projets
* @return array Liste des projets
*/
function getProjects(): array
{
$data = loadJsonData('projects.json');
return $data['projects'] ?? [];
}
/**
* Récupère les projets par catégorie
* @param string $category Catégorie (vedette|secondaire)
* @return array Projets filtrés
*/
function getProjectsByCategory(string $category): array
{
return array_filter(getProjects(), fn($p) => $p['category'] === $category);
}
/**
* Récupère un projet par son slug
* @param string $slug Slug du projet
* @return array|null Projet ou null si non trouvé
*/
function getProjectBySlug(string $slug): ?array
{
$projects = getProjects();
foreach ($projects as $project) {
if ($project['slug'] === $slug) {
return $project;
}
}
return null;
}
/**
* Récupère les technologies uniques de tous les projets
* @return array Liste triée des technologies
*/
function getAllTechnologies(): array
{
$technologies = [];
foreach (getProjects() as $project) {
foreach ($project['technologies'] ?? [] as $tech) {
if (!in_array($tech, $technologies)) {
$technologies[] = $tech;
}
}
}
sort($technologies);
return $technologies;
}