mikespub-org / seblucas-cops

Calibre OPDS (and HTML) PHP Server : web-based light alternative to Calibre content server / Calibre2OPDS to serve ebooks (epub, mobi, pdf, ...)
http://blog.slucas.fr/en/oss/calibre-opds-php-server
GNU General Public License v2.0
55 stars 7 forks source link

fix style css not being prefixed with Route::base() #54

Closed Mikescher closed 9 months ago

Mikescher commented 9 months ago

In the latest version (2.1.4) the style-default.css cannot be resolved when directly accessing a subpage (it works wehn navigating from root to another page).

The problem is the following generated html code:

...

<script type="text/javascript" src="https://my-domain.com/vendor/npm-asset/lru-fast/lru.js?v=2.1.4"></script>
<script type="text/javascript" src="https://my-domain.com/./util.js"></script>
<link rel="related" href="https://my-domain.com/feed.php" type="application/atom+xml;profile=opds-catalog" title="COPS - mikescher.com" />
<link rel="icon" type="image/vnd.microsoft.icon" href="https://my-domain.com/favicon.ico" />
<link rel="stylesheet" type="text/css" href="https://my-domain.com/vendor/npm-asset/normalize.css/normalize.css?v=2.1.4" />
<link rel="stylesheet" type="text/css" href="https://my-domain.com/templates/default/styles/fa-solid.min.css?v=2.1.4" media="screen" />
<link rel="stylesheet" type="text/css" href="https://my-domain.com/templates/default/styles/fontawesome.min.css?v=2.1.4" media="screen" />
<link rel="stylesheet" type="text/css" href="templates/default/styles/style-default.css?v=2.1.4" media="screen" />

The last stylesheet is relative instead of absolute specified.

My config looms like this (running on the linuxserver docker container):

    if (!isset($config)) $config = [];

    $config['calibre_directory'] = '/books/';

    $config['cops_use_url_rewriting'] = "0";
    $config['cops_use_route_urls']    = "1";

    $config['cops_update_epub-metadata'] = "0";

    $config['cops_full_url'] = 'https://my-domain.com';

    $config['cops_language'] = 'en';

    $config['cops_title_default'] = "COPS - mikescher.com";

    $config['cops_template'] = 'default';
    $config['cops_style']    = 'default';

    ....

The fix in this PR is to add Route::base(), to the style() method.

mikespub commented 9 months ago

Thanks for the catch. If you'll look at index.php, you'll see that other template variables go through Route::url(), so we'll probably want to do that for current_css too, instead of adding Route::base() inside Request like you did.

https://github.com/mikespub-org/seblucas-cops/blob/c623b6798fe2ccfbdb737806d7a9fad4ae8d9564/index.php#L60-L61

mikespub commented 9 months ago

Actually basedir already goes through Route::url too, so if your config changes, it will change with it :-)

https://github.com/mikespub-org/seblucas-cops/blob/c623b6798fe2ccfbdb737806d7a9fad4ae8d9564/index.php#L66