github.com/Jeffail/benthos/v3@v3.65.0/website/src/plugins/components/index.js (about) 1 const path = require('path'); 2 const fs = require('fs'); 3 const {parseMarkdownString} = require('@docusaurus/utils'); 4 5 function components(type) { 6 return all_components(type).filter(c => c.status != "deprecated") 7 } 8 9 function all_components(type) { 10 let components = []; 11 let dir = path.join(__dirname, `../../../docs/components/${type}`); 12 fs.readdirSync(dir).forEach(function (file) { 13 if ( !/about\.mdx?/.test(file) ) { 14 let name = file.split('.').slice(0, -1).join('.'); 15 let data = fs.readFileSync(path.join(dir, file)); 16 const {frontMatter} = parseMarkdownString(data); 17 frontMatter["name"] = name; 18 components.push(frontMatter); 19 } 20 }); 21 return components; 22 } 23 24 function listPaths(type) { 25 let paths = [`components/${type}/about`]; 26 27 let components = all_components(type); 28 29 components 30 .filter(c => c.status != "deprecated") 31 .forEach(function (info) { 32 paths.push(`components/${type}/${info.name}`); 33 }); 34 35 let deprecatedPaths = components 36 .filter(c => c.status == "deprecated") 37 .map(c => `components/${type}/${c.name}`); 38 39 if ( deprecatedPaths.length > 0 ) { 40 paths.push({ 41 type: 'category', 42 label: 'Deprecated', 43 items: deprecatedPaths, 44 }); 45 } 46 47 return paths; 48 } 49 50 module.exports = { 51 components: components, 52 listPaths: listPaths, 53 };