Repository navigation
Expand file tree
/
Copy pathnote.php
More file actions
58 lines (53 loc) · 2.07 KB
/
Copy pathnote.php
File metadata and controls
58 lines (53 loc) · 2.07 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
<?php
/** An engineering note: /notes/<slug> (rewritten to note.php?slug=<slug> by .htaccess). */
declare(strict_types=1);
require __DIR__ . '/app/bootstrap.php';
$slug = (string) ($_GET['slug'] ?? '');
$all = notes();
if (!preg_match('/^[a-z0-9-]{1,80}$/', $slug) || !isset($all[$slug])) {
require __DIR__ . '/404.php';
exit;
}
$n = $all[$slug];
$project = projects()[$n['project']];
send_page_headers();
header('Cache-Control: public, max-age=3600');
view('head', [
'title' => $n['title'] . ' · Israel Rocklyn',
'description' => $n['summary'],
'path' => '/notes/' . $slug,
'jsonld' => [
'@context' => 'https://schema.org',
'@type' => 'TechArticle',
'headline' => $n['title'],
'description' => $n['summary'],
'datePublished' => $n['date'],
'author' => ['@type' => 'Person', 'name' => profile()['name'], 'url' => SITE_URL . '/'],
],
]);
?>
<article class="note wrap">
<nav class="crumbs mono" aria-label="Breadcrumb"><a href="/#notes">notes</a> <span aria-hidden="true">/</span> <span><?= e($slug) ?></span></nav>
<header>
<p class="mono muted small"><?= e(date('F j, Y', (int) strtotime($n['date']))) ?> · from <a href="/work/<?= e($n['project']) ?>"><?= e($project['title']) ?></a></p>
<h1><?= e($n['title']) ?></h1>
<p class="lede"><?= e($n['summary']) ?></p>
</header>
<div class="prose">
<?php foreach ($n['body'] as [$type, $content]): ?>
<?php if ($type === 'h'): ?>
<h2><?= e($content) ?></h2>
<?php elseif ($type === 'list'): ?>
<ul><?php foreach ($content as $item): ?><li><?= e($item) ?></li><?php endforeach; ?></ul>
<?php elseif ($type === 'code'): ?>
<pre><code><?= e($content) ?></code></pre>
<?php else: ?>
<p><?= e($content) ?></p>
<?php endif; ?>
<?php endforeach; ?>
</div>
<footer class="note-foot">
<p>The full numbers, the code and the report are in the <a href="<?= e($project['repo']) ?>" rel="noopener"><?= e($project['title']) ?> repository</a>, and in the <a href="/work/<?= e($n['project']) ?>">case study</a>.</p>
</footer>
</article>
<?php view('foot'); ?>