-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
124 lines (114 loc) · 4.16 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
Asset::set(__DIR__ . D . 'bootstrap.min.css', 10.1);
Asset::set(__DIR__ . D . 'jquery.min.js', 10.1);
Asset::set(__DIR__ . D . 'popper.min.js', 10.2);
Asset::set(__DIR__ . D . 'bootstrap.min.js', 10.3);
$z = defined('TEST') && TEST ? '.' : '.min.';
Asset::set(__DIR__ . D . 'index' . $z . 'css', 20);
Asset::set(__DIR__ . D . 'index' . $z . 'js', 20);
lot('links', $links = new Anemone((static function ($links, $state, $url) {
$index = LOT . D . 'page' . D . trim(strtr($state->route ?? 'index', '/', D), D) . '.page';
$path = $url->path . '/';
foreach (g(LOT . D . 'page', 'page') as $k => $v) {
// Exclude home page
if ($k === $index) {
continue;
}
$v = new Page($k);
// Add current state
$v->current = 0 === strpos($path, '/' . $v->name . '/');
$links[$k] = $v;
}
ksort($links);
return $links;
})([], $state, $url)));
$states = [
'route-blog' => '/article',
'x.comment.page.type' => isset($state->x->comment) ? 'Markdown' : null,
'x.page.page.type' => isset($state->x->page) ? 'Markdown' : null
];
foreach ($states as $k => $v) {
!State::get($k) && null !== $v && State::set($k, $v);
}
if (isset($state->x->alert)) {
Hook::set('y.alert', function ($y) {
$y[0] = 'div';
foreach ($y[1] as &$v) {
$v[2]['class'] = 'alert alert-' . (['error' => 'danger'][$v['type'] ?? $v[2]['type']] ?? 'info');
}
$y[2]['class'] = 'mb-3';
return $y;
});
}
if (isset($state->x->comment)) {
Hook::set('y.form.comment', function ($y) {
foreach ([
'author' => 'input',
'content' => 'textarea',
'email' => 'input',
'link' => 'input'
] as $k => $v) {
if ($v === ($y[1][$k][1][2][1][0][0] ?? P)) {
$y[1][$k][1][2][1][0][2]['class'] = 'form-control';
}
if ('label' === ($y[1][$k][1][0][0] ?? P)) {
$y[1][$k][1][0][2]['class'] = 'col-form-label';
}
if ('small' === ($y[1][$k][1][2][1][2][0] ?? P)) {
$y[1][$k][1][2][1][2][2]['class'] = 'text-muted';
}
}
if ('button' === ($y[1]['tasks'][1][2][1]['publish'][0] ?? P)) {
$y[1]['tasks'][1][2][1]['publish'][2]['class'] = 'btn btn-primary';
}
if ('a' === ($y[1]['tasks'][1][2][1]['cancel'][0] ?? P)) {
if (!empty($y[1]['tasks'][1][2][1]['cancel'][2]['class'])) {
$y[1]['tasks'][1][2][1]['cancel'][2]['class'] = 'btn btn-danger ' . ($y[1]['tasks'][1][2][1]['cancel'][2]['class']);
}
}
return $y;
});
}
if (isset($state->x->pass)) {
Hook::set('y.form.pass', function ($y) {
foreach ([
'pass' => 'input',
] as $k => $v) {
if ($v === ($y[1][$k][1][2][1][0][0] ?? P)) {
$y[1][$k][1][2][1][0][2]['class'] = 'form-control';
}
if ('label' === ($y[1][$k][1][0][0] ?? P)) {
$y[1][$k][1][0][2]['class'] = 'col-form-label';
}
if ('small' === ($y[1][$k][1][2][1][2][0] ?? P)) {
$y[1][$k][1][2][1][2][2]['class'] = 'text-muted';
}
}
if ('button' === ($y[1]['tasks'][1][2][1]['enter'][0] ?? P)) {
$y[1]['tasks'][1][2][1]['enter'][2]['class'] = 'btn btn-primary';
}
return $y;
});
}
if (isset($state->x->user)) {
Hook::set('y.form.user', function ($y) {
foreach ([
'pass' => 'input',
'user' => 'input'
] as $k => $v) {
if ($v === ($y[1][$k][1][2][1][0][0] ?? P)) {
$y[1][$k][1][2][1][0][2]['class'] = 'form-control';
}
if ('label' === ($y[1][$k][1][0][0] ?? P)) {
$y[1][$k][1][0][2]['class'] = 'col-form-label';
}
if ('small' === ($y[1][$k][1][2][1][2][0] ?? P)) {
$y[1][$k][1][2][1][2][2]['class'] = 'text-muted';
}
}
if ('button' === ($y[1]['tasks'][1][2][1]['enter'][0] ?? P)) {
$y[1]['tasks'][1][2][1]['enter'][2]['class'] = 'btn btn-primary';
}
return $y;
});
}