mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-23 13:07:57 +02:00
update admin script
This commit is contained in:
parent
77aaf4a103
commit
34a0e3fc0e
1 changed files with 30 additions and 22 deletions
|
@ -7,39 +7,46 @@
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import yaml from 'js-yaml';
|
import yaml from 'js-yaml';
|
||||||
import axios from 'axios';
|
|
||||||
import {load} from 'cheerio';
|
import {load} from 'cheerio';
|
||||||
|
|
||||||
// TODO remove axois
|
|
||||||
// TODO recursive yml search in showcase folder
|
|
||||||
// TODO filter out tags.yml
|
|
||||||
|
|
||||||
async function processYamlFiles(directoryPath) {
|
async function processYamlFiles(directoryPath) {
|
||||||
try {
|
try {
|
||||||
const files = await fs.readdir(directoryPath);
|
const files = await fs.promises.readdir(directoryPath);
|
||||||
|
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const filePath = path.join(directoryPath, file);
|
const filePath = path.join(directoryPath, file);
|
||||||
const data = await fs.readFile(filePath, 'utf8');
|
const stat = await fs.promises.stat(filePath);
|
||||||
const yamlData = yaml.load(data);
|
|
||||||
const websiteUrl = yamlData.website;
|
|
||||||
|
|
||||||
try {
|
if (stat.isDirectory()) {
|
||||||
const response = await axios.get(websiteUrl, {
|
await processYamlFiles(filePath); // Recursive call for subdirectory
|
||||||
headers: {
|
} else {
|
||||||
'Accept-Encoding': 'gzip, deflate',
|
const data = await fs.promises.readFile(filePath, 'utf8');
|
||||||
},
|
const yamlData = yaml.load(data);
|
||||||
});
|
const websiteUrl = yamlData.website;
|
||||||
|
|
||||||
const html = response.data;
|
try {
|
||||||
const $ = load(html);
|
const response = await fetch(websiteUrl, {
|
||||||
const generatorMeta = $('meta[name="generator"]');
|
headers: {
|
||||||
|
'Accept-Encoding': 'gzip, deflate',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
if (generatorMeta.length === 0) {
|
if (!response.ok) {
|
||||||
console.log(`Website ${websiteUrl} is not a Docusaurus site.`);
|
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);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
console.error(`Error fetching website ${websiteUrl}:`, error.message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -47,4 +54,5 @@ async function processYamlFiles(directoryPath) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// processYamlFiles('./admin/scripts/showcase');
|
||||||
processYamlFiles('../../website/showcase');
|
processYamlFiles('../../website/showcase');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue