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

View file

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

View file

@ -14,4 +14,4 @@
</div> </div>
</div> </div>
</nav> </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"> <meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Trending - TikTok</title> <title>Trending - TikTok</title>
<link rel="stylesheet" href="https://unpkg.com/bulmaswatch/superhero/bulmaswatch.min.css"> <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> </head>
<body> <body>
{include 'navbar.latte'} {include 'navbar.latte'}

View file

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