mirror of
https://github.com/ikatyang/emoji-cheat-sheet.git
synced 2024-11-22 10:23:51 +01:00
Update emojis
add github emojis remove invalid emojis update markdown format
This commit is contained in:
parent
570451caad
commit
d7a88e7969
@ -6,36 +6,60 @@ const $ = require('cheerio');
|
|||||||
const request = require('request');
|
const request = require('request');
|
||||||
const markdown = require('./markdown');
|
const markdown = require('./markdown');
|
||||||
|
|
||||||
const url = 'http://www.emoji-cheat-sheet.com';
|
|
||||||
const title = 'emoji-cheat-sheet';
|
const title = 'emoji-cheat-sheet';
|
||||||
|
const apiUrl = 'https://api.github.com/emojis';
|
||||||
|
const sheetUrl = 'http://www.emoji-cheat-sheet.com';
|
||||||
|
|
||||||
const outDir = path.resolve(process.cwd(), './generated');
|
const outDir = path.resolve(process.cwd(), './generated');
|
||||||
const outFile = path.join(outDir, 'README.md');
|
const outFile = path.join(outDir, 'README.md');
|
||||||
|
|
||||||
const columnDivisions = 2;
|
const columnDivisions = 2;
|
||||||
|
|
||||||
request.get(url, (error, response, body) => {
|
const getHTML = (url) => new Promise((resolve, reject) => {
|
||||||
if (error || response.statusCode !== 200) {
|
const options = { url };
|
||||||
throw error || `Unexpected response status code: ${response.statusCode}`;
|
if (url === apiUrl) {
|
||||||
} else {
|
Object.assign(options, {
|
||||||
const emojiTable = {};
|
headers: { 'User-Agent': 'https://github.com/ikatyang/emoji-cheat-sheet' },
|
||||||
const $html = $.load(body).root();
|
|
||||||
$html.find('h2').each((_, catalogElement) => {
|
|
||||||
const emojis = [];
|
|
||||||
const catalog = $(catalogElement).text();
|
|
||||||
$html.find(`#emoji-${catalog.toLowerCase()} li .name`).each((_, emojiElement) => {
|
|
||||||
const emoji = $(emojiElement).text();
|
|
||||||
emojis.push(`:${emoji}:`);
|
|
||||||
});
|
|
||||||
emojiTable[catalog] = emojis;
|
|
||||||
});
|
});
|
||||||
if (fs.existsSync(outDir)) {
|
|
||||||
if (!fs.statSync(outDir).isDirectory()) {
|
|
||||||
throw `OutDir '${outDir}' should be a directory.`;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fs.mkdirSync(outDir);
|
|
||||||
}
|
|
||||||
fs.writeFileSync(outFile, markdown.create(url, title, emojiTable, columnDivisions));
|
|
||||||
}
|
}
|
||||||
|
request.get(options, (error, response, html) => {
|
||||||
|
if (error || response.statusCode !== 200) {
|
||||||
|
reject(error || `Unexpected response status code: ${response.statusCode}`);
|
||||||
|
} else {
|
||||||
|
resolve(html);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
Promise.all([getHTML(apiUrl), getHTML(sheetUrl)]).then(([apiHTML, sheetHTML]) => {
|
||||||
|
const apiEmojis = Object.keys(JSON.parse(apiHTML));
|
||||||
|
const emojiTable = {};
|
||||||
|
const $html = $.load(sheetHTML).root();
|
||||||
|
$html.find('h2').each((_, categoryElement) => {
|
||||||
|
const emojis = [];
|
||||||
|
const category = $(categoryElement).text();
|
||||||
|
$html.find(`#emoji-${category.toLowerCase()} li .name`).each((_, emojiElement) => {
|
||||||
|
const emoji = $(emojiElement).text();
|
||||||
|
const index = apiEmojis.indexOf(emoji);
|
||||||
|
if (index !== -1) {
|
||||||
|
apiEmojis.splice(index, 1);
|
||||||
|
emojis.push(emoji);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
emojiTable[category] = emojis;
|
||||||
|
});
|
||||||
|
if (apiEmojis.length > 0) {
|
||||||
|
emojiTable['Uncategorized'] = apiEmojis;
|
||||||
|
}
|
||||||
|
if (fs.existsSync(outDir)) {
|
||||||
|
if (!fs.statSync(outDir).isDirectory()) {
|
||||||
|
throw `OutDir '${outDir}' should be a directory.`;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fs.mkdirSync(outDir);
|
||||||
|
}
|
||||||
|
fs.writeFileSync(outFile, markdown.create({
|
||||||
|
'GitHub Emoji API': apiUrl,
|
||||||
|
'Emoji Cheat Sheet': sheetUrl,
|
||||||
|
}, title, emojiTable, columnDivisions));
|
||||||
});
|
});
|
||||||
|
@ -2,24 +2,25 @@ const format = str => str.trim().replace(/^ +/mg, '');
|
|||||||
|
|
||||||
module.exports = class Markdown {
|
module.exports = class Markdown {
|
||||||
|
|
||||||
static create(url, title, emojiTable, columnDivisions) {
|
static create(urls, title, emojiTable, columnDivisions) {
|
||||||
const emojiCatalogs = Object.keys(emojiTable);
|
const categories = Object.keys(emojiTable);
|
||||||
|
const urlDescriptions = Object.keys(urls).map((site) => `[${site}](${urls[site]})`).join(' and ');
|
||||||
return format(`
|
return format(`
|
||||||
|
|
||||||
# ${title}
|
# ${title}
|
||||||
|
|
||||||
This cheat sheet is auto-generated from <${url}> using [emoji-cheat-sheet-generator](https://github.com/ikatyang/emoji-cheat-sheet/tree/master).
|
This cheat sheet is auto-generated from ${urlDescriptions} using [emoji-cheat-sheet-generator](https://github.com/ikatyang/emoji-cheat-sheet/tree/master).
|
||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
|
|
||||||
${emojiCatalogs.map(catalog => `- [${catalog}](#${catalog.toLowerCase()})`).join('\n')}
|
${categories.map(category => `- [${category}](#${category.toLowerCase()})`).join('\n')}
|
||||||
|
|
||||||
${
|
${
|
||||||
emojiCatalogs.map(catalog => {
|
categories.map(category => {
|
||||||
const emojis = emojiTable[catalog];
|
const emojis = emojiTable[category];
|
||||||
return format(`
|
return format(`
|
||||||
|
|
||||||
### ${catalog}
|
### ${category}
|
||||||
|
|
||||||
${this.createTable(emojis, columnDivisions)}
|
${this.createTable(emojis, columnDivisions)}
|
||||||
|
|
||||||
@ -33,8 +34,8 @@ module.exports = class Markdown {
|
|||||||
static createTableHead(columnDivisions) {
|
static createTableHead(columnDivisions) {
|
||||||
return format(`
|
return format(`
|
||||||
|
|
||||||
| |${(' icon | emoji |').repeat(columnDivisions)}
|
| |${(' ico | emoji |').repeat(columnDivisions)}
|
||||||
| - |${(' ---- | ----- |').repeat(columnDivisions)}
|
| - |${(' --- | ----- |').repeat(columnDivisions)}
|
||||||
|
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
@ -47,7 +48,7 @@ module.exports = class Markdown {
|
|||||||
rowEmojis.push('');
|
rowEmojis.push('');
|
||||||
table += format(`
|
table += format(`
|
||||||
|
|
||||||
| [top](#table-of-contents) |${rowEmojis.map((emoji) => emoji ? ` ${emoji} | \`${emoji}\` ` : ' | ').join(' | ')}|
|
| [top](#table-of-contents) |${rowEmojis.map((emoji) => emoji ? ` :${emoji}: | \`:${emoji}:\` ` : ' | ').join(' | ')}|
|
||||||
|
|
||||||
`) + '\n';
|
`) + '\n';
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user