2023-01-27 01:16:32 +03:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
|
|
|
|
|
|
|
import { readdirSync } from 'fs';
|
|
|
|
import handlebars from 'handlebars';
|
|
|
|
|
|
|
|
handlebars.registerHelper('capitalize', function (str) {
|
|
|
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
function getDirectories(path) {
|
|
|
|
return fs.readdirSync(path).filter(function (file) {
|
|
|
|
return fs.statSync(path + '/' + file).isDirectory();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const emojiDir = path.resolve('../../../static/img/emoji');
|
|
|
|
|
|
|
|
const emojiCollectionDirs = getDirectories(emojiDir).map(dir => {
|
|
|
|
return dir;
|
|
|
|
});
|
|
|
|
|
|
|
|
let emojiCollections = {};
|
|
|
|
|
|
|
|
emojiCollectionDirs.forEach(collection => {
|
|
|
|
const emojiCollection = readdirSync(path.resolve(emojiDir, collection))
|
|
|
|
.filter(f => f.toLowerCase() !== 'license.md')
|
|
|
|
.map(emoji => {
|
2023-01-27 03:01:24 +03:00
|
|
|
return { name: emoji, src: `img/emoji/${collection}/${emoji}` };
|
2023-01-27 01:16:32 +03:00
|
|
|
});
|
|
|
|
emojiCollections[collection] = { name: collection, images: emojiCollection };
|
|
|
|
});
|
|
|
|
|
2023-01-27 03:37:29 +03:00
|
|
|
const template = fs.readFileSync('./Emoji.stories.mdx', 'utf8');
|
2023-01-27 01:16:32 +03:00
|
|
|
let t = handlebars.compile(template);
|
|
|
|
let output = t({ emojiCollections });
|
|
|
|
console.log(output);
|