Переглянути джерело

Add: <meta name="theme-color"> (#5105)

* implemented

* themes' metadata.json

* fix

* fix

* retrigger tests

* Update lib/Minz/View.php

Co-authored-by: Luc SANCHEZ <4697568+ColonelMoutarde@users.noreply.github.com>

* Update lib/Minz/View.php

Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>

* Update lib/Minz/View.php

Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>

* Update lib/Minz/View.php

Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>

* fix

---------

Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
Co-authored-by: Luc SANCHEZ <4697568+ColonelMoutarde@users.noreply.github.com>
maTh 3 роки тому
батько
коміт
068d18b69b

+ 4 - 0
app/FreshRSS.php

@@ -141,6 +141,10 @@ class FreshRSS extends Minz_FrontController {
 						FreshRSS_View::prependStyle(Minz_Url::display(FreshRSS::getThemeFileUrl($theme_id, $filename)));
 				}
 			}
+
+			if (!empty($theme['theme-color'])) {
+				FreshRSS_View::appendThemeColors($theme['theme-color']);
+			}
 		}
 		//Use prepend to insert before extensions. Added in reverse order.
 		if (Minz_Request::controllerName() !== 'index') {

+ 1 - 0
app/layout/layout.phtml

@@ -11,6 +11,7 @@ if (_t('gen.dir') === 'rtl') {
 	<head>
 		<meta charset="UTF-8" />
 		<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
+		<?= FreshRSS_View::metaThemeColor() ?>
 		<?= FreshRSS_View::headStyle() ?>
 		<script id="jsonVars" type="application/json">
 <?php $this->renderHelper('javascript_vars'); ?>

+ 30 - 0
lib/Minz/View.php

@@ -19,6 +19,7 @@ class Minz_View {
 	private static $title = '';
 	private static $styles = array ();
 	private static $scripts = array ();
+	private static $themeColors;
 
 	private static $params = array ();
 
@@ -237,6 +238,35 @@ class Minz_View {
 		);
 	}
 
+	/**
+	 * @param array|string $themeColors
+	 */
+	public static function appendThemeColors($themeColors): void {
+		self::$themeColors = $themeColors;
+	}
+
+	/**
+	 * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta/name/theme-color
+	 */
+	public static function metaThemeColor(): string {
+		$meta = '';
+
+		if (!empty(self::$themeColors['light'])) {
+			$meta .= '<meta name="theme-color" media="(prefers-color-scheme: light)" content="' . htmlspecialchars(self::$themeColors['light']) . '" />';
+		}
+		if (!empty(self::$themeColors['dark'])) {
+			$meta .= '<meta name="theme-color" media="(prefers-color-scheme: dark)" content="' . htmlspecialchars(self::$themeColors['dark']) . '" />';
+		}
+		if (!empty(self::$themeColors['default'])) {
+			$meta .= '<meta name="theme-color" content="' . htmlspecialchars(self::$themeColors['default']) . '" />';
+		}
+		if (empty(self::$themeColors['default']) && !empty(self::$themeColors) && empty(self::$themeColors['light']) && empty(self::$themeColors['dark'])) {
+			$meta .= '<meta name="theme-color" content="' . htmlspecialchars(self::$themeColors) . '" />';
+		}
+
+		return $meta;
+	}
+
 	/**
 	 * Gestion des scripts JS
 	 */

+ 2 - 1
p/themes/Alternative-Dark/metadata.json

@@ -3,5 +3,6 @@
   "author": "Ghost",
   "description": "Save my eyes!!!",
   "version": 0.1,
-  "files": ["_frss.css", "adark.css"]
+  "files": ["_frss.css", "adark.css"],
+  "theme-color": "#171717"
 }

+ 2 - 1
p/themes/Ansum/metadata.json

@@ -3,5 +3,6 @@
   "author": "Thomas Guesnon",
   "description": "Thème sablonneux",
   "version": 0.1,
-  "files": ["_frss.css", "ansum.css"]
+  "files": ["_frss.css", "ansum.css"],
+  "theme-color": "#fbf9f6"
 }

+ 2 - 1
p/themes/BlueLagoon/metadata.json

@@ -4,5 +4,6 @@
   "description": "C’est un cocktail (bis)! C’est la version plus fresh de Screwdriver. C’est… c’est… un thème pour l’agrégateur de flux RSS FreshRSS. En toute modestie, ce thème tue du Nyan Cat.",
   "version": 1.0,
   "files": ["_frss.css","BlueLagoon.css"],
-  "deprecated": true
+  "deprecated": true,
+  "theme-color": "#fefefd"
 }

+ 2 - 1
p/themes/Dark-pink/metadata.json

@@ -3,5 +3,6 @@
   "author": "Miicat_47",
   "description": "Nice dawk pink theme. >_< UwU",
   "version": 0.1,
-  "files": ["_frss.css", "../Alternative-Dark/adark.css", "pinkdark.css"]
+  "files": ["_frss.css", "../Alternative-Dark/adark.css", "pinkdark.css"],
+	"theme-color": "#171717"
 }

+ 2 - 1
p/themes/Dark/metadata.json

@@ -3,5 +3,6 @@
 	"author": "AD",
 	"description": "The dark side of the “Origine” theme",
 	"version": 0.2,
-	"files": ["_frss.css", "dark.css"]
+	"files": ["_frss.css", "dark.css"],
+	"theme-color": "#111111"
 }

+ 2 - 1
p/themes/Flat/metadata.json

@@ -4,5 +4,6 @@
   "description": "Thème plat pour FreshRSS",
   "version": 0.2,
   "files": ["_frss.css", "flat.css"],
-  "deprecated": true
+  "deprecated": true,
+	"theme-color": "#34495e"
 }

+ 2 - 1
p/themes/Mapco/metadata.json

@@ -3,5 +3,6 @@
   "author": "Thomas Guesnon",
   "description": "Thème pour FreshRSS",
   "version": 0.1,
-  "files": ["_frss.css", "mapco.css"]
+  "files": ["_frss.css", "mapco.css"],
+  "theme-color": "#303136"
 }

+ 2 - 1
p/themes/Nord/metadata.json

@@ -3,5 +3,6 @@
   "author": "joelchrono12",
   "description": "A simple theme based on Nord's color scheme",
   "version": 0.1,
-  "files": ["_frss.css","nord.css"]
+  "files": ["_frss.css","nord.css"],
+  "theme-color": "#2e3440"
 }

+ 2 - 1
p/themes/Origine-compact/metadata.json

@@ -3,5 +3,6 @@
   "author": "Kevin Papst",
   "description": "A theme that tries to use the screen size more efficiently, based on Origine",
   "version": 0.1,
-  "files": ["_frss.css", "../Origine/origine.css", "origine-compact.css"]
+  "files": ["_frss.css", "../Origine/origine.css", "origine-compact.css"],
+  "theme-color": {"dark": "#1f1f1f", "light": "#f0f0f0"}
 }

+ 2 - 1
p/themes/Origine/metadata.json

@@ -3,5 +3,6 @@
   "author": "Marien Fressinaud",
   "description": "Le thème par défaut pour FreshRSS",
   "version": 0.2,
-  "files": ["_frss.css", "origine.css"]
+  "files": ["_frss.css", "origine.css"],
+  "theme-color": {"dark": "#1f1f1f", "light": "#f0f0f0"}
 }

+ 2 - 1
p/themes/Pafat/metadata.json

@@ -3,5 +3,6 @@
   "author": "Plopoyop",
   "description": "Un thème pour FreshRSS",
   "version": 0.2,
-  "files": ["_frss.css", "pafat.css"]
+  "files": ["_frss.css", "pafat.css"],
+  "theme-color": "#f4f4f4"
 }

+ 2 - 1
p/themes/Screwdriver/metadata.json

@@ -4,5 +4,6 @@
   "description": "C’est un cocktail ! C’est chaud mais « fresh » à la fois. Ce thème tue du chaton.",
   "version": 1.1,
   "files": ["_frss.css","screwdriver.css"],
-  "deprecated" : true
+  "deprecated" : true,
+  "theme-color": "#fefefe"
 }

+ 2 - 1
p/themes/Swage/metadata.json

@@ -3,5 +3,6 @@
   "author": "Patrick Crandol",
   "description": "A Fresh take on the interface, inspired by the Flat Theme.",
   "version": 1.0,
-  "files": ["_frss.css", "swage.css"]
+  "files": ["_frss.css", "swage.css"],
+  "theme-color": "#22303d"
 }

+ 2 - 1
p/themes/base-theme/metadata.json

@@ -3,5 +3,6 @@
   "author": "Your name",
   "description": "A wonderful base theme",
   "version": 0.1,
-  "files": ["frss.css", "base.css"]
+  "files": ["frss.css", "base.css"],
+  "theme-color": "#123456"
 }