本文整理匯總了Golang中github.com/urandom/readeef/content.User.ArticleById方法的典型用法代碼示例。如果您正苦於以下問題:Golang User.ArticleById方法的具體用法?Golang User.ArticleById怎麽用?Golang User.ArticleById使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/urandom/readeef/content.User
的用法示例。
在下文中一共展示了User.ArticleById方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: articleReadState
func articleReadState(user content.User, id data.ArticleId, read bool) (resp responseError) {
resp = newResponse()
article := user.ArticleById(id, data.ArticleQueryOptions{SkipProcessors: true})
if user.HasErr() {
resp.err = user.Err()
return
}
in := article.Data()
previouslyRead := in.Read
if previouslyRead != read {
article.Read(read)
if article.HasErr() {
resp.err = article.Err()
return
}
}
resp.val["Success"] = previouslyRead != read
resp.val["Read"] = read
resp.val["Id"] = in.Id
return
}
示例2: articleFavoriteState
func articleFavoriteState(user content.User, id data.ArticleId, favorite bool) (resp responseError) {
resp = newResponse()
article := user.ArticleById(id, data.ArticleQueryOptions{SkipProcessors: true})
if user.HasErr() {
resp.err = user.Err()
return
}
in := article.Data()
previouslyFavorite := in.Favorite
if previouslyFavorite != favorite {
article.Favorite(favorite)
if article.HasErr() {
resp.err = article.Err()
return
}
}
resp.val["Success"] = previouslyFavorite != favorite
resp.val["Favorite"] = favorite
resp.val["Id"] = in.Id
return
}
示例3: formatArticle
func formatArticle(user content.User, id data.ArticleId, webfwConfig webfw.Config, readeefConfig readeef.Config) (resp responseError) {
resp = newResponse()
article := user.ArticleById(id)
if user.HasErr() {
resp.err = user.Err()
return
}
formatting := article.Format(webfwConfig.Renderer.Dir, readeefConfig.ArticleFormatter.ReadabilityKey)
if article.HasErr() {
resp.err = user.Err()
return
}
s := summarize.NewFromString(formatting.Title, readeef.StripTags(formatting.Content))
s.Language = formatting.Language
keyPoints := s.KeyPoints()
for i := range keyPoints {
keyPoints[i] = html.UnescapeString(keyPoints[i])
}
resp.val["KeyPoints"] = keyPoints
resp.val["Content"] = formatting.Content
resp.val["TopImage"] = formatting.TopImage
resp.val["Id"] = id
return
}
示例4: markArticleAsFavorite
func markArticleAsFavorite(user content.User, id data.ArticleId, favorite bool) (resp responseError) {
resp = newResponse()
article := user.ArticleById(id)
if user.HasErr() {
resp.err = user.Err()
return
}
in := article.Data()
previouslyFavorite := in.Favorite
if previouslyFavorite != favorite {
article.Favorite(favorite)
if article.HasErr() {
resp.err = article.Err()
return
}
}
resp.val["Success"] = previouslyFavorite != favorite
resp.val["Favorite"] = favorite
resp.val["Id"] = in.Id
return
}
示例5: markArticleAsRead
func markArticleAsRead(user content.User, id data.ArticleId, read bool) (resp responseError) {
resp = newResponse()
article := user.ArticleById(id)
if user.HasErr() {
resp.err = user.Err()
return
}
in := article.Data()
previouslyRead := in.Read
if previouslyRead != read {
article.Read(read)
if article.HasErr() {
resp.err = article.Err()
return
}
}
resp.val["Success"] = previouslyRead != read
resp.val["Read"] = read
resp.val["Id"] = in.Id
return
}
示例6: fetchArticle
func fetchArticle(user content.User, id data.ArticleId) (resp responseError) {
resp = newResponse()
article := user.ArticleById(id)
if user.HasErr() {
resp.err = user.Err()
return
}
resp.val["Article"] = article
return
}
示例7: formatArticle
func formatArticle(user content.User, id data.ArticleId, extractor content.Extractor, webfwConfig webfw.Config, readeefConfig readeef.Config) (resp responseError) {
resp = newResponse()
article := user.ArticleById(id)
if user.HasErr() {
resp.err = user.Err()
return
}
extract := article.Extract()
if article.HasErr() {
resp.err = article.Err()
return
}
extractData := extract.Data()
if extract.HasErr() {
switch err := extract.Err(); err {
case content.ErrNoContent:
if extractor == nil {
resp.err = fmt.Errorf("Error formatting article: A valid extractor is reequired")
return
}
extractData, resp.err = extractor.Extract(article.Data().Link)
if resp.err != nil {
return
}
extractData.ArticleId = article.Data().Id
extract.Data(extractData)
extract.Update()
if extract.HasErr() {
resp.err = extract.Err()
return
}
default:
resp.err = err
return
}
}
processors := user.Repo().ArticleProcessors()
if len(processors) > 0 {
a := user.Repo().UserArticle(user)
a.Data(data.Article{Description: extractData.Content})
ua := []content.UserArticle{a}
if extractData.TopImage != "" {
a = user.Repo().UserArticle(user)
a.Data(data.Article{
Description: fmt.Sprintf(`<img src="%s">`, extractData.TopImage),
})
ua = append(ua, a)
}
for _, p := range processors {
ua = p.ProcessArticles(ua)
}
extractData.Content = ua[0].Data().Description
if extractData.TopImage != "" {
content := ua[1].Data().Description
content = strings.Replace(content, `<img src="`, "", -1)
i := strings.Index(content, `"`)
content = content[:i]
extractData.TopImage = content
}
}
s := summarize.NewFromString(extractData.Title, search.StripTags(extractData.Content))
s.Language = extractData.Language
keyPoints := s.KeyPoints()
for i := range keyPoints {
keyPoints[i] = html.UnescapeString(keyPoints[i])
}
resp.val["KeyPoints"] = keyPoints
resp.val["Content"] = extractData.Content
resp.val["TopImage"] = extractData.TopImage
resp.val["Id"] = id
return
}
示例8: Handler
//.........這裏部分代碼省略.........
links[i] = link
}
resp["links"] = links
}
if val := r.PostFormValue("unread_recently_read"); val == "1" {
reqType = "unread and recently read"
logger.Infoln("Marking recently read fever items as unread")
t := time.Now().Add(-24 * time.Hour)
user.ReadState(false, data.ArticleUpdateStateOptions{
BeforeDate: time.Now(),
AfterDate: t,
})
err = user.Err()
if err != nil {
break
}
}
if val := r.PostFormValue("mark"); val != "" {
if val == "item" {
logger.Infof("Marking fever item '%s' as '%s'\n", r.PostFormValue("id"), r.PostFormValue("as"))
var id int64
var article content.UserArticle
id, err = strconv.ParseInt(r.PostFormValue("id"), 10, 64)
if err != nil {
break
}
article, err = user.ArticleById(data.ArticleId(id), data.ArticleQueryOptions{SkipSessionProcessors: true}), user.Err()
if err != nil {
break
}
switch r.PostFormValue("as") {
case "read":
article.Read(true)
case "saved":
article.Favorite(true)
case "unsaved":
article.Favorite(false)
default:
err = errors.New("Unknown 'as' action")
}
if err == nil {
err = article.Err()
}
} else if val == "feed" || val == "group" {
logger.Infof("Marking fever %s '%s' as '%s'\n", val, r.PostFormValue("id"), r.PostFormValue("as"))
if r.PostFormValue("as") != "read" {
err = errors.New("Unknown 'as' action")
break
}
var id, timestamp int64
id, err = strconv.ParseInt(r.PostFormValue("id"), 10, 64)
if err != nil {
break
}
timestamp, err = strconv.ParseInt(r.PostFormValue("before"), 10, 64)