mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-25 20:44:53 -04:00
Add fallback mode.
This commit is contained in:
parent
a0db0e0ac3
commit
aa87ec15b0
6 changed files with 18 additions and 0 deletions
|
@ -1,5 +1,7 @@
|
|||
# Changelog
|
||||
|
||||
* adds `view.fallbackMode` option to generally serve only fallback mode
|
||||
* serves fallback mode for text browsers (`curl`, `links`, `lynx`, `w3m`)
|
||||
* change type `txt-svg` to `img-svg`, no thumbs but preview
|
||||
* fixes a tree indentaion glitch
|
||||
* fixes shell command detection on Windows
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
General view options.
|
||||
|
||||
- binaryPrefix: boolean, set to true uses 1024B=1KiB when formatting file sizes (see http://en.wikipedia.org/wiki/Binary_prefix)
|
||||
- fallbackMode: boolean, serve fallback mode
|
||||
- fastBrowsing: boolean, use History API if available (no need to reload the whole page)
|
||||
- fonts: array of strings, fonts to use in regular context
|
||||
- fontsMono: array of strings, fonts to use in monopspaced context
|
||||
|
@ -58,6 +59,7 @@
|
|||
*/
|
||||
"view": {
|
||||
"binaryPrefix": false,
|
||||
"fallbackMode": false,
|
||||
"fastBrowsing": true,
|
||||
"fonts": ["Ubuntu", "Roboto", "Helvetica", "Arial", "sans-serif"],
|
||||
"fontsMono": ["Ubuntu Mono", "Monaco", "Lucida Sans Typewriter", "monospace"],
|
||||
|
|
|
@ -24,6 +24,7 @@ class Bootstrap {
|
|||
} else {
|
||||
$public_href = $setup->get('PUBLIC_HREF');
|
||||
$x_head_tags = $context->get_x_head_html();
|
||||
$fallback_mode = $context->is_fallback_mode();
|
||||
$fallback_html = (new Fallback($context))->get_html();
|
||||
require __DIR__ . '/pages/index.php';
|
||||
}
|
||||
|
|
|
@ -68,6 +68,14 @@ class Context {
|
|||
return Util::starts_with($this->setup->get('REQUEST_HREF') . '/', $this->setup->get('PUBLIC_HREF'));
|
||||
}
|
||||
|
||||
public function is_text_browser() {
|
||||
return preg_match('/curl|links|lynx|w3m/i', $this->setup->get('HTTP_USER_AGENT')) === 1;
|
||||
}
|
||||
|
||||
public function is_fallback_mode() {
|
||||
return $this->query_option('view.fallbackMode', false) || $this->is_text_browser();
|
||||
}
|
||||
|
||||
public function to_href($path, $trailing_slash = true) {
|
||||
$rel_path = substr($path, strlen($this->setup->get('ROOT_PATH')));
|
||||
$parts = explode('/', $rel_path);
|
||||
|
|
|
@ -53,6 +53,7 @@ class Setup {
|
|||
$this->set('REQUEST_HREF', parse_url(getenv('REQUEST_URI'), PHP_URL_PATH));
|
||||
$this->set('SCRIPT_NAME', getenv('SCRIPT_NAME'));
|
||||
$this->set('SERVER_SOFTWARE', getenv('SERVER_SOFTWARE'));
|
||||
$this->set('HTTP_USER_AGENT', getenv('HTTP_USER_AGENT'));
|
||||
}
|
||||
|
||||
private function add_php_checks() {
|
||||
|
|
|
@ -14,14 +14,18 @@ html(class='no-js', lang='en')
|
|||
link(rel='shortcut icon', href!='<?= $public_href; ?>images/favicon/favicon-16-32.ico')
|
||||
link(rel='apple-touch-icon-precomposed', type='image/png', href!='<?= $public_href; ?>images/favicon/favicon-152.png')
|
||||
link(rel='stylesheet', href!='<?= $public_href; ?>css/styles.css')
|
||||
<?php if (!$fallback_mode) { ?>
|
||||
script(src!='<?= $public_href; ?>js/scripts.js', data-module='#{module}')
|
||||
<?= $x_head_tags; ?>
|
||||
<?php } ?>
|
||||
|
||||
body#root(class='#{module}')
|
||||
|
||||
div#fallback-hints
|
||||
<?php if (!$fallback_mode) { ?>
|
||||
span.noJsMsg Works best with JavaScript enabled!
|
||||
span.noBrowserMsg Works best in #[a(href='http://browsehappy.com') modern browsers]!
|
||||
<?php } ?>
|
||||
span.backlink #[a(href='#{pkg.homepage}', title='h5ai v#{pkg.version} - #{pkg.description}') powered by h5ai]
|
||||
|
||||
block body
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue