mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-12 15:52:39 +02:00
refactor clean
This commit is contained in:
parent
34a0e3fc0e
commit
40000d07ca
1 changed files with 35 additions and 31 deletions
|
@ -9,7 +9,7 @@ import path from 'path';
|
|||
import yaml from 'js-yaml';
|
||||
import {load} from 'cheerio';
|
||||
|
||||
async function processYamlFiles(directoryPath) {
|
||||
async function parseFiles(directoryPath) {
|
||||
try {
|
||||
const files = await fs.promises.readdir(directoryPath);
|
||||
|
||||
|
@ -18,41 +18,45 @@ async function processYamlFiles(directoryPath) {
|
|||
const stat = await fs.promises.stat(filePath);
|
||||
|
||||
if (stat.isDirectory()) {
|
||||
await processYamlFiles(filePath); // Recursive call for subdirectory
|
||||
await parseFiles(filePath); // Recursively process subdirectories
|
||||
} else {
|
||||
const data = await fs.promises.readFile(filePath, 'utf8');
|
||||
const yamlData = yaml.load(data);
|
||||
const websiteUrl = yamlData.website;
|
||||
|
||||
try {
|
||||
const response = await fetch(websiteUrl, {
|
||||
headers: {
|
||||
'Accept-Encoding': 'gzip, deflate',
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Failed to fetch ${websiteUrl}: ${response.statusText}`,
|
||||
);
|
||||
}
|
||||
|
||||
const html = await response.text();
|
||||
const $ = load(html);
|
||||
const generatorMeta = $('meta[name="generator"]');
|
||||
|
||||
if (generatorMeta.length === 0) {
|
||||
console.log(`Website ${websiteUrl} is not a Docusaurus site.`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error fetching website ${websiteUrl}:`, error.message);
|
||||
}
|
||||
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);
|
||||
|
||||
// processYamlFiles('./admin/scripts/showcase');
|
||||
processYamlFiles('../../website/showcase');
|
||||
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');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue