mirror of
https://github.com/miniflux/v2.git
synced 2025-09-15 18:57:04 +00:00
Add reading time for entries
This commit is contained in:
parent
499fb1f7df
commit
ee5a8a05c9
25 changed files with 813 additions and 653 deletions
|
@ -237,6 +237,13 @@ SOFTWARE.
|
|||
<li>
|
||||
<time datetime="{{ isodate .entry.Date }}" title="{{ isodate .entry.Date }}">{{ elapsed .user.Timezone .entry.Date }}</time>
|
||||
</li>
|
||||
{{ if .user.ShowReadingTime }}
|
||||
<li>
|
||||
<span>
|
||||
{{ plural "entry.estimated_reading_time" (timeToRead .entry.Content) (timeToRead .entry.Content) }}
|
||||
</span>
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
<ul class="item-meta-icons">
|
||||
{{ if .entry.ShareCode }}
|
||||
|
@ -510,7 +517,7 @@ var templateCommonMapChecksums = map[string]string{
|
|||
"feed_list": "30acc9ecc413811e73a1dad120b5d44e29564de3ba794fb07ee886b30addfb19",
|
||||
"feed_menu": "318d8662dda5ca9dfc75b909c8461e79c86fb5082df1428f67aaf856f19f4b50",
|
||||
"icons": "3dbe754a98f524a227111191d76b8c6944711b13613cc548ee9e9808fe0bffb4",
|
||||
"item_meta": "a5b07cc6597e5c8f3ca849ee486acb3f16f062d8a1eaa47d2fb402ae6825b7ef",
|
||||
"item_meta": "a5b686c7af6348fdbd9a147e3fcfacc4a0b442c3b9637f3dce026ccf367fc312",
|
||||
"layout": "91d2ab3f683a2ced5e9ce5cd04919e74b3e3f329a5eedcc60015b8d49ecb1b77",
|
||||
"pagination": "7b61288e86283c4cf0dc83bcbf8bf1c00c7cb29e60201c8c0b633b2450d2911f",
|
||||
"settings_menu": "e2b777630c0efdbc529800303c01d6744ed3af80ec505ac5a5b3f99c9b989156",
|
||||
|
|
|
@ -65,6 +65,9 @@ func (e *Engine) Render(name, language string, data interface{}) []byte {
|
|||
"plural": func(key string, n int, args ...interface{}) string {
|
||||
return printer.Plural(key, n, args...)
|
||||
},
|
||||
"timeToRead": func(content string) int {
|
||||
return timeToRead(content)
|
||||
},
|
||||
})
|
||||
|
||||
var b bytes.Buffer
|
||||
|
|
|
@ -92,6 +92,9 @@ func (f *funcMap) Map() template.FuncMap {
|
|||
"plural": func(key string, n int, args ...interface{}) string {
|
||||
return ""
|
||||
},
|
||||
"timeToRead": func(content string) int {
|
||||
return 0
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -218,3 +221,9 @@ func formatFileSize(b int64) string {
|
|||
return fmt.Sprintf("%.1f %ciB",
|
||||
float64(b)/float64(div), "KMGTPE"[exp])
|
||||
}
|
||||
|
||||
func timeToRead(content string) int {
|
||||
nbOfWords := len(strings.Fields(content))
|
||||
|
||||
return int(math.Ceil(float64(nbOfWords) / 265))
|
||||
}
|
||||
|
|
|
@ -7,6 +7,13 @@
|
|||
<li>
|
||||
<time datetime="{{ isodate .entry.Date }}" title="{{ isodate .entry.Date }}">{{ elapsed .user.Timezone .entry.Date }}</time>
|
||||
</li>
|
||||
{{ if .user.ShowReadingTime }}
|
||||
<li>
|
||||
<span>
|
||||
{{ plural "entry.estimated_reading_time" (timeToRead .entry.Content) (timeToRead .entry.Content) }}
|
||||
</span>
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
<ul class="item-meta-icons">
|
||||
{{ if .entry.ShareCode }}
|
||||
|
|
|
@ -53,6 +53,8 @@
|
|||
<input type="number" name="entries_per_page" id="form-entries-per-page" value="{{ .form.EntriesPerPage }}" min="1">
|
||||
|
||||
<label><input type="checkbox" name="keyboard_shortcuts" value="1" {{ if .form.KeyboardShortcuts }}checked{{ end }}> {{ t "form.prefs.label.keyboard_shortcuts" }}</label>
|
||||
|
||||
<label><input type="checkbox" name="show_reading_time" value="1" {{ if .form.ShowReadingTime }}checked{{ end }}> {{ t "form.prefs.label.show_reading_time" }}</label>
|
||||
|
||||
<label>{{t "form.prefs.label.custom_css" }}</label><textarea name="custom_css" cols="40" rows="5">{{ .form.CustomCSS }}</textarea>
|
||||
<div class="buttons">
|
||||
|
|
|
@ -1324,6 +1324,8 @@ var templateViewsMap = map[string]string{
|
|||
<input type="number" name="entries_per_page" id="form-entries-per-page" value="{{ .form.EntriesPerPage }}" min="1">
|
||||
|
||||
<label><input type="checkbox" name="keyboard_shortcuts" value="1" {{ if .form.KeyboardShortcuts }}checked{{ end }}> {{ t "form.prefs.label.keyboard_shortcuts" }}</label>
|
||||
|
||||
<label><input type="checkbox" name="show_reading_time" value="1" {{ if .form.ShowReadingTime }}checked{{ end }}> {{ t "form.prefs.label.show_reading_time" }}</label>
|
||||
|
||||
<label>{{t "form.prefs.label.custom_css" }}</label><textarea name="custom_css" cols="40" rows="5">{{ .form.CustomCSS }}</textarea>
|
||||
<div class="buttons">
|
||||
|
@ -1568,7 +1570,7 @@ var templateViewsMapChecksums = map[string]string{
|
|||
"login": "79ff2ca488c0a19b37c8fa227a21f73e94472eb357a51a077197c852f7713f11",
|
||||
"search_entries": "c0786ddc6b17e865007b975eefb97417935cbc601f5917cca1ee0d3f584594bc",
|
||||
"sessions": "5d5c677bddbd027e0b0c9f7a0dd95b66d9d95b4e130959f31fb955b926c2201c",
|
||||
"settings": "3d6dd0d7fa0ca48cfd9a5edb43c055af8b816eb4460f16b71ae22db40ed9b754",
|
||||
"settings": "a4d3df17e6abc75881ec1ca5f92a9c2cfe24e3e08e5d844df848b4d6aaa1bbc0",
|
||||
"shared_entries": "1494d81e46f6af534a73cf6a91f8dfda1932a477bb3a70143513896ac0f0220b",
|
||||
"unread_entries": "e0080d0cf3583cda51d865422960137c8556c432853657086e43daf6bd5b73be",
|
||||
"users": "d7ff52efc582bbad10504f4a04fa3adcc12d15890e45dff51cac281e0c446e45",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue