Handling subdir assets

This commit is contained in:
Pablo Ferreiro 2022-01-03 14:18:16 +01:00
parent b33c35db27
commit 5b75dd84f4
No known key found for this signature in database
GPG key ID: 41FBCE65B779FA24
5 changed files with 13 additions and 5 deletions

View file

@ -8,6 +8,10 @@ use Steampixel\Route;
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
function getSubdir(): string {
return $_ENV['APP_SUBDIR'] ? $_ENV['APP_SUBDIR'] : '/';
}
function getApi(array $proxy_elements): \Sovit\TikTok\Api {
$options = [];
// Proxy config
@ -23,6 +27,11 @@ function getApi(array $proxy_elements): \Sovit\TikTok\Api {
function getLatte(): \Latte\Engine {
$latte = new Latte\Engine;
$latte->setTempDirectory('./cache/views');
$latte->addFunction('assets', function (string $name, string $type) {
$subdir = getSubdir();
$path = "{$subdir}/{$type}/{$name}";
return $path;
});
return $latte;
}
@ -146,5 +155,4 @@ Route::add("/settings", function () use ($proxy_elements) {
header('Location: ./home');
}, 'POST');
$subdir = getenv('APP_SUBDIR');
Route::run($subdir);

View file

@ -48,4 +48,4 @@
</footer>
</div>
</div>
<script src="../scripts/feed.js"></script>
<script src="{assets('feed.js', 'scripts')"></script>

View file

@ -14,4 +14,4 @@
</div>
</div>
</nav>
<script src="./scripts/navbar.js"></script>
<script src="{assets('navbar.js', 'scripts')}"></script>

View file

@ -6,7 +6,7 @@
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Trending - TikTok</title>
<link rel="stylesheet" href="https://unpkg.com/bulmaswatch/superhero/bulmaswatch.min.css">
<link rel="stylesheet" href="../styles/feed.css">
<link rel="stylesheet" href="{assets('feed.css', 'styles')">
</head>
<body>
{include 'navbar.latte'}

View file

@ -6,7 +6,7 @@
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>{$feed->info->detail->user->nickname} - TikTok</title>
<link rel="stylesheet" href="https://unpkg.com/bulmaswatch/superhero/bulmaswatch.min.css">
<link rel="stylesheet" href="../styles/feed.css">
<link rel="stylesheet" href="{assets('feed.css', 'styles')">
</head>
<body>
{include 'navbar.latte'}