From 7accdc4416b19bd1f54c153c6930107dbc81257f Mon Sep 17 00:00:00 2001 From: Alex McGrath Date: Tue, 31 Mar 2020 00:54:02 +0100 Subject: [PATCH] Add the ability to use custom css --- locale/translations.go | 30 ++++++++++++++++++++---------- locale/translations/de_DE.json | 1 + locale/translations/en_US.json | 1 + locale/translations/es_ES.json | 1 + locale/translations/fr_FR.json | 1 + locale/translations/it_IT.json | 1 + locale/translations/ja_JP.json | 1 + locale/translations/nl_NL.json | 1 + locale/translations/pl_PL.json | 1 + locale/translations/ru_RU.json | 1 + locale/translations/zh_CN.json | 1 + storage/user.go | 5 +++++ template/common.go | 5 ++++- template/html/common/layout.html | 3 +++ template/html/settings.html | 1 + template/views.go | 3 ++- ui/form/settings.go | 3 +++ ui/settings_show.go | 1 + ui/static_stylesheet.go | 18 ++++++++++++++++++ 19 files changed, 67 insertions(+), 12 deletions(-) diff --git a/locale/translations.go b/locale/translations.go index 06e2fe19..146f09fd 100644 --- a/locale/translations.go +++ b/locale/translations.go @@ -259,6 +259,7 @@ var translations = map[string]string{ "form.prefs.select.older_first": "Älteste Artikel zuerst", "form.prefs.select.recent_first": "Neueste Artikel zuerst", "form.prefs.label.keyboard_shortcuts": "Tastaturkürzel aktivieren", + "form.prefs.label.custom_css": "Benutzerdefiniertes CSS", "form.import.label.file": "OPML Datei", "form.import.label.url": "URL", "form.integration.fever_activate": "Fever API aktivieren", @@ -593,6 +594,7 @@ var translations = map[string]string{ "form.prefs.select.older_first": "Older entries first", "form.prefs.select.recent_first": "Recent entries first", "form.prefs.label.keyboard_shortcuts": "Enable keyboard shortcuts", + "form.prefs.label.custom_css": "Custom CSS", "form.import.label.file": "OPML file", "form.import.label.url": "URL", "form.integration.fever_activate": "Activate Fever API", @@ -907,6 +909,7 @@ var translations = map[string]string{ "form.prefs.select.older_first": "Entradas más viejas primero", "form.prefs.select.recent_first": "Entradas recientes primero", "form.prefs.label.keyboard_shortcuts": "Habilitar atajos de teclado", + "form.prefs.label.custom_css": "CSS personalizado", "form.import.label.file": "Archivo OPML", "form.import.label.url": "URL", "form.integration.fever_activate": "Activar API de Fever", @@ -1221,6 +1224,7 @@ var translations = map[string]string{ "form.prefs.select.older_first": "Ancien éléments en premier", "form.prefs.select.recent_first": "Éléments récents en premier", "form.prefs.label.keyboard_shortcuts": "Activer les raccourcis clavier", + "form.prefs.label.custom_css": "CSS personnalisé", "form.import.label.file": "Fichier OPML", "form.import.label.url": "URL", "form.integration.fever_activate": "Activer l'API de Fever", @@ -1555,6 +1559,7 @@ var translations = map[string]string{ "form.prefs.select.older_first": "Prima i più recenti", "form.prefs.select.recent_first": "Prima i più vecchi", "form.prefs.label.keyboard_shortcuts": "Abilita le scorciatoie da tastiera", + "form.prefs.label.custom_css": "CSS personalizzati", "form.import.label.file": "File OPML", "form.import.label.url": "URL", "form.integration.fever_activate": "Abilita l'API di Fever", @@ -1869,6 +1874,7 @@ var translations = map[string]string{ "form.prefs.select.older_first": "古い記事を最初に", "form.prefs.select.recent_first": "新しい記事を最初に", "form.prefs.label.keyboard_shortcuts": "キーボード・ショートカットを有効にする", + "form.prefs.label.custom_css": "カスタムCSS", "form.import.label.file": "OPML ファイル", "form.import.label.url": "URL", "form.integration.fever_activate": "Fever API を有効にする", @@ -2183,6 +2189,7 @@ var translations = map[string]string{ "form.prefs.select.older_first": "Oudere items eerst", "form.prefs.select.recent_first": "Recente items eerst", "form.prefs.label.keyboard_shortcuts": "Schakel sneltoetsen in", + "form.prefs.label.custom_css": "Aangepaste CSS", "form.import.label.file": "OPML-bestand", "form.import.label.url": "URL", "form.integration.fever_activate": "Activeer Fever API", @@ -2517,6 +2524,7 @@ var translations = map[string]string{ "form.prefs.select.older_first": "Najstarsze wpisy jako pierwsze", "form.prefs.label.keyboard_shortcuts": "Włącz skróty klawiaturowe", "form.prefs.select.recent_first": "Najnowsze wpisy jako pierwsze", + "form.prefs.label.custom_css": "Niestandardowy CSS", "form.import.label.file": "Plik OPML", "form.import.label.url": "URL", "form.integration.fever_activate": "Aktywuj Fever API", @@ -2857,6 +2865,7 @@ var translations = map[string]string{ "form.prefs.select.older_first": "Сначала старые записи", "form.prefs.select.recent_first": "Сначала последние записи", "form.prefs.label.keyboard_shortcuts": "Включить сочетания клавиш", + "form.prefs.label.custom_css": "Пользовательские CSS", "form.import.label.file": "OPML файл", "form.import.label.url": "URL", "form.integration.fever_activate": "Активировать Fever API", @@ -3175,6 +3184,7 @@ var translations = map[string]string{ "form.prefs.select.older_first": "旧->新", "form.prefs.select.recent_first": "新->旧", "form.prefs.label.keyboard_shortcuts": "启用键盘快捷键", + "form.prefs.label.custom_css": "自定义CSS", "form.import.label.file": "OPML 文件", "form.import.label.url": "URL", "form.integration.fever_activate": "启用 Fever API", @@ -3249,14 +3259,14 @@ var translations = map[string]string{ } var translationsChecksums = map[string]string{ - "de_DE": "1b69b48622854bdab214411c75e22bb66b51054354aae0c50222d966b5563dcd", - "en_US": "c1cd8a4c6360881299609332bc930c0d59a30aea5ae90a6c87bcc06dbba7c69d", - "es_ES": "94f4da8c6160ca30c59294ec520f8648496b94904b61ac47c7ca24bfa4fe793b", - "fr_FR": "80a2d02c7a90e90024af4f5eb3aad710f245963df99538d7d71c0efcaae79f82", - "it_IT": "b033ade2a67a273253d3251df97e6b2da7e2adbec60a33de5d0f41198e6783b2", - "ja_JP": "2136cad37933c112a6e69f28936c216c8f262b28c47b57b18482c56a3f8932fb", - "nl_NL": "4a3a4a117f11cf62de5cf515c5adc74c8467d05feac1844fee4f81d863173887", - "pl_PL": "c088a74ad9e4dca6bdbf73b0b4fce97db60b5066cb03c6884a9462573b0f93ad", - "ru_RU": "506a34fdfa35dacf2d86b16f44d47addf2e0f1f376d2a86a474619d6654967cc", - "zh_CN": "463037b8bd51bb1e940f432fd621d62d4e81697298b8058124d287b5cbaee10f", + "de_DE": "7c2c818451a72ac82bbdd0f27e7ea25454b8826f7032b219188644c8f20ffdb5", + "en_US": "82bae5216e33a188a0eae633620be6c124295484214f38e6364127684c07b7d8", + "es_ES": "f501a6e373bbef30175e6d944d6bed463a385341a41c54ba129dca261ff6a61d", + "fr_FR": "5fa9d2745b3420d0cf29a8aab0ecbbe43d885b3058988f0b9afa35a7f791a7c6", + "it_IT": "de975b7d55a7e83214bd7a8f6afd61bd1725feea61be848ebe062ceece4c4060", + "ja_JP": "96101b6f5b073284304f052548da30334c3488324022d46c889f5dd85f4ae1df", + "nl_NL": "dcb4a1e4c80479004d3e6ce639e7f1b48208b766754c4424d7be0a34d5682b19", + "pl_PL": "f920466805f2e40bd83e65a0396723c7a922ca73406e4a3fdb9e9228d944ce2d", + "ru_RU": "b3fdd388e001afe8878b1b58b41ccf7e2b593644b65c518366d60b09df374c8a", + "zh_CN": "058a8f98e6a682d6cd32b451cb83f440c9731eedd36090deac429ddf7570d00c", } diff --git a/locale/translations/de_DE.json b/locale/translations/de_DE.json index 6d258655..e75a9a02 100644 --- a/locale/translations/de_DE.json +++ b/locale/translations/de_DE.json @@ -254,6 +254,7 @@ "form.prefs.select.older_first": "Älteste Artikel zuerst", "form.prefs.select.recent_first": "Neueste Artikel zuerst", "form.prefs.label.keyboard_shortcuts": "Tastaturkürzel aktivieren", + "form.prefs.label.custom_css": "Benutzerdefiniertes CSS", "form.import.label.file": "OPML Datei", "form.import.label.url": "URL", "form.integration.fever_activate": "Fever API aktivieren", diff --git a/locale/translations/en_US.json b/locale/translations/en_US.json index d189d8ae..7910e2a3 100644 --- a/locale/translations/en_US.json +++ b/locale/translations/en_US.json @@ -254,6 +254,7 @@ "form.prefs.select.older_first": "Older entries first", "form.prefs.select.recent_first": "Recent entries first", "form.prefs.label.keyboard_shortcuts": "Enable keyboard shortcuts", + "form.prefs.label.custom_css": "Custom CSS", "form.import.label.file": "OPML file", "form.import.label.url": "URL", "form.integration.fever_activate": "Activate Fever API", diff --git a/locale/translations/es_ES.json b/locale/translations/es_ES.json index 9feeaf38..b1d60b38 100644 --- a/locale/translations/es_ES.json +++ b/locale/translations/es_ES.json @@ -254,6 +254,7 @@ "form.prefs.select.older_first": "Entradas más viejas primero", "form.prefs.select.recent_first": "Entradas recientes primero", "form.prefs.label.keyboard_shortcuts": "Habilitar atajos de teclado", + "form.prefs.label.custom_css": "CSS personalizado", "form.import.label.file": "Archivo OPML", "form.import.label.url": "URL", "form.integration.fever_activate": "Activar API de Fever", diff --git a/locale/translations/fr_FR.json b/locale/translations/fr_FR.json index d7ef62da..c3f9b934 100644 --- a/locale/translations/fr_FR.json +++ b/locale/translations/fr_FR.json @@ -254,6 +254,7 @@ "form.prefs.select.older_first": "Ancien éléments en premier", "form.prefs.select.recent_first": "Éléments récents en premier", "form.prefs.label.keyboard_shortcuts": "Activer les raccourcis clavier", + "form.prefs.label.custom_css": "CSS personnalisé", "form.import.label.file": "Fichier OPML", "form.import.label.url": "URL", "form.integration.fever_activate": "Activer l'API de Fever", diff --git a/locale/translations/it_IT.json b/locale/translations/it_IT.json index 54505439..17767fdc 100644 --- a/locale/translations/it_IT.json +++ b/locale/translations/it_IT.json @@ -254,6 +254,7 @@ "form.prefs.select.older_first": "Prima i più recenti", "form.prefs.select.recent_first": "Prima i più vecchi", "form.prefs.label.keyboard_shortcuts": "Abilita le scorciatoie da tastiera", + "form.prefs.label.custom_css": "CSS personalizzati", "form.import.label.file": "File OPML", "form.import.label.url": "URL", "form.integration.fever_activate": "Abilita l'API di Fever", diff --git a/locale/translations/ja_JP.json b/locale/translations/ja_JP.json index 8549ad44..0a454c1a 100644 --- a/locale/translations/ja_JP.json +++ b/locale/translations/ja_JP.json @@ -254,6 +254,7 @@ "form.prefs.select.older_first": "古い記事を最初に", "form.prefs.select.recent_first": "新しい記事を最初に", "form.prefs.label.keyboard_shortcuts": "キーボード・ショートカットを有効にする", + "form.prefs.label.custom_css": "カスタムCSS", "form.import.label.file": "OPML ファイル", "form.import.label.url": "URL", "form.integration.fever_activate": "Fever API を有効にする", diff --git a/locale/translations/nl_NL.json b/locale/translations/nl_NL.json index 34f13c16..5ed6e992 100644 --- a/locale/translations/nl_NL.json +++ b/locale/translations/nl_NL.json @@ -254,6 +254,7 @@ "form.prefs.select.older_first": "Oudere items eerst", "form.prefs.select.recent_first": "Recente items eerst", "form.prefs.label.keyboard_shortcuts": "Schakel sneltoetsen in", + "form.prefs.label.custom_css": "Aangepaste CSS", "form.import.label.file": "OPML-bestand", "form.import.label.url": "URL", "form.integration.fever_activate": "Activeer Fever API", diff --git a/locale/translations/pl_PL.json b/locale/translations/pl_PL.json index ab002bfc..184e4c58 100644 --- a/locale/translations/pl_PL.json +++ b/locale/translations/pl_PL.json @@ -256,6 +256,7 @@ "form.prefs.select.older_first": "Najstarsze wpisy jako pierwsze", "form.prefs.label.keyboard_shortcuts": "Włącz skróty klawiaturowe", "form.prefs.select.recent_first": "Najnowsze wpisy jako pierwsze", + "form.prefs.label.custom_css": "Niestandardowy CSS", "form.import.label.file": "Plik OPML", "form.import.label.url": "URL", "form.integration.fever_activate": "Aktywuj Fever API", diff --git a/locale/translations/ru_RU.json b/locale/translations/ru_RU.json index f55bf717..12ffb111 100644 --- a/locale/translations/ru_RU.json +++ b/locale/translations/ru_RU.json @@ -256,6 +256,7 @@ "form.prefs.select.older_first": "Сначала старые записи", "form.prefs.select.recent_first": "Сначала последние записи", "form.prefs.label.keyboard_shortcuts": "Включить сочетания клавиш", + "form.prefs.label.custom_css": "Пользовательские CSS", "form.import.label.file": "OPML файл", "form.import.label.url": "URL", "form.integration.fever_activate": "Активировать Fever API", diff --git a/locale/translations/zh_CN.json b/locale/translations/zh_CN.json index 9b67a8f1..2d8b83c3 100644 --- a/locale/translations/zh_CN.json +++ b/locale/translations/zh_CN.json @@ -252,6 +252,7 @@ "form.prefs.select.older_first": "旧->新", "form.prefs.select.recent_first": "新->旧", "form.prefs.label.keyboard_shortcuts": "启用键盘快捷键", + "form.prefs.label.custom_css": "自定义CSS", "form.import.label.file": "OPML 文件", "form.import.label.url": "URL", "form.integration.fever_activate": "启用 Fever API", diff --git a/storage/user.go b/storage/user.go index b182a568..0463c6f8 100644 --- a/storage/user.go +++ b/storage/user.go @@ -172,6 +172,11 @@ func (s *Storage) UpdateUser(user *model.User) error { if err != nil { return fmt.Errorf(`store: unable to update user: %v`, err) } + + err = s.UpdateExtraField(user.ID, "custom_css", user.Extra["custom_css"]) + if err != nil { + return fmt.Errorf(`store: unable to update user css: %v`, err) + } } return nil diff --git a/template/common.go b/template/common.go index 1df49f1f..3288c80d 100644 --- a/template/common.go +++ b/template/common.go @@ -302,6 +302,9 @@ SOFTWARE. + {{ if .user }} {{ if ne (index .user.Extra "custom_css") ("") }} + + {{ end }}{{ end }} @@ -474,7 +477,7 @@ var templateCommonMapChecksums = map[string]string{ "feed_menu": "318d8662dda5ca9dfc75b909c8461e79c86fb5082df1428f67aaf856f19f4b50", "icons": "f0d94c2cfa6655b44adaf97f0b95c52a9cff5c31f3a8829ad438e4db7114af7e", "item_meta": "a5b07cc6597e5c8f3ca849ee486acb3f16f062d8a1eaa47d2fb402ae6825b7ef", - "layout": "a1f67b8908745ee4f9cee6f7bbbb0b242d4dcc101207ad4a9d67242b45683299", + "layout": "a4ed0b69bf16342166358ca9c3cf23c27d61443eca2e5da9fa46ff7474afe55b", "pagination": "7b61288e86283c4cf0dc83bcbf8bf1c00c7cb29e60201c8c0b633b2450d2911f", "settings_menu": "e2b777630c0efdbc529800303c01d6744ed3af80ec505ac5a5b3f99c9b989156", } diff --git a/template/html/common/layout.html b/template/html/common/layout.html index 4afa6ff5..94b7a490 100644 --- a/template/html/common/layout.html +++ b/template/html/common/layout.html @@ -35,6 +35,9 @@ + {{ if .user }} {{ if ne (index .user.Extra "custom_css") ("") }} + + {{ end }}{{ end }} diff --git a/template/html/settings.html b/template/html/settings.html index b7563fa8..11ef033c 100644 --- a/template/html/settings.html +++ b/template/html/settings.html @@ -51,6 +51,7 @@ +
diff --git a/template/views.go b/template/views.go index 68c78f05..f7ec0535 100644 --- a/template/views.go +++ b/template/views.go @@ -1310,6 +1310,7 @@ var templateViewsMap = map[string]string{ +
@@ -1552,7 +1553,7 @@ var templateViewsMapChecksums = map[string]string{ "login": "79ff2ca488c0a19b37c8fa227a21f73e94472eb357a51a077197c852f7713f11", "search_entries": "274950d03298c24f3942e209c0faed580a6d57be9cf76a6c236175a7e766ac6a", "sessions": "5d5c677bddbd027e0b0c9f7a0dd95b66d9d95b4e130959f31fb955b926c2201c", - "settings": "d949ecdd28a33eadafaa3a727e548b3466c5aa44b0a4bbf86cc49784704ff7f6", + "settings": "3ab566c3220c62edc3edc51f2e93c1101b728e9f62f52f23de6bc6322d86aeb6", "shared_entries": "19caea053664220bb9519df295eb2a17cf5836eaa9104b7ee24c60b88bb524e9", "unread_entries": "e38f7ffce17dfad3151b08cd33771a2cefe8ca9db42df04fc98bd1d675dd6075", "users": "d7ff52efc582bbad10504f4a04fa3adcc12d15890e45dff51cac281e0c446e45", diff --git a/ui/form/settings.go b/ui/form/settings.go index 8b4d7e6b..40a06ff7 100644 --- a/ui/form/settings.go +++ b/ui/form/settings.go @@ -21,6 +21,7 @@ type SettingsForm struct { Timezone string EntryDirection string KeyboardShortcuts bool + CustomCSS string } // Merge updates the fields of the given user. @@ -31,6 +32,7 @@ func (s *SettingsForm) Merge(user *model.User) *model.User { user.Timezone = s.Timezone user.EntryDirection = s.EntryDirection user.KeyboardShortcuts = s.KeyboardShortcuts + user.Extra["custom_css"] = s.CustomCSS if s.Password != "" { user.Password = s.Password @@ -74,5 +76,6 @@ func NewSettingsForm(r *http.Request) *SettingsForm { Timezone: r.FormValue("timezone"), EntryDirection: r.FormValue("entry_direction"), KeyboardShortcuts: r.FormValue("keyboard_shortcuts") == "1", + CustomCSS: r.FormValue("custom_css"), } } diff --git a/ui/settings_show.go b/ui/settings_show.go index 2803dc48..8e0a51b2 100644 --- a/ui/settings_show.go +++ b/ui/settings_show.go @@ -33,6 +33,7 @@ func (h *handler) showSettingsPage(w http.ResponseWriter, r *http.Request) { Timezone: user.Timezone, EntryDirection: user.EntryDirection, KeyboardShortcuts: user.KeyboardShortcuts, + CustomCSS: user.Extra["custom_css"], } timezones, err := h.store.Timezones() diff --git a/ui/static_stylesheet.go b/ui/static_stylesheet.go index 506caf44..e4300122 100644 --- a/ui/static_stylesheet.go +++ b/ui/static_stylesheet.go @@ -16,6 +16,24 @@ import ( func (h *handler) showStylesheet(w http.ResponseWriter, r *http.Request) { filename := request.RouteStringParam(r, "name") + if filename == "custom_css" { + user, err := h.store.UserByID(request.UserID(r)) + if err != nil { + html.NotFound(w, r) + return + } + b := response.New(w, r) + if user == nil { + b.WithHeader("Content-Type", "text/css; charset=utf-8") + b.WithBody("") + b.Write() + return + } + b.WithHeader("Content-Type", "text/css; charset=utf-8") + b.WithBody(user.Extra["custom_css"]) + b.Write() + return + } etag, found := static.StylesheetsChecksums[filename] if !found { html.NotFound(w, r)