-
Notifications
You must be signed in to change notification settings - Fork 0
/
recent.11ty.js
42 lines (37 loc) · 1.08 KB
/
recent.11ty.js
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
const Twitter = require("./src/twitter");
const dataSource = require("./src/DataSource");
class Recent extends Twitter {
data() {
return {
layout: "layout.11ty.js"
};
}
getRecentTweets(tweets) {
return tweets.filter(tweet => this.isOriginalPost(tweet)).sort(function(a,b) {
return b.date - a.date;
}).slice(0, 40);
}
async render(data) {
let tweets = await dataSource.getAllTweets();
let tweetHtml = await Promise.all(this.getRecentTweets(tweets).map(tweet => this.renderTweet(tweet, {showSentiment: true})));
return `<h2>Most Recent 40 Tweets</h2>
<p>Not including replies or retweets or mentions.</p>
<h3>Mood</h3>
<div class="twtr-sentiment js">
<div class="twtr-sentiment-chart ct-chart"></div>
<div class="twtr-sentiment-label">
⬅️ New
<span>⬆️ 🙂<br>⬇️ 🙁</span>
</div>
</div>
<h3>Tweets</h3>
<ol class="tweets tweets-linear-list">
${tweetHtml.join("")}
</ol>
<script>
var series = getSentimentsFromList( '.tweets' );
makeSentimentChart( '.twtr-sentiment-chart', series );
</script>`;
}
}
module.exports = Recent;