-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
2 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,34 @@ | ||
import Joi from 'joi' | ||
import { metric } from '../text-formatters.js' | ||
import { documentation, YouTubeVideoBase } from './youtube-base.js' | ||
|
||
const documentationWithDislikes = ` | ||
${documentation} | ||
<p> | ||
When enabling the <code>withDislikes</code> option, 👍 corresponds to the number | ||
of likes of a given video, 👎 corresponds to the number of dislikes. | ||
</p> | ||
` | ||
|
||
const queryParamSchema = Joi.object({ | ||
withDislikes: Joi.equal(''), | ||
}).required() | ||
|
||
export default class YouTubeLikes extends YouTubeVideoBase { | ||
static route = { | ||
base: 'youtube/likes', | ||
pattern: ':videoId', | ||
queryParamSchema, | ||
} | ||
|
||
static get examples() { | ||
const previewLikes = this.render({ | ||
statistics: { likeCount: 7 }, | ||
id: 'abBdk8bSPKU', | ||
}) | ||
const previewVotes = this.render( | ||
{ | ||
statistics: { likeCount: 10236, dislikeCount: 396 }, | ||
id: 'pU9Q6oiQNd0', | ||
}, | ||
{ withDislikes: '' } | ||
) | ||
// link[] is not allowed in examples | ||
delete previewLikes.link | ||
delete previewVotes.link | ||
return [ | ||
{ | ||
title: 'YouTube Video Likes', | ||
namedParams: { videoId: 'abBdk8bSPKU' }, | ||
staticPreview: previewLikes, | ||
documentation, | ||
}, | ||
{ | ||
title: 'YouTube Video Likes and Dislikes', | ||
namedParams: { videoId: 'pU9Q6oiQNd0' }, | ||
staticPreview: previewVotes, | ||
queryParams: { | ||
withDislikes: null, | ||
}, | ||
documentation: documentationWithDislikes, | ||
}, | ||
] | ||
} | ||
|
||
static render({ statistics, id }, queryParams) { | ||
let renderedBadge = super.renderSingleStat({ | ||
const renderedBadge = super.renderSingleStat({ | ||
statistics, | ||
statisticName: 'like', | ||
id, | ||
}) | ||
if (queryParams && typeof queryParams.withDislikes !== 'undefined') { | ||
renderedBadge = { | ||
...renderedBadge, | ||
message: `${metric(statistics.likeCount)} 👍`, | ||
} | ||
} | ||
return renderedBadge | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters