-
-
Notifications
You must be signed in to change notification settings - Fork 9k
/
Copy pathshowcaseCheck.js
62 lines (53 loc) · 1.65 KB
/
showcaseCheck.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import fs from 'fs-extra';
import path from 'path';
import yaml from 'js-yaml';
import {load} from 'cheerio';
async function parseFiles(directoryPath) {
try {
const files = await fs.promises.readdir(directoryPath);
for (const file of files) {
const filePath = path.join(directoryPath, file);
const stat = await fs.promises.stat(filePath);
if (stat.isDirectory()) {
await parseFiles(filePath); // Recursively process subdirectories
} else {
await processYamlFile(filePath); // Process individual YAML file
}
}
} catch (err) {
console.error('Error reading directory:', err);
}
}
async function processYamlFile(filePath) {
const data = await fs.promises.readFile(filePath, 'utf8');
const {website} = yaml.load(data);
try {
const html = await fetchWebsiteHtml(website);
const $ = load(html);
const generatorMeta = $('meta[name="generator"]');
if (generatorMeta.length === 0) {
console.log(`Website ${website} is not a Docusaurus site.`);
}
} catch (error) {
console.error(`Error fetching website ${website}:`, error.message);
}
}
async function fetchWebsiteHtml(url) {
const response = await fetch(url, {
headers: {
'Accept-Encoding': 'gzip, deflate',
},
});
if (!response.ok) {
throw new Error(`Failed to fetch ${url}: ${response.statusText}`);
}
return response.text();
}
// processYamlFiles('../../website/showcase');
parseFiles('./admin/scripts/showcase');