rssssing/platforms/tumblr.js

48 lines
1.3 KiB
JavaScript

import { createSource, createSourceOptions, fetchChannel, pullImages } from "../lib.js"
let tumblr = {}
export const testWhitelist = (array, whitelist) =>
whitelist.find(tag => !array.includes(tag)) !== undefined
export const testBlacklist = (array, blacklist) =>
blacklist.find(tag => array.includes(tag)) !== undefined
tumblr.createSource = (user, options, postReducerCallback, cache) => {
let lowercaseUser = user.toLowerCase()
let source = {
type: 'tumblr',
description: `Aggregate feed for @${lowercaseUser} on tumblr.com`,
hostname: lowercaseUser + '.tumblr.com',
pathname: 'rss',
name: `tumblr-${lowercaseUser}`,
displayName: user,
user: lowercaseUser,
...createSourceOptions(options)
}
return createSource(source, fetchChannel, postReducerCallback, cache)
}
tumblr.isRepost = (post) => {
let reblog = post.description.querySelector('p > a.tumblr_blog')
return reblog ? reblog.innerHTML !== post.source.user : false
}
tumblr.matchesTags = (post, whitelist, blacklist) => {
if(whitelist && testWhitelist(post.categories, whitelist)) {
return false
}
if(blacklist && testBlacklist(post.categories, blacklist)) {
return false
}
return true
}
tumblr.pullImages = pullImages
export default tumblr