~chrisppy/beagles

a83a8dc4aa8b98705f517f8e35addb5658f91d58 — Chris Palmer 24 days ago 013c748
Strip all possible HTML from content/description
2 files changed, 24 insertions(+), 14 deletions(-)

M db/db.go
M util/util.go
M db/db.go => db/db.go +14 -14
@@ 192,15 192,10 @@ func (s *Storage) Backup(path string) error {

	i := 0
	for k, v := range s.Feeds {
		d, err := util.StripHTML(v.Description)
		if err != nil {
			return err
		}

		f := barefeed.FeedV1{
			Feed:        k,
			Title:       v.Title,
			Description: d,
			Description: v.Description,
			Link:        v.Link,
			Items:       make([]barefeed.ItemV1, len(v.Items)),
		}


@@ 216,15 211,10 @@ func (s *Storage) Backup(path string) error {
			if !ok {
				return fmt.Errorf("database is out of sync")
			}
			c, err := util.StripHTML(val.Content)
			if err != nil {
				return nil
			}

			it := barefeed.ItemV1{
				Link:     k1,
				Title:    val.Title,
				Content:  c,
				Content:  val.Content,
				Read:     val.Read,
				Favorite: val.Favorite,
				Date:     barefeed.ToTimestamp(val.Date),


@@ 336,9 326,14 @@ func (s *Storage) Restore(path string) error {

func (s *Storage) processMessageV1(db *bolt.DB, msg *barefeed.MessageV1) error {
	for _, feed := range msg.Feeds {
		d, err := util.StripHTML(feed.Description)
		if err != nil {
			return err
		}

		f := Feed{
			Title:       feed.Title,
			Description: feed.Description,
			Description: d,
			UpdateURL:   feed.Feed,
			Link:        feed.Link,
			Items:       make(map[string]bool),


@@ 350,10 345,15 @@ func (s *Storage) processMessageV1(db *bolt.DB, msg *barefeed.MessageV1) error {
		}

		for _, item := range feed.Items {
			c, err := util.StripHTML(item.Content)
			if err != nil {
				return err
			}

			it := Item{
				FeedURL:  f.UpdateURL,
				Title:    item.Title,
				Content:  item.Content,
				Content:  c,
				Link:     item.Link,
				Date:     item.Date.Time(),
				Read:     item.Read,

M util/util.go => util/util.go +10 -0
@@ 28,6 28,7 @@ import (
	"os"
	"os/exec"
	"path/filepath"
	"regexp"
	"runtime"
	"strings"
	"time"


@@ 296,6 297,15 @@ func ExtPlay(path, bin string, args []string) {

// StripHTML from the included text
func StripHTML(text string) (string, error) {
	re, err := regexp.CompilePOSIX(`((<\/)[a-zA-Z0-9]+(>))`)
	if err != nil {
		return "", err
	}

	if f := re.FindString(text); f == "" {
		return text, nil
	}

	options := ht.Options{
		OmitLinks:           false,
		PrettyTables:        true,