Exemplo n.º 1
0
func (item *FeedItem) getItem() *feeds.Item {
	var out feeds.Item

	out.Created = item.LastActive
	out.Title = item.Title
	out.Link = &feeds.Link{Href: item.Address}
	out.Description = item.description

	return &out
}
Exemplo n.º 2
0
func compileRSS(ctx *Context) error {
	// todo : should compile RSS if no posts ?
	toDir := ctx.DstDir()
	now := time.Now()
	feed := &feeds.Feed{
		Title:       ctx.Source.Meta.Title,
		Link:        &feeds.Link{Href: ctx.Source.Meta.Root},
		Description: ctx.Source.Meta.Desc,
		Created:     now,
	}
	if ctx.Source.Owner != nil {
		feed.Author = &feeds.Author{
			Name:  ctx.Source.Owner.Nick,
			Email: ctx.Source.Owner.Email,
		}
	}
	var item *feeds.Item
	for _, p := range ctx.Source.Posts {
		item = &feeds.Item{
			Title:       p.Title,
			Link:        &feeds.Link{Href: ctx.Source.Meta.DomainURL(p.URL())},
			Description: string(p.Content()),
			Created:     p.Created(),
			Updated:     p.Updated(),
		}
		if p.Author != nil {
			item.Author = &feeds.Author{
				Name:  p.Author.Nick,
				Email: p.Author.Email,
			}
		}
		feed.Items = append(feed.Items, item)
	}

	dstFile := path.Join(toDir, ctx.Source.Meta.Path, "feed.xml")
	os.MkdirAll(filepath.Dir(dstFile), os.ModePerm)
	f, err := os.OpenFile(dstFile, os.O_CREATE|os.O_TRUNC|os.O_RDWR, os.ModePerm)
	if err != nil {
		return err
	}
	defer f.Close()
	if err = feed.WriteRss(f); err != nil {
		return err
	}
	ctx.Sync.SetSynced(dstFile)
	log15.Debug("Build|%s", dstFile)
	atomic.AddInt64(&ctx.counter, 1)
	return nil
}
Exemplo n.º 3
0
func augmentItemHTML(item *feeds.Item, body *string) {
	doc, err := html.Parse(strings.NewReader(*body))
	if err != nil {
		// TODO: pass url in for error logging?  return err?
		log.Printf("unable to parse the body: %s", err)
	}
	item.Title = getHTMLTitle(doc)
	// TODO - snippet of html body in description
}
Exemplo n.º 4
0
func Feed(context *GoInk.Context) {
	baseUrl := model.GetSetting("site_url")
	article, _ := model.GetArticleList(1, 20)
	feed := new(feeds.Feed)
	feed.Title = model.GetSetting("site_title")
	feed.Link = &feeds.Link{Href: baseUrl}
	feed.Description = model.GetSetting("site_description")
	author := model.GetUsersByRole("ADMIN")[0]
	feed.Author = &feeds.Author{author.Nick, author.Email}
	feed.Items = make([]*feeds.Item, 0)
	var create int64
	if len(article) > 0 {
		create = article[0].EditTime
	} else {
		create = utils.Now()
	}
	feed.Created = time.Unix(create, 0)
	for _, a := range article {
		item := new(feeds.Item)
		item.Title = a.Title
		item.Link = &feeds.Link{Href: path.Join(baseUrl, a.Link())}
		item.Author = feed.Author
		item.Created = time.Unix(a.CreateTime, 0)
		item.Description = utils.Html2str(a.Summary())
		feed.Items = append(feed.Items, item)
	}
	str, e := feed.ToRss()
	if e != nil {
		panic(e)
	}
	context.ContentType("application/rss+xml;charset=UTF-8")
	context.Body = []byte(str)
}
Exemplo n.º 5
0
//DispatchRSS returns the rss feed of namespace
func DispatchRSS(w http.ResponseWriter, r *http.Request) {
	con := data.MakeContext(r)

	w.Header().Set("Content-Type", "application/rss+xml")
	w.Header().Set("Cache-Control", "public, max-age=1800") // 30 minutes
	w.Header().Set("Pragma", "Public")

	// get namespace
	namespace := mux.Vars(r)["namespace"]
	if namespace == "" {
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	cache, err := data.ReadRSSCache(con, namespace)
	if err == nil {
		w.Write([]byte(cache))
		return
	}
	if err == memcache.ErrCacheMiss {
		con.Log.Infof("Cache miss for namespace %v", namespace)
	} else {
		con.Log.Errorf("Error at in rss.dispatch while reading the cache. Error: %v", err)
	}

	t := time.Now()
	t = t.Add(-24 * time.Hour * config.RSSTimeRangeinDays)
	is, _, err := data.GetNewestItemsByTime(con, namespace, 100, t, "")
	if err != nil {
		con.Log.Errorf("Error at in rss.dispatch @ GetNewestItem. Error: %v", err)
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	con.Log.Infof("items: %v", is)

	feed := &feeds.Feed{
		Title: namespace + " - Kaffeeshare",
		Link:  &feeds.Link{Href: r.URL.String()},
	}

	for _, i := range is {
		rssI := feeds.Item{
			Title:   i.Caption,
			Link:    &feeds.Link{Href: i.URL},
			Created: i.CreatedAt,
		}

		if i.ImageURL != "" {
			rssI.Description += "<div style=\"float:left; margin-right:16px; margin-bottom:16px;\"><img width=\"200\" src=\"" + i.ImageURL + "\" alt=\"\"/></div>"
		}

		rssI.Description += "<p>" + i.Description + "</p><br/><br/>"
		rssI.Description += "<a href=\"" + i.URL + "\">&raquo; " + i.URL + "</a>"

		feed.Items = append(feed.Items, &rssI)
	}

	s, err := feed.ToRss()
	if err != nil {
		con.Log.Errorf("Error at mashaling in www.dispatch. Error: %v", err)
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	if err := data.CacheRSS(con, namespace, s); err != nil {
		con.Log.Errorf("Error at storing the RSS Feed in the cache. Error: %v", err)
	}

	w.Write([]byte(s))
}