Skip to content

Commit af35bbc

Browse files
committed
docs: update twitter example
1 parent 9e64317 commit af35bbc

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

examples/twitter/index.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,30 @@ module.exports = async ({ query }) => {
3131
attr: 'text'
3232
}
3333
},
34-
tweetsIds: {
34+
tweets: {
3535
selectors: {
36-
selector: 'ol > li a',
37-
attr: 'data-conversation-id'
38-
}
39-
},
40-
tweetsText: {
41-
selectors: {
42-
selector: 'ol > li p',
43-
attr: 'text'
36+
selector: 'ol > li',
37+
attr: {
38+
id: {
39+
selector: '.tweet-timestamp',
40+
attr: 'data-conversation-id',
41+
type: value => `https://twitter.com/${value}`
42+
},
43+
text: {
44+
selector: '.tweet-text',
45+
attr: 'text'
46+
},
47+
tweetUrl: {
48+
selector: '.tweet-timestamp',
49+
attr: 'href'
50+
}
51+
}
4452
}
4553
}
4654
}
4755
})
4856

49-
const { tweetsIds, tweetsText, bio, name, avatarUrl } = data
50-
51-
const tweets = tweetsIds.map((id, index) => ({
52-
id,
53-
text: tweetsText[index]
54-
}))
57+
const { tweets, bio, name, avatarUrl } = data
5558

5659
const [pinnedTweet, ...restTweets] = tweets
5760

0 commit comments

Comments
 (0)