Skip to content

Commit 4be73f9

Browse files
committed
Workaround that SpeakerDeck removed the talk date from the user page
1 parent 193f51e commit 4be73f9

File tree

2 files changed

+4
-29
lines changed

2 files changed

+4
-29
lines changed

types.go

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type User struct {
1919

2020
// TalkPreviews is a list of TalkPreview objects, containing information about each talk
2121
// as seen on the user page
22-
TalkPreviews TalkPreviews `json:"talkPreviews"`
22+
TalkPreviews []TalkPreview `json:"talkPreviews"`
2323
}
2424

2525
// Author describes the SD profile of the person that's created the presentations
@@ -53,9 +53,6 @@ type TalkPreview struct {
5353
// Stars describes how many other users have starred this talk
5454
Stars uint32 `json:"stars"`
5555

56-
// Date represents the talk presentation date
57-
Date time.Time `json:"date"`
58-
5956
// Link describes the link to the talk at Speakerdeck
6057
Link string `json:"link"`
6158

@@ -75,6 +72,9 @@ type Talk struct {
7572
// TalkPreview is embedded here as it contains all the data we want to display here, too
7673
TalkPreview
7774

75+
// Date represents the talk presentation date
76+
Date time.Time `json:"date"`
77+
7878
// Author describes the Speakerdeck profile of the person that's created the presentations
7979
Author Author `json:"author"`
8080

@@ -124,24 +124,6 @@ func (p Talks) Swap(i, j int) {
124124
p[i], p[j] = p[j], p[i]
125125
}
126126

127-
// TalkPreviews orders the TalkPreview objects by time
128-
type TalkPreviews []TalkPreview
129-
130-
// Len implements sort.Interface
131-
func (p TalkPreviews) Len() int {
132-
return len(p)
133-
}
134-
135-
// Less implements sort.Interface
136-
func (p TalkPreviews) Less(i, j int) bool {
137-
return p[i].Date.Before(p[j].Date)
138-
}
139-
140-
// Swap implements sort.Interface
141-
func (p TalkPreviews) Swap(i, j int) {
142-
p[i], p[j] = p[j], p[i]
143-
}
144-
145127
// Location describes a geographical location for the talk
146128
// This struct is populated by the LocationExtension, and is set based on
147129
// a "Location: <address>" string in the talk description. For instance,

user.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package speakerdeck
33
import (
44
"fmt"
55
"path"
6-
"sort"
76

87
"github.com/gocolly/colly"
98
"github.com/luxas/speakerdeck-api/scraper"
@@ -23,7 +22,6 @@ func ScrapeUser(userHandle string, opts *scraper.ScrapeOptions) (*User, error) {
2322
return nil, err
2423
}
2524
user := data.(*User)
26-
sort.Sort(user.TalkPreviews)
2725
return user, nil
2826
}
2927

@@ -85,10 +83,6 @@ func onUserAbstract(e *colly.HTMLElement, data interface{}) (*string, error) {
8583
func onUserTalkFound(e *colly.HTMLElement, data interface{}) (*string, error) {
8684
u := data.(*User)
8785

88-
d, err := parseDate(e.ChildText(".deck-preview-meta > :nth-child(1)"))
89-
if err != nil {
90-
return nil, err
91-
}
9286
stars, err := parseNumber(e.ChildText(".deck-preview-meta > :nth-child(2)"))
9387
if err != nil {
9488
return nil, err
@@ -102,7 +96,6 @@ func onUserTalkFound(e *colly.HTMLElement, data interface{}) (*string, error) {
10296
Title: e.Attr("title"),
10397
Link: sdPrefix(e.Attr("href")),
10498
DataID: e.ChildAttr("div.deck-preview", "data-id"),
105-
Date: d,
10699
Views: views,
107100
Stars: stars,
108101
}

0 commit comments

Comments
 (0)