-
Notifications
You must be signed in to change notification settings - Fork 0
/
movies.js
49 lines (44 loc) · 1.49 KB
/
movies.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
43
44
45
46
47
48
49
import * as cheerio from 'cheerio'
import { XMLParser } from 'fast-xml-parser'
import _ from 'lodash'
import EleventyFetch from '@11ty/eleventy-fetch'
const parser = new XMLParser()
export default async function () {
const cache = await EleventyFetch('https://letterboxd.com/higby_/rss/', {
duration: '0s',
type: 'text'
})
let films = parser
.parse(cache)
.rss.channel.item.filter(entry => !entry.link.includes('/list/'))
.map(entry => {
return {
title: entry['letterboxd:filmTitle'],
year: entry['letterboxd:filmYear'],
// TODO: Turn the following into a Liquid filter
rating: () => {
let rating = entry['letterboxd:memberRating']
let stars = ''
let floor = Math.floor(rating)
for (let i = 0; i < floor; i++) stars += '★'
if (rating - floor == 0.5) stars += '½'
return stars
},
twoThumbsUp: () => (entry['letterboxd:memberRating'] > 4.4 ? true : false),
date: entry['letterboxd:watchedDate'],
review: () => {
const $ = cheerio.load(entry.description, null, false)
$('p').first().remove()
if ($('p').first().text().startsWith('Watched on ')) $('p').first().remove()
return $.html()
}
}
})
.sort((a, b) => new Date(b.date) - new Date(a.date))
let groupedFilms = _.chain(films)
.groupBy(entry => new Date(entry.date).getFullYear())
.toPairs()
.reverse()
.value()
return groupedFilms
}