mirror of
https://github.com/nkanaev/yarr.git
synced 2025-05-24 00:33:14 +00:00
switch to server-side readability
This commit is contained in:
parent
a83d43a5b1
commit
485587825c
2
src/assets/javascripts/Readability.min.js
vendored
2
src/assets/javascripts/Readability.min.js
vendored
File diff suppressed because one or more lines are too long
@ -102,9 +102,7 @@
|
||||
return api('post', './logout')
|
||||
},
|
||||
crawl: function(url) {
|
||||
return xfetch('./page?url=' + url).then(function(res) {
|
||||
return res.text()
|
||||
})
|
||||
return api('post', './page?url=' + url).then(json)
|
||||
}
|
||||
}
|
||||
})()
|
||||
|
@ -612,15 +612,9 @@ var vm = new Vue({
|
||||
}
|
||||
if (item.link) {
|
||||
this.loading.readability = true
|
||||
api.crawl(item.link).then(function(body) {
|
||||
api.crawl(item.link).then(function(data) {
|
||||
vm.itemSelectedReadability = data && data.content
|
||||
vm.loading.readability = false
|
||||
if (!body.length) return
|
||||
var bodyClean = sanitize(body, item.link)
|
||||
var doc = new DOMParser().parseFromString(bodyClean, 'text/html')
|
||||
var parsed = new Readability(doc).parse()
|
||||
if (parsed && parsed.content) {
|
||||
vm.itemSelectedReadability = parsed.content
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
|
@ -2,7 +2,6 @@ package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math"
|
||||
"net/http"
|
||||
@ -12,6 +11,7 @@ import (
|
||||
"github.com/nkanaev/yarr/src/auth"
|
||||
"github.com/nkanaev/yarr/src/opml"
|
||||
"github.com/nkanaev/yarr/src/router"
|
||||
"github.com/nkanaev/yarr/src/scraper"
|
||||
"github.com/nkanaev/yarr/src/storage"
|
||||
"github.com/nkanaev/yarr/src/worker"
|
||||
)
|
||||
@ -389,16 +389,32 @@ func (s *Server) handleOPMLExport(c *router.Context) {
|
||||
}
|
||||
|
||||
func (s *Server) handlePageCrawl(c *router.Context) {
|
||||
query := c.Req.URL.Query()
|
||||
if url := query.Get("url"); len(url) > 0 {
|
||||
if c.Req.Method != "POST" {
|
||||
c.Out.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
url := c.Req.URL.Query().Get("url")
|
||||
if url == "" {
|
||||
c.Out.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
res, err := http.Get(url)
|
||||
if err == nil {
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
if err == nil {
|
||||
c.Out.Write(body)
|
||||
}
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
c.Out.WriteHeader(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
defer res.Body.Close()
|
||||
content, err := scraper.ExtractContent(res.Body)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
c.Out.WriteHeader(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
content = scraper.Sanitize(url, content)
|
||||
c.JSON(http.StatusOK, map[string]string{
|
||||
"content": content,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Server) handleLogout(c *router.Context) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user