Skip to content

Commit

Permalink
fresh run of prettier; remove NOTES.md (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
adampash authored Jan 31, 2019
1 parent 244d17d commit 663cc45
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 165 deletions.
84 changes: 0 additions & 84 deletions NOTES.md

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/templates/custom-extractor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import template from './index';

export default function (hostname, name) {
export default function(hostname, name) {
return template`
export const ${name} = {
domain: '${hostname}',
Expand Down
5 changes: 3 additions & 2 deletions scripts/templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ export default function template(strings, ...values) {
indentLevel = /^\s{0,2}(.+)$/g;
}

return body.split('\n')
return body
.split('\n')
.slice(1)
.map((line) => {
.map(line => {
line = line.replace(indentLevel, '$1');

if (trailingWhitespace.test(line)) {
Expand Down
4 changes: 1 addition & 3 deletions src/cleaners/date-published.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import assert from 'assert';
import moment from 'moment-timezone';

import cleanDatePublished, {
cleanDateString,
} from './date-published';
import cleanDatePublished, { cleanDateString } from './date-published';

describe('cleanDatePublished(dateString)', () => {
it('returns a date', () => {
Expand Down
24 changes: 6 additions & 18 deletions src/extractors/custom/www.fastcompany.com/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,26 @@ export const WwwFastcompanyComExtractor = {
domain: 'www.fastcompany.com',

title: {
selectors: [
'h1',
],
selectors: ['h1'],
},

author: {
selectors: [
'.post__by',
],
selectors: ['.post__by'],
},

date_published: {
selectors: [
['meta[name="article:published_time"]', 'value'],
],
selectors: [['meta[name="article:published_time"]', 'value']],
},

dek: {
selectors: [
'.post__deck',
],
selectors: ['.post__deck'],
},

lead_image_url: {
selectors: [
['meta[name="og:image"]', 'value'],
],
selectors: [['meta[name="og:image"]', 'value']],
},

content: {
selectors: [
'.post__article',
],
selectors: ['.post__article'],
},
};
75 changes: 46 additions & 29 deletions src/extractors/custom/www.fastcompany.com/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ describe('WwwFastcompanyComExtractor', () => {
beforeAll(() => {
url =
'https://www.fastcompany.com/3067012/the-only-five-email-folders-your-inbox-will-ever-need';
const html =
fs.readFileSync('./fixtures/www.fastcompany.com/1547124373499.html');
result =
Mercury.parse(url, html, { fallback: false });
const html = fs.readFileSync(
'./fixtures/www.fastcompany.com/1547124373499.html'
);
result = Mercury.parse(url, html, { fallback: false });
});

it('is selected properly', () => {
Expand All @@ -30,53 +30,62 @@ describe('WwwFastcompanyComExtractor', () => {
});

it('returns the title', async () => {
// To pass this test, fill out the title selector
// in ./src/extractors/custom/www.fastcompany.com/index.js.
// To pass this test, fill out the title selector
// in ./src/extractors/custom/www.fastcompany.com/index.js.
const { title } = await result;

// Update these values with the expected values from
// the article.
assert.equal(title, 'The Only Five Email Folders Your Inbox Will Ever Need');
// Update these values with the expected values from
// the article.
assert.equal(
title,
'The Only Five Email Folders Your Inbox Will Ever Need'
);
});

it('returns the author', async () => {
// To pass this test, fill out the author selector
// in ./src/extractors/custom/www.fastcompany.com/index.js.
// To pass this test, fill out the author selector
// in ./src/extractors/custom/www.fastcompany.com/index.js.
const { author } = await result;

// Update these values with the expected values from
// the article.
// Update these values with the expected values from
// the article.
assert.equal(author, 'Zach Hanlon');
});

it('returns the date_published', async () => {
// To pass this test, fill out the date_published selector
// in ./src/extractors/custom/www.fastcompany.com/index.js.
// To pass this test, fill out the date_published selector
// in ./src/extractors/custom/www.fastcompany.com/index.js.
const { date_published } = await result;

// Update these values with the expected values from
// the article.
// Update these values with the expected values from
// the article.
assert.equal(date_published, '2017-01-09T05:00:00.000Z');
});

it('returns the dek', async () => {
// To pass this test, fill out the dek selector
// in ./src/extractors/custom/www.fastcompany.com/index.js.
// To pass this test, fill out the dek selector
// in ./src/extractors/custom/www.fastcompany.com/index.js.
const { dek } = await result;

// Update these values with the expected values from
// the article.
assert.equal(dek, 'Stop “organizing” your emails by subject and start thinking of them in terms of deadlines.');
// Update these values with the expected values from
// the article.
assert.equal(
dek,
'Stop “organizing” your emails by subject and start thinking of them in terms of deadlines.'
);
});

it('returns the lead_image_url', async () => {
// To pass this test, fill out the lead_image_url selector
// in ./src/extractors/custom/www.fastcompany.com/index.js.
// To pass this test, fill out the lead_image_url selector
// in ./src/extractors/custom/www.fastcompany.com/index.js.
const { lead_image_url } = await result;

// Update these values with the expected values from
// the article.
assert.equal(lead_image_url, 'https://images.fastcompany.net/image/upload/w_1280,f_auto,q_auto,fl_lossy/fc/3067012-poster-p-1-the-only-five-email-folders-your-inbox-will-ever-need.jpg');
// Update these values with the expected values from
// the article.
assert.equal(
lead_image_url,
'https://images.fastcompany.net/image/upload/w_1280,f_auto,q_auto,fl_lossy/fc/3067012-poster-p-1-the-only-five-email-folders-your-inbox-will-ever-need.jpg'
);
});

it('returns the content', async () => {
Expand All @@ -88,11 +97,19 @@ describe('WwwFastcompanyComExtractor', () => {

const $ = cheerio.load(content || '');

const first13 = excerptContent($('*').first().text(), 13);
const first13 = excerptContent(
$('*')
.first()
.text(),
13
);

// Update these values with the expected values from
// the article.
assert.equal(first13, 'For years, my approach to email was like slaying a hydra. For every');
assert.equal(
first13,
'For years, my approach to email was like slaying a hydra. For every'
);
});
});
});
6 changes: 4 additions & 2 deletions src/extractors/custom/www.fortinet.com/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ export const WwwFortinetComExtractor = {
},

content: {
selectors: ['div.responsivegrid.aem-GridColumn.aem-GridColumn--default--12'],
selectors: [
'div.responsivegrid.aem-GridColumn.aem-GridColumn--default--12',
],

transforms: {
noscript: ($node) => {
noscript: $node => {
const $children = $node.children();
if ($children.length === 1 && $children.get(0).tagName === 'img') {
return 'figure';
Expand Down
9 changes: 7 additions & 2 deletions src/extractors/custom/www.fortinet.com/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ describe('WwwFortinetComExtractor', () => {
beforeAll(() => {
url =
'https://www.fortinet.com/blog/threat-research/defeating-an-android-packer-with-frida.html';
const html = fs.readFileSync('./fixtures/www.fortinet.com/1546954846985.html');
const html = fs.readFileSync(
'./fixtures/www.fortinet.com/1546954846985.html'
);
result = Mercury.parse(url, html, { fallback: false });
});

Expand All @@ -34,7 +36,10 @@ describe('WwwFortinetComExtractor', () => {

// Update these values with the expected values from
// the article.
assert.equal(title, 'How-to Guide: Defeating an Android Packer with FRIDA');
assert.equal(
title,
'How-to Guide: Defeating an Android Packer with FRIDA'
);
});

it('returns the author', async () => {
Expand Down
8 changes: 2 additions & 6 deletions src/extractors/custom/www.washingtonpost.com/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@ export const WwwWashingtonpostComExtractor = {
},

author: {
selectors: [
'.pb-author-name',
],
selectors: ['.pb-author-name'],
},

date_published: {
selectors: [
['.author-timestamp[itemprop="datePublished"]', 'content'],
],
selectors: [['.author-timestamp[itemprop="datePublished"]', 'content']],
},

dek: {
Expand Down
8 changes: 4 additions & 4 deletions src/extractors/custom/www.washingtonpost.com/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ describe('WwwWashingtonpostComExtractor', () => {
beforeAll(() => {
url =
'https://www.washingtonpost.com/news/opinions/wp/2018/10/29/enough-platitudes-lets-name-names/';
const html =
fs.readFileSync('./fixtures/www.washingtonpost.com/1546958901450.html');
result =
Mercury.parse(url, html, { fallback: false });
const html = fs.readFileSync(
'./fixtures/www.washingtonpost.com/1546958901450.html'
);
result = Mercury.parse(url, html, { fallback: false });
});

it('is selected properly', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/extractors/detect-by-html.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MediumExtractor, BloggerExtractor } from "./custom";
import { MediumExtractor, BloggerExtractor } from './custom';

const Detectors = {
'meta[name="al:ios:app_name"][value="Medium"]': MediumExtractor,
Expand Down
6 changes: 4 additions & 2 deletions src/extractors/generic/content/scoring/merge-siblings.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ export default function mergeSiblings($candidate, topScore, $) {

if (newScore >= siblingScoreThreshold) {
return wrappingDiv.append($sibling);
} if (sibling.tagName === 'p') {
}
if (sibling.tagName === 'p') {
const siblingContent = $sibling.text();
const siblingContentLength = textLength(siblingContent);

if (siblingContentLength > 80 && density < 0.25) {
return wrappingDiv.append($sibling);
} if (
}
if (
siblingContentLength <= 80 &&
density === 0 &&
hasSentenceEnd(siblingContent)
Expand Down
Loading

0 comments on commit 663cc45

Please sign in to comment.