@p10i/create-nestbox 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dockerignore +34 -0
- package/.env.example +35 -0
- package/.gitattributes +10 -0
- package/INSTALL.md +258 -0
- package/LICENSE +21 -0
- package/README.md +41 -0
- package/bin/create-nestbox.js +184 -0
- package/docker/nginx/Dockerfile +31 -0
- package/docker/opencode/Dockerfile +36 -0
- package/docker/opencode/entrypoint.sh +9 -0
- package/docker/php-fpm/Dockerfile +43 -0
- package/docker/rollup/Dockerfile +16 -0
- package/docker-compose.yaml +139 -0
- package/home/code/.user.ini +1 -0
- package/home/code/404.php +104 -0
- package/home/code/__data/.gitignore +2 -0
- package/home/code/__includes/footer.php +3 -0
- package/home/code/__includes/functions.php +325 -0
- package/home/code/__includes/header.php +20 -0
- package/home/code/__templates/super-document.php +47 -0
- package/home/code/scripts-bundle.css +13295 -0
- package/home/code/scripts-bundle.js +6277 -0
- package/home/code/scripts.js +3 -0
- package/home/code/styles.css +36 -0
- package/home/configs/nginx/nginx.conf +199 -0
- package/home/configs/opencode/instance.example.md +16 -0
- package/home/configs/opencode/instructions.md +308 -0
- package/home/configs/opencode/opencode.json +15 -0
- package/home/configs/php/cli.php +33 -0
- package/home/configs/php/composer.json +10 -0
- package/home/configs/php/composer.lock +805 -0
- package/home/configs/php/index.php +105 -0
- package/home/configs/php/init.php +3 -0
- package/home/configs/php/php.ini +5 -0
- package/home/configs/php/preload.php +5 -0
- package/home/configs/rollup/package-lock.json +2089 -0
- package/home/configs/rollup/package.json +16 -0
- package/home/configs/rollup/rollup.config.js +28 -0
- package/package.json +42 -0
- package/scripts/check-package.js +31 -0
- package/template.gitignore +20 -0
- package/tests/nestbox.ps1 +322 -0
- package/tests/nestbox.sh +438 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
require_once __DIR__ . '/init.php';
|
|
3
|
+
require_once '/home/code/__includes/functions.php';
|
|
4
|
+
|
|
5
|
+
use League\CommonMark\Environment\Environment;
|
|
6
|
+
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
|
|
7
|
+
use League\CommonMark\Extension\FrontMatter\FrontMatterExtension;
|
|
8
|
+
use League\CommonMark\Extension\FrontMatter\Output\RenderedContentWithFrontMatter;
|
|
9
|
+
use League\CommonMark\Extension\GithubFlavoredMarkdownExtension;
|
|
10
|
+
use League\CommonMark\Extension\HeadingPermalink\HeadingPermalinkExtension;
|
|
11
|
+
use League\CommonMark\MarkdownConverter;
|
|
12
|
+
|
|
13
|
+
$pagesDir = '/home/code';
|
|
14
|
+
$requestPath = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/';
|
|
15
|
+
|
|
16
|
+
if ($requestPath === '/_nestbox/health') {
|
|
17
|
+
header('Content-Type: application/json; charset=UTF-8');
|
|
18
|
+
echo '{"status":"ok"}';
|
|
19
|
+
exit;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
$route = trim(preg_replace('#/+#', '/', $requestPath), '/');
|
|
23
|
+
if ($route === '') {
|
|
24
|
+
$route = 'index';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
$markdownOutput = str_ends_with(strtolower($route), '.md');
|
|
28
|
+
if ($markdownOutput) {
|
|
29
|
+
$route = substr($route, 0, -3);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!preg_match('#^[A-Za-z0-9/_-]+$#', $route)) {
|
|
33
|
+
http_response_code(400);
|
|
34
|
+
exit;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
foreach (explode('/', $route) as $segment) {
|
|
38
|
+
if (str_starts_with($segment, '__')) {
|
|
39
|
+
http_response_code(404);
|
|
40
|
+
exit;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
$environment = new Environment([
|
|
45
|
+
'html_input' => 'allow',
|
|
46
|
+
'allow_unsafe_links' => false,
|
|
47
|
+
// Super-documents are trusted and may use script, style, and form elements.
|
|
48
|
+
'disallowed_raw_html' => [
|
|
49
|
+
'disallowed_tags' => [],
|
|
50
|
+
],
|
|
51
|
+
'heading_permalink' => [
|
|
52
|
+
'symbol' => '¶',
|
|
53
|
+
'insert' => 'after',
|
|
54
|
+
'min_heading_level' => 2,
|
|
55
|
+
'max_heading_level' => 4,
|
|
56
|
+
],
|
|
57
|
+
]);
|
|
58
|
+
$environment->addExtension(new CommonMarkCoreExtension());
|
|
59
|
+
$environment->addExtension(new GithubFlavoredMarkdownExtension());
|
|
60
|
+
$environment->addExtension(new FrontMatterExtension());
|
|
61
|
+
$environment->addExtension(new HeadingPermalinkExtension());
|
|
62
|
+
$markdown = new MarkdownConverter($environment);
|
|
63
|
+
|
|
64
|
+
$realPagesDir = realpath($pagesDir);
|
|
65
|
+
$phpPath = realpath($pagesDir . '/' . $route . '.php');
|
|
66
|
+
$markdownPath = realpath($pagesDir . '/' . $route . '.md');
|
|
67
|
+
$sourcePath = $markdownOutput && $markdownPath && is_file($markdownPath)
|
|
68
|
+
? $markdownPath
|
|
69
|
+
: ($phpPath && is_file($phpPath) ? $phpPath : ($markdownPath && is_file($markdownPath) ? $markdownPath : false));
|
|
70
|
+
|
|
71
|
+
if (!$realPagesDir || !$sourcePath || !str_starts_with($sourcePath, $realPagesDir . DIRECTORY_SEPARATOR)) {
|
|
72
|
+
http_response_code(404);
|
|
73
|
+
exit;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (str_ends_with(strtolower($sourcePath), '.php')) {
|
|
77
|
+
ob_start();
|
|
78
|
+
include $sourcePath;
|
|
79
|
+
$content = ob_get_clean();
|
|
80
|
+
} else {
|
|
81
|
+
$content = file_get_contents($sourcePath);
|
|
82
|
+
if ($content === false) {
|
|
83
|
+
http_response_code(500);
|
|
84
|
+
exit;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if ($markdownOutput) {
|
|
89
|
+
header('Content-Type: text/markdown; charset=UTF-8');
|
|
90
|
+
echo $content;
|
|
91
|
+
exit;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
$rendered = $markdown->convert($content);
|
|
95
|
+
$title = 'Nestbox';
|
|
96
|
+
if ($rendered instanceof RenderedContentWithFrontMatter) {
|
|
97
|
+
$frontMatter = $rendered->getFrontMatter();
|
|
98
|
+
if (is_array($frontMatter) && isset($frontMatter['title']) && is_string($frontMatter['title'])) {
|
|
99
|
+
$title = $frontMatter['title'];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
require $pagesDir . '/__includes/header.php';
|
|
104
|
+
echo $rendered->getContent();
|
|
105
|
+
require $pagesDir . '/__includes/footer.php';
|