|
1 |
| -import { load } from 'cheerio'; |
2 |
| -import { readFile, writeFile } from 'node:fs/promises'; |
| 1 | +import { readdir, readFile, writeFile } from 'node:fs/promises'; |
3 | 2 | import { join, resolve } from 'node:path';
|
4 | 3 |
|
5 |
| - |
6 | 4 | const ROOT_DIR = resolve('.');
|
7 |
| -const DATA_DIR = join(ROOT_DIR, '/docs/kr.tree'); |
| 5 | +const DATA_DIR = join(ROOT_DIR, 'pages'); |
8 | 6 |
|
9 |
| -const text = (await readFile(DATA_DIR)); |
10 |
| -const $ = await load(text, { xml: true }); |
| 7 | +const toc = Object.keys(JSON.parse(await readFile(DATA_DIR + '/HelpTOC.json', 'utf8')).entities.pages); |
| 8 | +const filelist = await readdir(DATA_DIR); |
11 | 9 |
|
12 |
| -const ids = (await $('toc-element[hidden="true"]')) |
13 |
| - .map((i, e) => $(e).attr('id')).get(); |
| 10 | +console.log('total', filelist.length); |
14 | 11 |
|
15 |
| -console.log('total', ids.length); |
| 12 | +const dels = filelist |
| 13 | + .map(async fileName => { |
| 14 | + if (!fileName.endsWith('.html')) return; |
| 15 | + const key = fileName.replace(/\.html$/, ''); |
| 16 | + if (toc.includes(key)) return; |
16 | 17 |
|
17 |
| -const dels = ids |
18 |
| - .map(async id => { |
19 |
| - console.log('process', id); |
20 |
| - const fileName = id.replace(/.md$/g, '').replace(/\./g, '-') + '.html'; |
21 |
| - const file = `${ROOT_DIR}/pages/${fileName}`; |
| 18 | + const file = DATA_DIR + '/' + fileName; |
22 | 19 | const text = await readFile(file);
|
| 20 | + if (!text.includes('<meta name="built-on"')) return; |
| 21 | + |
23 | 22 | const patched = text.toString().replace(/(<head>)/g, '$1<meta name="robots" content="noindex">');
|
24 | 23 | console.log('exclude', file);
|
25 | 24 | await writeFile(file, patched);
|
|
0 commit comments