Skip to content

Commit 1e23204

Browse files
committed
social login updated
1 parent 0e311bd commit 1e23204

File tree

25 files changed

+202
-74
lines changed

25 files changed

+202
-74
lines changed

package-lock.json

+112-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"joi": "^14.3.1",
7474
"jsdom": "^16.2.2",
7575
"keyword-extractor": "0.0.19",
76+
"open-graph-scraper": "^3.6.2",
7677
"path": "^0.12.7",
7778
"prettier": "^2.0.5",
7879
"pretty": "^2.0.0",

source/index.js

+45-19
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ const path = require('path');
33
const fs = require('fs');
44
const { flatten } = require('array-flatten');
55

6-
// console.log(flatten);
7-
8-
// process.exit(0);
9-
106
dotenv.config();
117

8+
// eslint-disable-next-line no-unused-vars
9+
const logger = (name) => {
10+
console.log(name);
11+
return name;
12+
};
13+
1214
/**
1315
* ArticleBuilder
1416
* @class
@@ -66,20 +68,20 @@ class ArticleBuilder {
6668
};
6769
let plugins = this.pluginCollector(path.resolve('./source/plugins'));
6870
// eslint-disable-next-line import/no-dynamic-require, global-require
69-
plugins = plugins.map(uri => (require(uri)));
71+
plugins = plugins.map((uri) => (require(uri)));
7072

71-
await flatten(this.stages
73+
return flatten(this.stages
7274
// remove stages we should skip
73-
.filter(stage => (!this.skip.stages.includes(stage)))
75+
.filter((stage) => (!this.skip.stages.includes(stage)))
7476
// map stages to plugins array
75-
.map(stage => plugins
77+
.map((stage) => plugins
7678
// filter plugin that have no functions for this stage
77-
.filter(plugin => ((plugin[stage] !== undefined) && (typeof plugin[stage] === 'function')))
79+
.filter((plugin) => ((plugin[stage] !== undefined) && (typeof plugin[stage] === 'function')))
7880
// filter plugin we need to skip
7981
.filter((plugin) => {
8082
const { meta: { name } } = plugin;
8183
return (this.skip.plugins.find(
82-
skippedPlugin => (
84+
(skippedPlugin) => (
8385
(
8486
skippedPlugin.name === name
8587
&& skippedPlugin.stages === undefined
@@ -99,20 +101,44 @@ class ArticleBuilder {
99101
.sort((pluginA, pluginB) => (
100102
pluginA.meta.dependency.includes(pluginB.meta.name)
101103
? 1 : -1))
104+
// .map(logger)
102105
// map plugins to functions
103-
.map(plugin => (plugin[stage]))))
106+
.map((plugin) => (plugin[stage]))))
104107
.reduce(async (state, plugin) => {
105108
const resolvedState = await state;
106109
return plugin(resolvedState);
107110
}, article);
108111
}
109112
}
110113

111-
// (async () => {
112-
// try {
113-
// const builder = new ArticleBuilder();
114-
// await builder.create('https://www.smashingmagazine.com/2020/05/convince-others-against-dark-patterns/');
115-
// } catch (error) {
116-
// console.log(error);
117-
// }
118-
// })();
114+
(async () => {
115+
const builder = new ArticleBuilder();
116+
builder.skip.stages = [
117+
'github:before',
118+
'github',
119+
'github:after',
120+
];
121+
builder.skip.plugins = [
122+
{ name: 'codepenTransform' },
123+
{ name: 'codepenTransformIFrame' },
124+
{ name: 'createREADME' },
125+
{ name: 'downloadImages' },
126+
{ name: 'writeMarkdown' },
127+
{ name: 'TMPDir' },
128+
{ name: 'initGithub' },
129+
{ name: 'uploadToRepo' },
130+
{ name: 'createRepo' },
131+
{ name: 'createREADME' },
132+
{ name: 'createCard' },
133+
];
134+
135+
try {
136+
const result = await builder.create('https://increment.com/frontend/a-users-guide-to-css-variables/');
137+
// console.log(result);
138+
console.log(result.tags);
139+
console.log(result.mercury[0].author);
140+
console.log(result.openGraph);
141+
} catch (error) {
142+
console.log(error);
143+
}
144+
})();

source/libs/PluginBase.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = {
2525
* @throw {Error} - if some dependencies not met
2626
*/
2727
dependencyCheck: (stack = [], dependency = [], name = null) => {
28-
const error = dependency.find(plugin => (!stack.includes(plugin)));
28+
const error = dependency.find((plugin) => (!stack.includes(plugin)));
2929
if (error !== undefined) throw new Error(`Dependencies ${name ? `of ${name}` : ''} not met: ${error}`);
3030
},
3131

@@ -36,6 +36,6 @@ module.exports = {
3636
*/
3737
domainCheck: (url, domain) => {
3838
const currentDomain = /https?:\/\/(?<domain>[^/\\]+)/ig.exec(url);
39-
return currentDomain && (domain === currentDomain[1]);
39+
return (domain === null) || (currentDomain && (currentDomain[1].includes(domain)));
4040
},
4141
};

source/plugins/TMPDir/TMPDir.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ module.exports = deepmerge(pluginBase, {
3030
* @return {object} - modified article state
3131
*/
3232
after: (unmodified) => {
33-
return unmodified;
3433
const {
3534
meta: {
3635
name,
@@ -52,7 +51,7 @@ module.exports = deepmerge(pluginBase, {
5251
stack: [],
5352
...unmodified,
5453
};
55-
if (domainCheck(url, domain)) return unmodified;
54+
if (!domainCheck(url, domain)) return unmodified;
5655
dependencyCheck(stack, [...dependency, `${name}:before`]);
5756
const articleDIR = path.resolve(TMP_DIR_NAME, slug);
5857
rimraf.sync(articleDIR);
@@ -88,8 +87,7 @@ module.exports = deepmerge(pluginBase, {
8887
stack: [],
8988
...unmodified,
9089
};
91-
92-
if (domainCheck(url, domain)) return unmodified;
90+
if (!domainCheck(url, domain)) return unmodified;
9391
dependencyCheck(stack, dependency, name);
9492

9593
const articleDIR = path.resolve(TMP_DIR_NAME, slug);

source/plugins/cleanDisqus/cleanDisqus.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module.exports = deepmerge(pluginBase, {
4949
mercury,
5050
},
5151
} = modified;
52-
if (domainCheck(url, domain)) return unmodified;
52+
if (!domainCheck(url, domain)) return unmodified;
5353
dependencyCheck(stack, dependency, name);
5454

5555
Array.from(mercury.window.document.querySelectorAll('[class*="disqus"],[class*="dsq-"],[id*="disqus"]'))

source/plugins/cleanHidden/cleanHidden.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module.exports = deepmerge(pluginBase, {
4949
mercury,
5050
},
5151
} = modified;
52-
if (domainCheck(url, domain)) return unmodified;
52+
if (!domainCheck(url, domain)) return unmodified;
5353
dependencyCheck(stack, dependency, name);
5454

5555
Array.from(mercury.window.document.querySelectorAll('[hidden],[style*="display:none"],[style*="display: none"]'))

source/plugins/codepenTransform/codepenTransform.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ module.exports = deepmerge(pluginBase, {
6868
mercury,
6969
},
7070
} = modified;
71-
if (domainCheck(url, domain)) return unmodified;
71+
if (!domainCheck(url, domain)) return unmodified;
7272
dependencyCheck(stack, dependency, name);
7373
modified.stack.push(name);
7474

source/plugins/codepenTransformIFrame/codepenTransformIFrame.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ module.exports = deepmerge(pluginBase, {
7070
mercury,
7171
},
7272
} = modified;
73-
if (domainCheck(url, domain)) return unmodified;
73+
if (!domainCheck(url, domain)) return unmodified;
7474
dependencyCheck(stack, dependency, name);
7575
modified.stack.push(name);
7676

source/plugins/createCard/createCard.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ module.exports = deepmerge(pluginBase, {
5252
assignees,
5353
tags,
5454
} = modified;
55-
if (domainCheck(url, domain)) return unmodified;
55+
if (!domainCheck(url, domain)) return unmodified;
5656
dependencyCheck(stack, dependency, name);
5757
const [{ title }] = mercury;
5858
await gitHubUtils.createCard(url, title, tags, assignees);

source/plugins/createMarkdown/createMarkdown.js

+1-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const fs = require('fs');
2-
const path = require('path');
31
const prettier = require('prettier');
42
const query = require('query-string');
53
const deepmerge = require('deepmerge');
@@ -179,8 +177,6 @@ module.exports = deepmerge(pluginBase, {
179177
const {
180178
url,
181179
stack,
182-
slug,
183-
TMP_DIR_NAME,
184180
} = unmodified;
185181
const modified = {
186182
dom: {},
@@ -192,7 +188,7 @@ module.exports = deepmerge(pluginBase, {
192188
mercury,
193189
},
194190
} = modified;
195-
if (domainCheck(url, domain)) return unmodified;
191+
if (!domainCheck(url, domain)) return unmodified;
196192
dependencyCheck(stack, dependency, name);
197193

198194
let markdown = convertToMD(mercury);
@@ -204,18 +200,6 @@ module.exports = deepmerge(pluginBase, {
204200
useTabs: false,
205201
});
206202

207-
fs.writeFileSync(path.resolve(
208-
TMP_DIR_NAME,
209-
slug,
210-
'eng.md',
211-
), markdown);
212-
213-
fs.writeFileSync(path.resolve(
214-
TMP_DIR_NAME,
215-
slug,
216-
'rus.md',
217-
), markdown);
218-
219203
modified.markdown = markdown;
220204
modified.stack.push(name);
221205
return modified;

0 commit comments

Comments
 (0)