1
0
forked from Thunix/www

added terminal interface as default. old website as no-js fallback

This commit is contained in:
root
2026-01-21 09:58:53 -07:00
parent 81d9ddfd03
commit 6f709886ed
14 changed files with 1569 additions and 19 deletions

53
terminal/api/page.php Normal file
View File

@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
require __DIR__ . '/_bootstrap.php';
$p = $_GET['p'] ?? '';
if (!is_string($p)) {
json_out(['error' => 'Invalid page'], 400);
}
$slug = trim($p);
$slug = ltrim($slug, '/');
$slug = preg_replace('/\?.*$/', '', $slug) ?? $slug;
if ($slug === '' || !preg_match('/^[A-Za-z0-9][A-Za-z0-9_-]*$/', $slug)) {
json_out(['error' => 'Invalid page'], 400);
}
if (preg_match('/^success\d+$/', $slug) === 1) {
json_out(['error' => 'Not found'], 404);
}
$file = $rootDir . '/articles/' . $slug . '.md';
if (!is_file($file)) {
json_out(['error' => 'Not found'], 404);
}
$md = file_get_contents($file);
if ($md === false) {
json_out(['error' => 'Failed to read page'], 500);
}
$parsedownPath = $rootDir . '/parsedown-1.7.3/Parsedown.php';
$extraPath = $rootDir . '/parsedown-extra-0.7.1/ParsedownExtra.php';
if (is_file($parsedownPath)) {
require_once $parsedownPath;
}
if (is_file($extraPath)) {
require_once $extraPath;
}
$html = '';
if (class_exists('ParsedownExtra')) {
$pd = new ParsedownExtra();
$html = $pd->text($md);
}
json_out([
'slug' => $slug,
'markdown' => $md,
'html' => $html,
]);