gallery/generate.php

53 lines
1.7 KiB
PHP
Raw Permalink Normal View History

2020-05-15 09:26:18 +00:00
<?php
$html = file_get_contents('https://tilde.town/');
$download = [];
$gallery = [];
$download[] = '@echo off';
$gallery[] = <<<HTML
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>tilde.town gallery</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="gallery.css">
</head>
<body>
<div class="wrapper">
<h1>tilde.town gallery</h1>
<p>by <a href="https://tilde.town/~severak">Severák</a></p>
<p>I really like <a href="https://neocities.org/browse">Neocities browse page</a>. I was wondering how would it look for tilde.town.</p>
<p>So here is it:</p>
2020-05-15 12:34:44 +00:00
<p><small>(please note that this is just first prototype, not a final product)</small></p>
2020-05-15 09:26:18 +00:00
<ul class="gallery">
HTML;
$regex = '/<a href="\/~(\w+)">[\w]+<\/a>/';
$matches = [];
preg_match_all($regex, $html, $matches);
foreach ($matches[1] as $match) {
$download[] = sprintf('echo downloading %s...', $match);
$download[] = sprintf('capture-website --overwrite --no-javascript --scale-factor 0.5 http://tilde.town/~%s/ --output %s.png', $match, $match);
$gallery[] = sprintf('<li><a href="https://tilde.town/~%s"><img src="%s.png" title="%s"><p>%s</p></a></li>', $match, $match, $match, $match);
}
$download[] = 'echo ALL OK';
$gallery[] = <<<HTML
</ul>
<hr>
2020-05-15 12:34:44 +00:00
<small>Generated using <a href="https://tildegit.org/severak/gallery">this code</a>. Updated manually, because you need headless browser to generate all these thumbnails.</small>
2020-05-15 09:26:18 +00:00
</div>
</body>
</html>
HTML;
file_put_contents('download.bat', implode(PHP_EOL, $download));
file_put_contents('index.html', implode(PHP_EOL, $gallery));
echo 'OK - generated index.html + download.bat' . PHP_EOL;