From c0ee3ed375ad3c51fe98faf9c4c92c0f6cfe4af2 Mon Sep 17 00:00:00 2001 From: Davide Masserut Date: Wed, 14 Dec 2022 13:32:45 +0100 Subject: [PATCH] Update reading time HTML element after fetching the original web page --- template/templates/views/entry.html | 2 +- ui/entry_scraper.go | 5 ++++- ui/static/js/app.js | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/template/templates/views/entry.html b/template/templates/views/entry.html index e3930c49..3d579d14 100644 --- a/template/templates/views/entry.html +++ b/template/templates/views/entry.html @@ -130,7 +130,7 @@ {{ end }} {{ if and .user.ShowReadingTime (gt .entry.ReadingTime 0) }} · - + {{ plural "entry.estimated_reading_time" .entry.ReadingTime .entry.ReadingTime }} {{ end }} diff --git a/ui/entry_scraper.go b/ui/entry_scraper.go index a7cc0403..e556dc94 100644 --- a/ui/entry_scraper.go +++ b/ui/entry_scraper.go @@ -9,6 +9,7 @@ import ( "miniflux.app/http/request" "miniflux.app/http/response/json" + "miniflux.app/locale" "miniflux.app/model" "miniflux.app/proxy" "miniflux.app/reader/processor" @@ -64,5 +65,7 @@ func (h *handler) fetchContent(w http.ResponseWriter, r *http.Request) { json.ServerError(w, r, err) } - json.OK(w, r, map[string]string{"content": proxy.ImageProxyRewriter(h.router, entry.Content)}) + readingTime := locale.NewPrinter(user.Language).Plural("entry.estimated_reading_time", entry.ReadingTime, entry.ReadingTime) + + json.OK(w, r, map[string]string{"content": proxy.ImageProxyRewriter(h.router, entry.Content), "reading_time": readingTime}) } diff --git a/ui/static/js/app.js b/ui/static/js/app.js index a58fd499..b8082fc8 100644 --- a/ui/static/js/app.js +++ b/ui/static/js/app.js @@ -334,8 +334,9 @@ function handleFetchOriginalContent() { element.innerHTML = previousInnerHTML; response.json().then((data) => { - if (data.hasOwnProperty("content")) { + if (data.hasOwnProperty("content") && data.hasOwnProperty("reading_time")) { document.querySelector(".entry-content").innerHTML = data.content; + document.querySelector(".entry-reading-time").innerHTML = data.reading_time; } }); });