From d256564c435c5cef02262fb64fb2bddcd38c05a1 Mon Sep 17 00:00:00 2001 From: Adam Mathes Date: Tue, 21 Nov 2017 15:13:15 -0700 Subject: add full view toggle kb shortcut --- models/item/item.go | 25 +++++++++++++++++++++---- static/ui.js | 16 +++++++++++++--- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/models/item/item.go b/models/item/item.go index 48d76bf..ebc1214 100644 --- a/models/item/item.go +++ b/models/item/item.go @@ -70,16 +70,33 @@ func (i *Item) FullSave() { func (i *Item) GetFullContent() { g := goose.New() article, err := g.ExtractFromURL(i.Url) + if err != nil { + log.Println(err) + return + } + + if article.TopNode == nil { + return + } + var md, img string md = "" img = "" + md = string(blackfriday.MarkdownCommon([]byte(article.CleanedText))) + + ht, err := article.TopNode.Html() if err != nil { - log.Println(err) - } else { - md = string(blackfriday.MarkdownCommon([]byte(article.CleanedText))) - img = article.TopImage + return } + p := bluemonday.NewPolicy() + p.AllowElements("blockquote", "a", "img", "p", "h1", "h2", "h3", "h4", "b", "i", "em", "strong") + p.AllowAttrs("href").OnElements("a") + p.AllowAttrs("src", "alt").OnElements("img") + md = p.Sanitize(ht) + + img = article.TopImage + _, err = models.DB.Exec(`UPDATE item SET full_content=?, header_image=? WHERE id=?`, md, img, i.Id) diff --git a/static/ui.js b/static/ui.js index 4f9305c..4df0550 100644 --- a/static/ui.js +++ b/static/ui.js @@ -109,10 +109,17 @@ var AppModel = Backbone.Model.extend({ }, star: function() { - if(this.get('selectedIndex') > 0) { + if(this.get('selectedIndex') >= 0) { App.items.at(this.get('selectedIndex')).toggleStar(); } + }, + + full: function() { + if(this.get('selectedIndex') >= 0) { + App.items.at(this.get('selectedIndex')).full(); + } } + }); var App = new AppModel(); @@ -206,7 +213,7 @@ var Item = Backbone.Model.extend({ }, full: function() { - this.set({'full': true}); + this.set({'full': !(this.get('full'))} ); } }); @@ -544,7 +551,10 @@ function boot() { event.preventDefault(); App.star(); } - + if (event.which == 70) { + event.preventDefault(); + App.full(); + } }); App.boot(); -- cgit v1.2.3