add /latest-{ru,en}.pdf endpoints; store versions in config.yaml

This commit is contained in:
E. S. 2024-07-25 05:34:36 +03:00
parent fcb1460859
commit 5dc63760a8
6 changed files with 22 additions and 7 deletions

View File

@ -34,4 +34,8 @@ files_domain: files.example.org
git_repo: git@github.com:example/example_org.git
# runtime variables
is_dev: false
is_dev: false
book_versions:
en: 1
ru: 1

View File

@ -1,6 +1,6 @@
<?php
const ROUTER_VERSION = 7;
const ROUTER_VERSION = 8;
const ROUTER_MC_KEY = '4in1/routes';
$RouterInput = [];

View File

@ -14,7 +14,8 @@ class MainHandler extends request_handler {
set_title('$site_title');
set_skin_opts(['is_index' => true]);
render('main/index');
render('main/index',
versions: $config['book_versions']);
}
function GET_about() { redirect('/info/'); }

View File

@ -13,4 +13,13 @@ TXT;
exit;
}
function GET_latest() {
global $config;
list($lang) = input('lang');
if (!isset($config['book_versions'][$lang]))
not_found();
redirect("https://files.4in1.ws/4in1-{$lang}.pdf?{$config['book_versions'][$lang]}",
code: HTTPCode::Found);
}
}

View File

@ -22,7 +22,8 @@ return (function() {
'files/{'.implode(',', $coll_with_folder_support).'}/(\d+)/' => 'collection collection=${1} folder_id=$(1)',
],
'Services' => [
'robots.txt' => 'robots_txt',
'robots.txt' => 'robots_txt',
'latest-{en,ru}.pdf' => 'latest lang=${1}'
],
'Admin' => [
'admin/' => 'index',

View File

@ -9,7 +9,7 @@ use Post;
use PostLanguage;
use function is_admin;
function index($ctx) {
function index($ctx, array $versions) {
return <<<HTML
<div class="page"><div class="blog-post-text">
<div class="clearfix index-book">
@ -17,13 +17,13 @@ function index($ctx) {
<a class="index-book-image" id="index-book-image" href="https://files.4in1.ws/Images/4in1-cover-en.png" target="_blank" data-link-template="https://files.4in1.ws/Images/4in1-cover-{lang}.png"></a>
</div>
<a class="index-dl-line" href="https://files.4in1.ws/4in1-en.pdf?7" onmouseenter="IndexPage.setCoverLang('en')">
<a class="index-dl-line" href="https://files.4in1.ws/4in1-en.pdf?{$versions['en']}" onmouseenter="IndexPage.setCoverLang('en')">
<b>Download in English</b><br>
<div class="index-dl-line-info">
PDF <span class="bullet">&#8226;</span> 379 pp. <span class="bullet">&#8226;</span> 25 MiB
</div>
</a>
<a class="index-dl-line" href="https://files.4in1.ws/4in1-ru.pdf?5" onmouseenter="IndexPage.setCoverLang('ru')">
<a class="index-dl-line" href="https://files.4in1.ws/4in1-ru.pdf?{$versions['ru']}" onmouseenter="IndexPage.setCoverLang('ru')">
<b>Скачать на русском</b>
<div class="index-dl-line-info">
PDF <span class="bullet">&#8226;</span> 453 стр. <span class="bullet">&#8226;</span> 26 MiB