Add missing files

This commit is contained in:
Thomas Rogers 2023-06-20 02:42:09 +02:00
parent a08af0610a
commit 0cae728a43
4 changed files with 2039 additions and 1 deletions

File diff suppressed because one or more lines are too long

View file

@ -36,6 +36,7 @@ import { TwitterHandler } from './websites/twitter-handler'
import { WeixinQqHandler } from './websites/weixin-qq-handler'
import { WikipediaHandler } from './websites/wikipedia-handler'
import { YoutubeHandler } from './websites/youtube-handler'
import { TheAtlanticHandler } from './websites/the-atlantic-handler'
const validateUrlString = (url: string): boolean => {
const u = new URL(url)
@ -56,6 +57,7 @@ const validateUrlString = (url: string): boolean => {
}
const contentHandlers: ContentHandler[] = [
new TheAtlanticHandler(),
new AppleNewsHandler(),
new BloombergHandler(),
new DerstandardHandler(),

View file

@ -0,0 +1,42 @@
import { TheAtlanticHandler } from '../src/websites/the-atlantic-handler'
import fs from 'fs';
import nock from 'nock'
describe('Testing the atlantic opening', () => {
const load = (path: string): string => {
return fs.readFileSync(path, 'utf8')
}
before(() => {
const html = load('./test/data/the-atlantic-article.html');
nock('https://theatlantic.com').get('/article/').reply(200, html)
})
it('should parse the title of the atlantic article.', async () => {
const response = await new TheAtlanticHandler().preHandle(
'https://theatlantic.com/article/'
);
// We grab the title from the doucment.
expect(response.title).not.toBeFalsy()
})
it('should remove the article section, and replace it with a parseable div', async () => {
const response = await new TheAtlanticHandler().preHandle(
'https://theatlantic.com/article/'
);
// We grab the title from the doucment.
expect(response.dom?.querySelector('[data-event-module="article body"]')).toBeEmptyDOMElement()
});
it ('should append a new div, and add the article content inside', () => {
const response = await new TheAtlanticHandler().preHandle(
'https://theatlantic.com/article/'
);
// We grab the title from the doucment.
expect(response.dom?.getElementById('prehandled')).not.toBeEmptyDOMElement()
})
})

View file

@ -14,7 +14,7 @@ const signToken = promisify(jwt.sign);
const os = require('os');
const { Storage } = require('@google-cloud/storage');
const { parseHTML } = require('linkedom');
const { preHandleContent, preParseContent } = require('../content-handler/src/index');
const { preHandleContent, preParseContent } = require("@omnivore/content-handler");
const { Readability } = require("@omnivore/readability");
const puppeteer = require('puppeteer-extra');