mirror of
https://github.com/awesome-opencode/awesome-opencode.git
synced 2026-04-28 12:29:29 +00:00
feat: data-driven README automation with YAML entries and GitHub Actions
This commit is contained in:
parent
20d7d4db6f
commit
25446b49eb
64 changed files with 1864 additions and 323 deletions
52
scripts/utils/yaml.js
Normal file
52
scripts/utils/yaml.js
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* YAML file reading utilities for awesome-opencode
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const yaml = require('js-yaml');
|
||||
const { glob } = require('glob');
|
||||
|
||||
/**
|
||||
* Read and parse a single YAML file
|
||||
* @param {string} filePath - Path to YAML file
|
||||
* @returns {object} Parsed YAML object
|
||||
*/
|
||||
function readYamlFile(filePath) {
|
||||
try {
|
||||
const content = fs.readFileSync(filePath, 'utf8');
|
||||
return yaml.load(content, { filename: filePath });
|
||||
} catch (e) {
|
||||
throw new Error(`Failed to parse ${filePath}: ${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read all YAML files from a directory
|
||||
* @param {string} dirPath - Directory containing YAML files
|
||||
* @returns {Promise<object[]>} Array of parsed YAML objects with _filePath metadata
|
||||
*/
|
||||
async function readYamlDir(dirPath) {
|
||||
const pattern = path.join(dirPath, '*.yaml').replace(/\\/g, '/');
|
||||
const files = await glob(pattern);
|
||||
|
||||
return files.map(file => ({
|
||||
...readYamlFile(file),
|
||||
_filePath: file,
|
||||
_fileName: path.basename(file, '.yaml')
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a name to a filename-safe slug
|
||||
* @param {string} name - Entry name
|
||||
* @returns {string} Slugified filename (without extension)
|
||||
*/
|
||||
function slugify(name) {
|
||||
return name
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, '-')
|
||||
.replace(/^-+|-+$/g, '');
|
||||
}
|
||||
|
||||
module.exports = { readYamlFile, readYamlDir, slugify };
|
||||
Loading…
Add table
Add a link
Reference in a new issue