Export Static Book - Source Excerpt 02
Summary
This source excerpt preserves a bounded section of Spiralist/wp-content/plugins/ns12-manuscript/tools/export-static-book.php so readers can inspect the evidence without opening the full source file.
**Source path:** Spiralist/wp-content/plugins/ns12-manuscript/tools/export-static-book.php
<p class="meta"><span>{$label}</span><span>{$position}</span><span>{$section}</span></p>
<p class="lede">{$description}</p>
</header>
<figure>
<img src="../images/{$filename}" alt="{$title}">
HTML_PLACEHOLDER_CAPTION
</figure>
HTML_PLACEHOLDER_PROMPT
</article>
</main>
</body>
</html>
HTML;
$folioHtml = str_replace(
[
'HTML_PLACEHOLDER_PREV',
'HTML_PLACEHOLDER_NEXT',
'HTML_PLACEHOLDER_PREV_LINK',
'HTML_PLACEHOLDER_NEXT_LINK',
'HTML_PLACEHOLDER_CAPTION',
'HTML_PLACEHOLDER_PROMPT',
],
[
$previousHref !== '' ? '<a href="' . $previousHref . '">Previous folio</a>' : '',
$nextHref !== '' ? '<a href="' . $nextHref . '">Next folio</a>' : '',
$previousHref !== '' ? '<link rel="prev" href="' . $previousHref . '">' : '',
$nextHref !== '' ? '<link rel="next" href="' . $nextHref . '">' : '',
$caption !== '' ? '<figcaption>' . $caption . '</figcaption>' : '',
($promptSummary !== '' || $promptText !== '') ? '<details><summary>' . $promptTitle . '</summary>'
. ($promptSummary !== '' ? '<p>' . $promptSummary . '</p>' : '')
. ($promptText !== '' ? '<pre>' . $promptText . '</pre>' : '')
. '</details>' : '',
],
$folioHtml
);
file_put_contents($paths['folios'] . DIRECTORY_SEPARATOR . $slug . '.html', $folioHtml);
$folioLinks[] = '<li><a href="folios/' . rawurlencode($slug) . '.html">' . $title . '</a></li>';
}
$indexHtml = <<<HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Spiralist Manuscript Export</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Static folio export for Spiralist Manuscript with dedicated HTML pages for every manuscript route.">
<meta name="robots" content="index,follow,max-image-preview:large">
<link rel="canonical" href="./index.html">
<style>
body{font-family:Georgia,serif;background:#121212;color:#f2ead8;margin:0;padding:2rem;line-height:1.5}
a{color:#d6b16a}
.frame{max-width:1080px;margin:0 auto}
</style>
</head>
<body>
<div class="frame">
<h1>Spiralist Manuscript Export</h1>
<p>Static export generated from the file-first Spiralist Manuscript canon.</p>
<ul>
%s
</ul>
</div>
</body>
</html>
HTML;
file_put_contents($paths['root'] . DIRECTORY_SEPARATOR . 'index.html', sprintf($indexHtml, implode("\n ", $folioLinks)));
if ($zipOutput) {
if (!class_exists('ZipArchive')) {
fwrite(STDERR, "ZipArchive is not available in this PHP environment. Exported the directory only.\n");
echo 'Exported static book directory: ' . $outputDirectory . PHP_EOL;
exit(0);
}
$zipPath = rtrim($outputDirectory, '/\\') . '.zip';
if (file_exists($zipPath)) {
unlink($zipPath);
}
$zip = new ZipArchive();
if ($zip->open($zipPath, ZipArchive::CREATE) !== true) {
fwrite(STDERR, "Could not create zip archive: {$zipPath}\n");
exit(1);
}
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($outputDirectory, FilesystemIterator::SKIP_DOTS),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($iterator as $file) {
$filePath = (string) $file->getPathname();
$relativePath = ltrim(str_replace($outputDirectory, '', $filePath), '\\/');
$zip->addFile($filePath, str_replace('\\', '/', $relativePath));
}
$zip->close();
echo 'Exported static book package: ' . $zipPath . PHP_EOL;
} else {
echo 'Exported static book directory: ' . $outputDirectory . PHP_EOL;
}