Modify website to support new sub-folders architecture

This commit is contained in:
Benjamin Loison 2023-02-13 05:45:08 +01:00
parent 454503271e
commit 94ad823e3b
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8
2 changed files with 10 additions and 2 deletions

View File

@ -15,11 +15,19 @@
} }
} }
function str_replace_first($needle, $replace, $haystack) {
$pos = strpos($haystack, $needle);
if ($pos !== false) {
$haystack = substr_replace($haystack, $replace, $pos, strlen($needle));
}
return $haystack;
}
$uri = $_SERVER['REQUEST_URI']; $uri = $_SERVER['REQUEST_URI'];
$uri = str_replace('/channels/', '', $uri); $uri = str_replace('/channels/', '', $uri);
$prefix = '/mnt/HDD0/YouTube_captions_search_engine/channels/'; $prefix = '/mnt/HDD0/YouTube_captions_search_engine/channels/';
if (str_contains($uri, '/')) { if (str_contains($uri, '/')) {
$uri = str_replace('/', '#', $uri); $uri = str_replace_first('/', '#', $uri);
$uri = $prefix . $uri; $uri = $prefix . $uri;
if (str_ends_with($uri, '.json')) { if (str_ends_with($uri, '.json')) {
header('Content-Type: application/json; charset=UTF-8'); header('Content-Type: application/json; charset=UTF-8');

View File

@ -39,7 +39,7 @@ See <?php echoUrl('https://gitea.lemnoslife.com/Benjamin_Loison/YouTube_captions
var channelsDom = document.getElementById('channels'); var channelsDom = document.getElementById('channels');
const channelFileParts = line.split('/'); const channelFileParts = line.split('/');
const channel = channelFileParts[0]; const channel = channelFileParts[0];
const channelFile = channelFileParts[1]; const channelFile = channelFileParts.slice(1).join('/');
const channelHref = `channels/${channel}`; const channelHref = `channels/${channel}`;
if (!channels.includes(channel)) { if (!channels.includes(channel)) {
channels.push(channel); channels.push(channel);