mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-17 18:22:37 +02:00
admin script
This commit is contained in:
parent
c9a05e29f3
commit
8c1770b44e
1 changed files with 50 additions and 0 deletions
50
admin/scripts/showcaseCheck.js
Normal file
50
admin/scripts/showcaseCheck.js
Normal file
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
* 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 axios from 'axios';
|
||||
import {load} from 'cheerio';
|
||||
|
||||
// TODO remove axois
|
||||
// TODO recursive yml search in showcase folder
|
||||
// TODO filter out tags.yml
|
||||
|
||||
async function processYamlFiles(directoryPath) {
|
||||
try {
|
||||
const files = await fs.readdir(directoryPath);
|
||||
|
||||
for (const file of files) {
|
||||
const filePath = path.join(directoryPath, file);
|
||||
const data = await fs.readFile(filePath, 'utf8');
|
||||
const yamlData = yaml.load(data);
|
||||
const websiteUrl = yamlData.website;
|
||||
|
||||
try {
|
||||
const response = await axios.get(websiteUrl, {
|
||||
headers: {
|
||||
'Accept-Encoding': 'gzip, deflate',
|
||||
},
|
||||
});
|
||||
|
||||
const html = response.data;
|
||||
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 (err) {
|
||||
console.error('Error reading directory:', err);
|
||||
}
|
||||
}
|
||||
|
||||
processYamlFiles('../../website/showcase');
|
Loading…
Add table
Add a link
Reference in a new issue