mirror of
https://github.com/nkanaev/yarr.git
synced 2025-05-24 21:19:19 +00:00
Compare commits
3 Commits
b09c95d7ea
...
5254df53dc
Author | SHA1 | Date | |
---|---|---|---|
|
5254df53dc | ||
|
7301eab99c | ||
|
ad138c3017 |
@ -15,6 +15,7 @@
|
|||||||
- (fix) error caused by missing config dir (thanks to @timster)
|
- (fix) error caused by missing config dir (thanks to @timster)
|
||||||
- (etc) load external images with no-referrer policy (thanks to @tillcash for the report)
|
- (etc) load external images with no-referrer policy (thanks to @tillcash for the report)
|
||||||
- (etc) open external links with no-referrer policy (thanks to @donovanglover)
|
- (etc) open external links with no-referrer policy (thanks to @donovanglover)
|
||||||
|
- (etc) show article content in the list if title is missing (thanks to @asimpson for suggestion)
|
||||||
|
|
||||||
# v2.4 (2023-08-15)
|
# v2.4 (2023-08-15)
|
||||||
|
|
||||||
|
@ -62,3 +62,7 @@
|
|||||||
- site: https://juliepowell.blogspot.com/
|
- site: https://juliepowell.blogspot.com/
|
||||||
feed: https://juliepowell.blogspot.com/feeds/posts/default
|
feed: https://juliepowell.blogspot.com/feeds/posts/default
|
||||||
tags: [blogger, text]
|
tags: [blogger, text]
|
||||||
|
|
||||||
|
- site: https://micro.blog/val
|
||||||
|
feed: https://micro.blog/posts/val
|
||||||
|
tags: [json, microblog]
|
||||||
|
@ -330,10 +330,10 @@
|
|||||||
<span class="icon">{% inline "external-link.svg" %}</span>
|
<span class="icon">{% inline "external-link.svg" %}</span>
|
||||||
</a>
|
</a>
|
||||||
<div class="flex-grow-1"></div>
|
<div class="flex-grow-1"></div>
|
||||||
<button class="toolbar-item" @click="navigateToItem(-1)" title="Previous Article">
|
<button class="toolbar-item" @click="navigateToItem(-1)" title="Previous Article" :disabled="itemSelected == items[0].id">
|
||||||
<span class="icon">{% inline "chevron-left.svg" %}</span>
|
<span class="icon">{% inline "chevron-left.svg" %}</span>
|
||||||
</button>
|
</button>
|
||||||
<button class="toolbar-item" @click="navigateToItem(+1)" title="Next Article">
|
<button class="toolbar-item" @click="navigateToItem(+1)" title="Next Article" :disabled="itemSelected == items[items.length - 1].id">
|
||||||
<span class="icon">{% inline "chevron-right.svg" %}</span>
|
<span class="icon">{% inline "chevron-right.svg" %}</span>
|
||||||
</button>
|
</button>
|
||||||
<button class="toolbar-item" @click="itemSelected=null" title="Close Article">
|
<button class="toolbar-item" @click="itemSelected=null" title="Close Article">
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"unicode"
|
||||||
|
|
||||||
"golang.org/x/net/html"
|
"golang.org/x/net/html"
|
||||||
)
|
)
|
||||||
@ -61,3 +62,16 @@ func ExtractText(content string) string {
|
|||||||
text = whitespaceRegex.ReplaceAllLiteralString(text, " ")
|
text = whitespaceRegex.ReplaceAllLiteralString(text, " ")
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TruncateText(input string, size int) string {
|
||||||
|
runes := []rune(input)
|
||||||
|
if len(runes) <= size {
|
||||||
|
return input
|
||||||
|
}
|
||||||
|
for i := size - 1; i > 0; i-- {
|
||||||
|
if unicode.IsSpace(runes[i]) {
|
||||||
|
return string(runes[:i]) + " ..."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return input
|
||||||
|
}
|
||||||
|
@ -24,3 +24,21 @@ func TestExtractText(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTruncateText(t *testing.T) {
|
||||||
|
input := "Lorem ipsum — классический текст-«рыба»"
|
||||||
|
|
||||||
|
size := 30
|
||||||
|
want := "Lorem ipsum — классический ..."
|
||||||
|
have := TruncateText(input, size)
|
||||||
|
if want != have {
|
||||||
|
t.Errorf("\nsize: %d\nwant: %#v\nhave: %#v", size, want, have)
|
||||||
|
}
|
||||||
|
|
||||||
|
size = 1000
|
||||||
|
want = input
|
||||||
|
have = TruncateText(input, size)
|
||||||
|
if want != have {
|
||||||
|
t.Errorf("\nsize: %d\nwant: %#v\nhave: %#v", size, want, have)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -371,12 +371,19 @@ func (s *Server) handleItemList(c *router.Context) {
|
|||||||
}
|
}
|
||||||
newestFirst := query.Get("oldest_first") != "true"
|
newestFirst := query.Get("oldest_first") != "true"
|
||||||
|
|
||||||
items := s.db.ListItems(filter, perPage+1, newestFirst, false)
|
items := s.db.ListItems(filter, perPage+1, newestFirst, true)
|
||||||
hasMore := false
|
hasMore := false
|
||||||
if len(items) == perPage+1 {
|
if len(items) == perPage+1 {
|
||||||
hasMore = true
|
hasMore = true
|
||||||
items = items[:perPage]
|
items = items[:perPage]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for i, item := range items {
|
||||||
|
if item.Title == "" {
|
||||||
|
text := htmlutil.ExtractText(item.Content)
|
||||||
|
items[i].Title = htmlutil.TruncateText(text, 140)
|
||||||
|
}
|
||||||
|
}
|
||||||
c.JSON(http.StatusOK, map[string]interface{}{
|
c.JSON(http.StatusOK, map[string]interface{}{
|
||||||
"list": items,
|
"list": items,
|
||||||
"has_more": hasMore,
|
"has_more": hasMore,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user