Browse Source

Update reading time HTML element after fetching the original web page

Davide Masserut 3 years ago
parent
commit
c0ee3ed375
3 changed files with 7 additions and 3 deletions
  1. 1 1
      template/templates/views/entry.html
  2. 4 1
      ui/entry_scraper.go
  3. 2 1
      ui/static/js/app.js

+ 1 - 1
template/templates/views/entry.html

@@ -130,7 +130,7 @@
             {{ end }}
             {{ if and .user.ShowReadingTime (gt .entry.ReadingTime 0) }}
             ·
-            <span>
+            <span class="entry-reading-time">
                 {{ plural "entry.estimated_reading_time" .entry.ReadingTime .entry.ReadingTime }}
             </span>
             {{ end }}

+ 4 - 1
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})
 }

+ 2 - 1
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;
             }
         });
     });