-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathportfolio.php
More file actions
153 lines (138 loc) · 5.2 KB
/
portfolio.php
File metadata and controls
153 lines (138 loc) · 5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
include __DIR__ . '/includes/config.php';
use App\Services\BlogContentService; // Reuse for markdown/front matter parsing
use Symfony\Component\Finder\Finder;
$service = new BlogContentService();
$projectSlug = $_GET['project'] ?? '';
$portfolioRoot = __DIR__ . '/portfolio';
// Helper: sanitize slug
function isValidSlug(string $slug): bool {
return (bool) preg_match('/^[a-z0-9-]+$/', $slug);
}
// List all projects if no specific project requested
if ($projectSlug === '') {
$projects = [];
if (is_dir($portfolioRoot)) {
$finder = new Finder();
$finder->files()->in($portfolioRoot)->name('markdown.md')->depth('== 1');
foreach ($finder as $file) {
$slug = basename($file->getPath());
$parsed = $service->parseFile($file->getRealPath());
$meta = $parsed['metadata'];
// Normalize tech list if provided as string
if (isset($meta['tech']) && is_string($meta['tech'])) {
$meta['tech'] = array_filter(array_map('trim', explode(',', $meta['tech'])));
}
$projects[] = [
'slug' => $slug,
'title' => $meta['title'] ?? 'Untitled Project',
'description' => $meta['description'] ?? '',
'client' => $meta['client'] ?? '',
'role' => $meta['role'] ?? '',
'tech' => $meta['tech'] ?? [],
'tags' => $meta['tags'] ?? [],
'metadata' => $meta,
];
}
// Sort: optional by title for now
usort($projects, fn($a,$b) => strcasecmp($a['title'], $b['title']));
}
echo $twig->render('pages/portfolio-index.html.twig', [
'page_title' => 'Portfolio | ' . $SITE_NAME,
'body_class' => 'portfolio-index is-preload',
'projects' => $projects,
'current_page' => 'portfolio.php',
]);
exit;
}
// Detail view
if (!isValidSlug($projectSlug)) {
http_response_code(404);
echo '404 - Project not found';
exit;
}
$projectDir = $portfolioRoot . '/' . $projectSlug;
$markdownFile = $projectDir . '/markdown.md';
if (!file_exists($markdownFile)) {
http_response_code(404);
echo '404 - Project not found';
exit;
}
$parsed = $service->parseFile($markdownFile);
$meta = $parsed['metadata'];
$contentHtml = $parsed['html'];
// Normalize tech list
if (isset($meta['tech']) && is_string($meta['tech'])) {
$meta['tech'] = array_filter(array_map('trim', explode(',', $meta['tech'])));
}
// Details (metadata) placement variant: inline | left | right (A/B test like blog)
$validVariants = ['inline','left','right'];
$detailsVariant = null;
if (isset($_GET['details_variant']) && in_array($_GET['details_variant'], $validVariants, true)) {
$detailsVariant = $_GET['details_variant'];
setcookie('details_variant', $detailsVariant, time()+60*60*24*30, '/');
}
if (!$detailsVariant && isset($_COOKIE['details_variant']) && in_array($_COOKIE['details_variant'], $validVariants, true)) {
$detailsVariant = $_COOKIE['details_variant'];
}
if (!$detailsVariant) {
$detailsVariant = $validVariants[array_rand($validVariants)];
setcookie('details_variant', $detailsVariant, time()+60*60*24*30, '/');
}
// Render details component for sidebar & inline placement
$detailsSidebarHtml = $twig->render('components/portfolio/_details.html.twig', [
'project' => [
'client' => $meta['client'] ?? '',
'role' => $meta['role'] ?? '',
'tech' => $meta['tech'] ?? [],
'tags' => $meta['tags'] ?? [],
],
'placement' => 'sidebar'
]);
$detailsInlineHtml = $detailsSidebarHtml;
if ($detailsVariant === 'inline') {
$detailsInlineHtml = $twig->render('components/portfolio/_details.html.twig', [
'project' => [
'client' => $meta['client'] ?? '',
'role' => $meta['role'] ?? '',
'tech' => $meta['tech'] ?? [],
'tags' => $meta['tags'] ?? [],
],
'placement' => 'inline'
]);
}
// Aggregate sidebars (details only for now; extend later for TOC or related projects)
$sidebarLeft = '';
$sidebarRight = '';
if ($detailsVariant === 'left') {
$sidebarLeft .= $detailsSidebarHtml;
} elseif ($detailsVariant === 'right') {
$sidebarRight .= $detailsSidebarHtml;
}
// Simple SEO metadata
$seo = [
'title' => $meta['title'] ?? 'Project',
'description' => $meta['description'] ?? '',
'keywords' => isset($meta['tech']) && is_array($meta['tech']) ? implode(', ', $meta['tech']) : ''
];
echo $twig->render('pages/portfolio-project.html.twig', [
'page_title' => ($meta['title'] ?? 'Project') . ' | ' . $SITE_NAME,
'body_class' => 'portfolio-project is-preload',
'current_page' => 'portfolio.php',
'project' => [
'slug' => $projectSlug,
'title' => $meta['title'] ?? 'Untitled Project',
'description' => $meta['description'] ?? '',
'client' => $meta['client'] ?? '',
'role' => $meta['role'] ?? '',
'tech' => $meta['tech'] ?? [],
'tags' => $meta['tags'] ?? [],
'content' => $contentHtml,
],
'details_variant' => $detailsVariant,
'details_html' => $detailsInlineHtml,
'sidebar_left' => $sidebarLeft ?: null,
'sidebar_right' => $sidebarRight ?: null,
'seo' => $seo,
]);
?>