From 228a24a506a7fcc9f9bf3b3cd9298ea13544d445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Mon, 8 Aug 2022 21:03:22 +0200 Subject: [PATCH] CustomCategory: when no name set, use 'Custom ID' as name --- src/customCategory.js | 10 ++++++++-- src/customCategory.php | 11 +++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/customCategory.js b/src/customCategory.js index f469e7c4..3b79194c 100644 --- a/src/customCategory.js +++ b/src/customCategory.js @@ -25,7 +25,13 @@ class CustomCategoryRepository { } ajax('customCategory', { id }, (result) => { - callback(null, yaml.load(result)) + const data = yaml.load(result) + + if (Object.is(data) && !('name' in data)) { + data.name = 'Custom ' + id.substr(0, 6) + } + + callback(null, data) }) } @@ -200,7 +206,7 @@ function customCategoriesList (browser, options) { const a = document.createElement('a') a.href = '#categories=custom/' + cat.id - a.appendChild(document.createTextNode(cat.id)) + a.appendChild(document.createTextNode(cat.name)) li.appendChild(a) const edit = document.createElement('a') diff --git a/src/customCategory.php b/src/customCategory.php index dc4b1427..388d78f0 100644 --- a/src/customCategory.php +++ b/src/customCategory.php @@ -15,8 +15,19 @@ function ajax_customCategory ($param) { $data = array_map(function ($d) { $d['popularity'] = (float)$d['popularity']; $d['accessCount'] = (int)$d['accessCount']; + + $content = yaml_parse($d['content']); + if ($content && is_array($content) && array_key_exists('name', $content)) { + $d['name'] = lang($content['name']); + } + else { + $d['name'] = 'Custom ' . substr($d['id'], 0, 6); + } + + unset($d['content']); return $d; }, $data); + $stmt->closeCursor(); return $data; }