FetchMatchedExcerpt returns the matched excerpt according to the words
(html string, words []string, trimMarker string, trimLength int)
| 172 | |
| 173 | // FetchMatchedExcerpt returns the matched excerpt according to the words |
| 174 | func FetchMatchedExcerpt(html string, words []string, trimMarker string, trimLength int) string { |
| 175 | text := ClearText(html) |
| 176 | matchedWord, matchedIndex := findFirstMatchedWord(text, words) |
| 177 | runeIndex := utf8.RuneCountInString(text[0:matchedIndex]) |
| 178 | |
| 179 | trimLength = max(0, trimLength) |
| 180 | runeOffset := runeIndex - trimLength |
| 181 | runeLimit := trimLength + trimLength + utf8.RuneCountInString(matchedWord) |
| 182 | |
| 183 | textRuneCount := utf8.RuneCountInString(text) |
| 184 | if runeOffset+runeLimit > textRuneCount { |
| 185 | // Reserved extra chars before the matched word |
| 186 | runeOffset = textRuneCount - runeLimit |
| 187 | } |
| 188 | |
| 189 | return FetchRangedExcerpt(html, trimMarker, runeOffset, runeLimit) |
| 190 | } |
| 191 | |
| 192 | func GetPicByUrl(url string) string { |
| 193 | res, err := http.Get(url) |