@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.
Files changed (43) hide show
  1. package/.dockerignore +34 -0
  2. package/.env.example +35 -0
  3. package/.gitattributes +10 -0
  4. package/INSTALL.md +258 -0
  5. package/LICENSE +21 -0
  6. package/README.md +41 -0
  7. package/bin/create-nestbox.js +184 -0
  8. package/docker/nginx/Dockerfile +31 -0
  9. package/docker/opencode/Dockerfile +36 -0
  10. package/docker/opencode/entrypoint.sh +9 -0
  11. package/docker/php-fpm/Dockerfile +43 -0
  12. package/docker/rollup/Dockerfile +16 -0
  13. package/docker-compose.yaml +139 -0
  14. package/home/code/.user.ini +1 -0
  15. package/home/code/404.php +104 -0
  16. package/home/code/__data/.gitignore +2 -0
  17. package/home/code/__includes/footer.php +3 -0
  18. package/home/code/__includes/functions.php +325 -0
  19. package/home/code/__includes/header.php +20 -0
  20. package/home/code/__templates/super-document.php +47 -0
  21. package/home/code/scripts-bundle.css +13295 -0
  22. package/home/code/scripts-bundle.js +6277 -0
  23. package/home/code/scripts.js +3 -0
  24. package/home/code/styles.css +36 -0
  25. package/home/configs/nginx/nginx.conf +199 -0
  26. package/home/configs/opencode/instance.example.md +16 -0
  27. package/home/configs/opencode/instructions.md +308 -0
  28. package/home/configs/opencode/opencode.json +15 -0
  29. package/home/configs/php/cli.php +33 -0
  30. package/home/configs/php/composer.json +10 -0
  31. package/home/configs/php/composer.lock +805 -0
  32. package/home/configs/php/index.php +105 -0
  33. package/home/configs/php/init.php +3 -0
  34. package/home/configs/php/php.ini +5 -0
  35. package/home/configs/php/preload.php +5 -0
  36. package/home/configs/rollup/package-lock.json +2089 -0
  37. package/home/configs/rollup/package.json +16 -0
  38. package/home/configs/rollup/rollup.config.js +28 -0
  39. package/package.json +42 -0
  40. package/scripts/check-package.js +31 -0
  41. package/template.gitignore +20 -0
  42. package/tests/nestbox.ps1 +322 -0
  43. 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';
@@ -0,0 +1,3 @@
1
+ <?php
2
+ // Per-request bootstrap. Loaded once by the router.
3
+ require_once '/vendor/autoload.php';
@@ -0,0 +1,5 @@
1
+ ; Opcache configuration
2
+ [opcache]
3
+ opcache.enable=1
4
+ opcache.preload_user=nestbox
5
+ opcache.preload=/sources/php/preload.php
@@ -0,0 +1,5 @@
1
+ <?php
2
+ // OPcache preload. Runs once when PHP-FPM starts so the autoloader and
3
+ // the league/commonmark classes are warm in shared memory across every
4
+ // request.
5
+ require_once '/vendor/autoload.php';