1 | const fs = require('fs')
|
2 | const { processPost } = require('./src/processPost')
|
3 | const { getPostsFromZip } = require('./src/getPostsFromZip')
|
4 | const { setVerbose, green, UTF8 } = require('./src/utils');
|
5 |
|
6 | exports.onPreInit = async (_, pluginOptions) => {
|
7 | const before = new Date().getTime();
|
8 | const {source, destination} = pluginOptions
|
9 | const prefix = pluginOptions['prefix'] ? pluginOptions['prefix'] : null;
|
10 | const h1h2 = pluginOptions['h1h2'] ? pluginOptions['h1h2'] : false;
|
11 | const h2h3 = pluginOptions['h2h3'] ? pluginOptions['h2h3'] : false;
|
12 | const remove = pluginOptions['remove'] ? pluginOptions['remove'] : []
|
13 |
|
14 | if(pluginOptions.verbose){
|
15 | setVerbose(pluginOptions.verbose)
|
16 | }
|
17 |
|
18 |
|
19 | if(!fs.existsSync(destination))
|
20 | fs.mkdirSync(destination)
|
21 |
|
22 | let counter = 0;
|
23 | let markdownPagesCreated = 0;
|
24 |
|
25 | await getPostsFromZip(source, async (filename, buffer) => {
|
26 | const content = (await buffer).toString(UTF8)
|
27 | if(await processPost(filename, content, destination, prefix, h1h2, h2h3, remove)) {
|
28 | markdownPagesCreated++
|
29 | }
|
30 | counter++
|
31 | })
|
32 |
|
33 | const after = new Date().getTime();
|
34 | const timePassed = (after-before)/1000
|
35 |
|
36 | console.log(`${green('success')} ${counter} medium post were processed. Created ${markdownPagesCreated} markdown pages - ${timePassed}s`)
|
37 | } |
\ | No newline at end of file |