aboutsummaryrefslogtreecommitdiff
path: root/jsonfeed/jsonfeed.go
blob: 913880dd779c0e7bbbd35d6a1214995038646b88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/

package jsonfeed

import (
	"encoding/json"
	"io"
	"time"
)

const CurrentVersion = "https://jsonfeed.org/version/1"

type Item struct {
	ID            string    `json:"id"`
	URL           string    `json:"url"`
	ExternalURL   string    `json:"external_url"`
	Title         string    `json:"title"`
	ContentHTML   string    `json:"content_html"`
	ContentText   string    `json:"content_text"`
	Summary       string    `json:"summary"`
	Image         string    `json:"image"`
	BannerImage   string    `json:"banner_image"`
	DatePublished time.Time `json:"date_published"`
	DateModified  time.Time `json:"date_modified"`
	Author        Author    `json:"author"`
	Tags          []string  `json:"tags"`
}

type Author struct {
	Name   string `json:"name"`
	URL    string `json:"url"`
	Avatar string `json:"avatar"`
}

type Hub struct {
	Type string `json:"type"`
	URL  string `json:"url"`
}

type Attachment struct {
	URL               string `json:"url"`
	MIMEType          string `json:"mime_type"`
	Title             string `json:"title"`
	SizeInBytes       int64  `json:"size_in_bytes"`
	DurationInSeconds int64  `json:"duration_in_seconds"`
}

type Feed struct {
	Version     string `json:"version"`
	Title       string `json:"title"`
	HomePageURL string `json:"home_page_url"`
	FeedURL     string `json:"feed_url"`
	Description string `json:"description"`
	UserComment string `json:"user_comment"`
	NextURL     string `json:"next_url"`
	Icon        string `json:"icon"`
	Favicon     string `json:"favicon"`
	Author      Author `json:"author"`
	Expired     bool   `json:"expired"`
	Hubs        []Hub  `json:"hubs"`
	Items       []Item `json:"items"`
}

func Parse(r io.Reader) (Feed, error) {
	var feed Feed
	decoder := json.NewDecoder(r)
	if err := decoder.Decode(&feed); err != nil {
		return Feed{}, err
	}
	return feed, nil
}