style: ✨ add HTMX
This commit is contained in:
parent
a2c6842b71
commit
b8e449006b
16 changed files with 299 additions and 84 deletions
|
@ -133,6 +133,25 @@ function render_twig($template, $args = []) {
|
|||
echo $twig->render($template, $args);
|
||||
}
|
||||
|
||||
function try_render_ajax($SURI) {
|
||||
global $adapter;
|
||||
|
||||
$match = null;
|
||||
preg_match('/^\/ajax\/([^\/]+)(.*)$/', $SURI, $match);
|
||||
|
||||
if(!isset($match)) {
|
||||
die();
|
||||
}
|
||||
|
||||
$post = $adapter->get_post_by_path($match[2]);
|
||||
$subposts = $adapter->get_subposts_by_path($match[2]);
|
||||
|
||||
echo render_twig('ajax/' . $match[1] . '.html', [
|
||||
"post" => $post,
|
||||
"subposts" => $subposts
|
||||
]);
|
||||
}
|
||||
|
||||
function try_render_post($SURI) {
|
||||
global $adapter;
|
||||
|
||||
|
@ -281,6 +300,8 @@ function generate_website($SURI) {
|
|||
header('Content-Type: application/json');
|
||||
echo json_encode($adapter->perform_post_search($_GET['search_query']));
|
||||
}
|
||||
} elseif(preg_match('/^\/ajax\//', $SURI)) {
|
||||
try_render_ajax($SURI);
|
||||
} elseif(preg_match('/^\/feed(?:\/(rss|atom)(.*))?$/', $SURI, $match)) {
|
||||
$feed = $adapter->get_laminas_feed($match[2] ?? '/', $match[1] ?? 'rss');
|
||||
|
||||
|
@ -289,7 +310,7 @@ function generate_website($SURI) {
|
|||
header('Etag: W/"' . $SURI . '/' . strtotime($feed['feed_ts']) . '"');
|
||||
|
||||
echo $feed['feed'];
|
||||
} elseif(true) {
|
||||
} else {
|
||||
try_render_post($SURI);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue