Move rendering into private templates

Add an explicit template renderer with HTML views and partials for the app, bootstrap, package, and catalog pages. Move shared reporting setup into config/reporting.php and relocate stylesheet assets under css/.
This commit is contained in:
www-data
2026-05-26 12:50:26 +02:00
parent 2f2e8869d6
commit 475765e31f
55 changed files with 2328 additions and 1175 deletions
+23 -83
View File
@@ -31,14 +31,12 @@
* links op die pagina gebruikt.
*/
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
ini_set('log_errors', '1');
error_reporting(E_ALL);
require_once __DIR__ . '/config/reporting.php';
require_once __DIR__ . '/private/nexttoken.php';
require_once __DIR__ . '/private/base64config.php';
require_once __DIR__ . '/private/racketzip.php';
require_once __DIR__ . '/private/Template.php';
$TOKENS = new NextTokenStore(__DIR__ . '/data/racket-sandbox.sqlite');
@@ -131,9 +129,10 @@ function text_response($text, $status = 200)
function fail_html($message, $status = 500)
{
html_response(
'<!doctype html>' .
'<html><head><meta charset="utf-8"><title>Error</title></head>' .
'<body><h1>Error</h1><pre>' . h($message) . '</pre></body></html>',
RacketSandboxTemplate::renderFile('protocol-error.html', array(
'title' => 'Error',
'message' => $message,
)),
$status
);
}
@@ -185,88 +184,29 @@ function serve_bootstrap()
$rows = '';
foreach ($parts as $i => $part) {
$rows .=
'<tr>' .
'<td>' . h((string)($i + 1)) . '</td>' .
'<td>' . h($part['number']) . '</td>' .
'<td>' . h((string)$part['size']) . '</td>' .
'<td><a href="' . h($part['url']) . '">' . h($part['url']) . '</a></td>' .
'</tr>' . "\n";
$rows .= RacketSandboxTemplate::renderFile('partials/racket-part-row.html', array(
'index' => (string)($i + 1),
'number' => $part['number'],
'size' => (string)$part['size'],
'url' => $part['url'],
)) . "\n";
}
$zipSize = (int)($manifest['source_bytes'] ?? 0);
$pkg_url = make_url('/racket-pkg-index');
html_response('<!doctype html>
<html lang="nl">
<head>
<meta charset="utf-8">
<title>Racket bootstrap</title>
<link rel="stylesheet" href="/styles.css">
</head>
<body class="simple-doc">
<h1>Racket bootstrap</h1>
<p>
<code>racket.zip</code> is vooraf via de configuratiepagina gesplitst naar
parts in de map <code>data</code>.
</p>
<p>
Package index: <a href="' . $pkg_url . '"> Racket package index</a>
</p>
<p>
Bronbestand: <code>config/racket.zip</code><br>
Bronbestand bytes: <code>' . h((string)$zipSize) . '</code><br>
Maximale base64 part-grootte: <code>' . h((string)RACKET_ZIP_MAX_BASE64_KB) . '</code> KiB (<code>' . h((string)RACKET_ZIP_MAX_BASE64_BYTES) . '</code> bytes)<br>
Binaire chunk-grootte: <code>' . h((string)RACKET_ZIP_BINARY_CHUNK_BYTES) . '</code> bytes<br>
Aantal parts: <code>' . h((string)count($parts)) . '</code><br>
Parts gemaakt op: <code>' . h((string)($manifest['created_at'] ?? '')) . '</code><br>
next-id voor alle links op deze pagina: <code>' . h($NEXT_ID) . '</code>
</p>
<p>
Elke link hieronder geeft <strong>text/plain</strong> met de
<strong>base64-representatie van één binair part</strong>.
De URL bevat alleen een nummer, geen bestandsnaam en geen extensie.
</p>
<table>
<thead>
<tr>
<th>#</th>
<th>partnummer</th>
<th>bytes</th>
<th>base64 text/plain URL</th>
</tr>
</thead>
<tbody>
' . $rows . '
</tbody>
</table>
<h2>Reconstructie in de sandbox</h2>
<p>
Decodeer ieder base64-part afzonderlijk naar een binair part. Plak daarna de
binaire parts in numerieke volgorde aan elkaar.
</p>
<pre>
base64 -d part-000001.txt &gt; part-000001
base64 -d part-000002.txt &gt; part-000002
base64 -d part-000003.txt &gt; part-000003
# enzovoort
cat part-* &gt; racket.zip
unzip racket.zip -d /tmp/racket
</pre>
</body>
</html>');
html_response(RacketSandboxTemplate::renderFile('bootstrap-racket.html', array(
'pkg_url' => $pkg_url,
'zip_size' => (string)$zipSize,
'max_base64_kb' => (string)RACKET_ZIP_MAX_BASE64_KB,
'max_base64_bytes' => (string)RACKET_ZIP_MAX_BASE64_BYTES,
'binary_chunk_bytes' => (string)RACKET_ZIP_BINARY_CHUNK_BYTES,
'part_count' => (string)count($parts),
'created_at' => (string)($manifest['created_at'] ?? ''),
'next_id' => $NEXT_ID,
'part_rows_html' => $rows,
)));
}
function serve_part()