This repository has been archived by the owner on Sep 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbody.js
60 lines (55 loc) · 2.37 KB
/
body.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
50
51
52
53
54
55
56
57
58
59
60
'use strict';
const {parallel, deps} = require('@quarterto/promise-deps-parallel');
const cheerioTransform = require('../cheerio-transform');
// text-based transforms
const replaceEllipses = require('./text/replace-ellipses');
const removeLinkWhitespace = require('./text/remove-link-whitespace');
// DOM-based transforms
const relatedBox = require('./html/related-box');
const externalImages = require('./html/external-images');
const trimmedLinks = require('./html/trimmed-links');
const removeStyles = require('./html/remove-styles');
const insertAd = require('./html/insert-ad');
const blockquotes = require('./html/blockquotes');
const replaceTagsWithContent = require('./html/replace-tags-with-content');
const video = require('./html/video');
const unfurlVideo = require('./html/unfurl-video');
const slideshow = require('./html/slideshow');
const interactiveGraphics = require('./html/interactive-graphics');
const infoBox = require('./html/info-box');
const contentLinks = require('./html/content-links');
const linkAnalytics = require('./html/link-analytics');
const removeInvalidLinks = require('./html/remove-invalid-links');
const figure = require('./html/figure');
const removeImageData = require('./html/remove-image-data');
const imagePlaceholder = require('./html/image-placeholder');
const subhead = require('./html/subhead');
const table = require('./html/table');
// runs transforms in parallel, keeping transforms that depend on each other in order.
// `deps('foo')(bar)` tells `parallel` to run `foo` before `bar`.
const transformBody = cheerioTransform(parallel({
relatedBox: deps('externalImages')(relatedBox),
figure: deps('externalImages')(figure),
linkAnalytics: deps('contentLinks', 'relatedBox')(linkAnalytics),
removeInvalidLinks: deps('contentLinks', 'linkAnalytics')(removeInvalidLinks),
imagePlaceholder: deps('externalImages', 'relatedBox', 'figure')(imagePlaceholder),
removeImageData: deps('externalImages', 'relatedBox', 'figure', 'imagePlaceholder')(removeImageData),
video: deps('unfurlVideo')(video),
externalImages,
trimmedLinks,
removeStyles,
insertAd,
blockquotes,
replaceTagsWithContent,
unfurlVideo,
slideshow,
interactiveGraphics,
infoBox,
contentLinks,
subhead,
table,
}));
module.exports = (body, options = {}) => Promise.resolve(body)
.then(replaceEllipses)
.then(removeLinkWhitespace)
.then(articleBody => transformBody(articleBody, options));