Пример #1
0
func getAtomFeed(res http.ResponseWriter, req *http.Request) {
	feed := atom.Feed{
		Title:   "",
		Updated: atom.Time(time.Now()),
	}
	limit, err := strconv.Atoi(req.URL.Query().Get("limit"))
	if err != nil {
		limit = 100
	}
	alerts, err := qcap.GetAlerts(limit)
	if err != nil {
		log.Panic("Error retrieving alerts:", err)
	}
	for _, a := range alerts {
		t := atom.Time(a.Id.Time())
		id := a.Id.Hex()
		e := atom.Entry{
			Title:     fmt.Sprint("Alert ", id),
			ID:        id,
			Published: t,
			Updated:   t,
			Link: []atom.Link{
				atom.Link{Rel: "self", Href: qcapBaseUrl + xmlEndpoint + "/alerts/" + id},
			},
		}
		feed.Entry = append(feed.Entry, &e)
	}
	r.XML(res, http.StatusOK, feed)
}
Пример #2
0
func (c Feed) BuildFeed(feedID, user string) ([]byte, error) {
	repos, err := c.StarredRepositories(user)
	if err != nil {
		return nil, err
	}
	releases, err := c.Releases(repos)
	if err != nil {
		return nil, err
	}

	sort.Sort(sort.Reverse(ByDate(releases)))

	var entries []*atom.Entry
	for _, release := range releases {
		entries = append(entries, &atom.Entry{
			Title:     release.Title(),
			ID:        feedID + "/" + strconv.Itoa(*release.ID),
			Updated:   atom.Time(release.PublishedAt.Time),
			Published: atom.Time(release.PublishedAt.Time),
			Author: &atom.Person{
				Name: release.Releaser(),
			},
			Link: []atom.Link{{
				Rel:  "alternate",
				Href: *release.HTMLURL,
			}},
			Content: &atom.Text{
				Type: "html",
				Body: release.SanitisedBody(),
			},
		})
	}

	feed := atom.Feed{
		Title:   fmt.Sprintf("Starred Github Releases for %s", user),
		ID:      feedID,
		Updated: atom.Time(time.Now()),
		Entry:   entries,
		Link: []atom.Link{{
			Rel:  "self",
			Href: feedID,
		}},
	}
	b, err := xml.Marshal(&feed)
	if err != nil {
		return nil, err
	}
	return b, nil
}
Пример #3
0
// renderAtomFeed generates an XML Atom feed and stores it in the Server's
// atomFeed field.
func (s *Server) renderAtomFeed() error {
	var updated time.Time
	if len(s.docs) > 0 {
		updated = s.docs[0].Time
	}
	feed := atom.Feed{
		Title:   s.cfg.FeedTitle,
		ID:      "tag:" + s.cfg.Hostname + ",2015:" + s.cfg.Hostname,
		Updated: atom.Time(updated),
		Link: []atom.Link{{
			Rel:  "self",
			Href: s.cfg.BaseURL + "/feed.atom",
		}},
	}
	for i, doc := range s.docs {
		if i >= s.cfg.FeedArticles {
			break
		}
		e := &atom.Entry{
			Title: doc.Title,
			ID:    feed.ID + doc.Path,
			Link: []atom.Link{{
				Rel:  "alternate",
				Href: doc.Permalink,
			}},
			Published: atom.Time(doc.Time),
			Updated:   atom.Time(doc.Time),
			Summary: &atom.Text{
				Type: "html",
				Body: summary(doc),
			},
			Content: &atom.Text{
				Type: "html",
				Body: string(doc.HTML),
			},
			Author: &atom.Person{
				Name: authors(doc.Authors),
			},
		}
		feed.Entry = append(feed.Entry, e)
	}
	data, err := xml.Marshal(&feed)
	if err != nil {
		return err
	}
	s.atomFeed = data
	return nil
}
Пример #4
0
func createAtomFeed(filename string, posts []*Post) (err error) {
	feed := atom.Feed{
		Title: "Will Roe's blog",
	}
	for _, p := range posts {
		var t time.Time
		t, err = p.Date()
		if err != nil {
			fmt.Printf("Error getting date of post: %v\n", p)
			break
		}
		e := &atom.Entry{
			Title:     p.Title,
			Published: atom.Time(t),
		}
		feed.Entry = append(feed.Entry, e)
	}

	var data []byte
	data, err = xml.Marshal(&feed)
	if err != nil {
		fmt.Printf("Failed to marshal the feed: %s", err)
		os.Exit(1)
	}
	writeFile(string(data[:]), filename)
	return
}
Пример #5
0
//GetRSS get rss object in atom format
func GetRSS() (interface{}, error) {
	r, err := storage.Get()
	if err != nil {
		return nil, err
	}
	if len(r.Content) == 0 {
		return nil, waitErr
	}

	//sorted by time
	sort.Sort(r)

	//Init a common infos
	feed := &atom.Feed{
		Title: "Tw's blog",
		Link:  []atom.Link{atom.Link{Href: "/rss"}},
		ID:    "/rss",
		Author: &atom.Person{
			Name:  "Tw",
			Email: "*****@*****.**",
		},
		//use the newest post time
		Updated: atom.Time(r.Content[0].Date()),
	}

	//fill the entries
	feed.Entry = make([]*atom.Entry, len(r.Content))
	for i := range feed.Entry {
		p := r.Content[i]
		feed.Entry[i] = &atom.Entry{
			Title:   string(p.Title()),
			ID:      p.Key(),
			Updated: atom.Time(p.Date()),
			Link:    []atom.Link{atom.Link{Href: "/posts/" + p.Key()}},
			Content: &atom.Text{Body: string(p.Content()), Type: "html"},
		}
	}
	return feed, nil
}