-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
66 lines (56 loc) · 1.56 KB
/
index.php
File metadata and controls
66 lines (56 loc) · 1.56 KB
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
<?php
// index.php — tiny router
require __DIR__ . '/functions.php';
date_default_timezone_set(site('timezone') ?: 'UTC');
/**
* Figure out what part of the site is being requested.
*
* $path → the full request path (no domain, no query string),
* e.g. '/', '/blog', '/blog/hello'.
*
* $parts → the path split into segments. The home page '/' is treated
* as an empty array []. For '/blog/hello' you get ['blog','hello'].
*
* $first → the first segment of the path, or '' if none.
* Used to decide whether this is a collection ('blog'),
* a page ('about'), or the site root ('').
*/
$path = request_path(); // e.g. '/', '/blog', '/blog/hello'
$parts = $path === '/' ? [] : explode('/', ltrim($path, '/'));
$first = $parts[0] ?? '';
if ($path === '/robots.txt') {
require __DIR__ . '/routes/robots.php';
exit;
}
if ($path === '/sitemap.xml') {
require __DIR__ . '/routes/sitemap.php';
exit;
}
if ($path === '/admin') {
require __DIR__ . '/routes/admin.php';
exit;
}
if ($path === '/search') {
require __DIR__ . '/routes/search.php';
exit;
}
// Tags
if ($path === '/tags') {
require __DIR__ . '/routes/tags.php';
exit;
}
if ($first === 'tag' && isset($parts[1])) {
require __DIR__ . '/routes/tag.php';
exit;
}
// API: anything under /api/*
if (str_starts_with($path, '/api')) {
require __DIR__ . '/routes/api.php';
exit;
}
// Collections: /blog or /blog/slug
if (is_collection($first)) {
require __DIR__ . '/routes/collections.php';
exit;
}
require __DIR__ . '/routes/pages.php';