Skip to content

Commit 1f8fd65

Browse files
committed
docs: refactor image file structure and add filename check
1 parent 615e6b9 commit 1f8fd65

29 files changed

+81
-14
lines changed

.github/workflows/nodejs.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,16 @@ jobs:
1616
node-version-matrix: '[24]'
1717
upload-coverage: false
1818
disable-test-package: true
19+
check-kebab-case:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
25+
- name: Setup Node.js
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: '24'
29+
30+
- name: Run kebab-case check
31+
run: node checkFilenames.mjs
File renamed without changes.

checkFilenames.mjs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
import { fileURLToPath } from 'url';
4+
5+
const __filename = fileURLToPath(import.meta.url);
6+
const __dirname = path.dirname(__filename);
7+
8+
function getAllFiles(dirPath) {
9+
let nonKebabElements = [];
10+
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
11+
12+
const kebabCaseRegex = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
13+
14+
for (const entry of entries) {
15+
// Skip certain files/folders
16+
if (
17+
entry.name === '.DS_Store' ||
18+
entry.name === 'images' ||
19+
entry.name === 'demos' ||
20+
entry.name === '_category_.json'
21+
) {
22+
continue;
23+
}
24+
25+
// Get the name without extension for files, or full name for directories
26+
const nameToTest = entry.isFile()
27+
? path.parse(entry.name).name
28+
: entry.name;
29+
30+
if (!kebabCaseRegex.test(nameToTest)) {
31+
nonKebabElements.push(path.join(dirPath, entry.name));
32+
}
33+
34+
// Recursively check subdirectories
35+
if (entry.isDirectory()) {
36+
const subDirResults = getAllFiles(path.join(dirPath, entry.name));
37+
nonKebabElements = nonKebabElements.concat(subDirResults);
38+
}
39+
}
40+
41+
return nonKebabElements;
42+
}
43+
44+
const folders = ['docs', 'blog'];
45+
46+
for (const folder of folders) {
47+
const folderPath = path.join(__dirname, folder);
48+
const nonKebabFiles = getAllFiles(folderPath);
49+
if (nonKebabFiles.length !== 0) {
50+
throw new Error(`Non-kebab-case files found:\n${nonKebabFiles.join('\n')}`);
51+
}
52+
}
53+
console.log('All files have passed the check.');
File renamed without changes.

0 commit comments

Comments
 (0)