From 632aae66e094ee74a99cacf637a36a63a892c5b9 Mon Sep 17 00:00:00 2001 From: Ika Date: Sat, 18 Mar 2017 01:33:26 +0800 Subject: [PATCH] Update markdown format add back to top links add some descriptions --- scripts/generate.js | 2 +- scripts/markdown.js | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/scripts/generate.js b/scripts/generate.js index 881f215..aefab8b 100644 --- a/scripts/generate.js +++ b/scripts/generate.js @@ -36,6 +36,6 @@ request.get(url, (error, response, body) => { } else { fs.mkdirSync(outDir); } - fs.writeFileSync(outFile, markdown.create(title, emojiTable, columnDivisions)); + fs.writeFileSync(outFile, markdown.create(url, title, emojiTable, columnDivisions)); } }); diff --git a/scripts/markdown.js b/scripts/markdown.js index 781aae8..9bef41c 100644 --- a/scripts/markdown.js +++ b/scripts/markdown.js @@ -2,17 +2,24 @@ const format = str => str.trim().replace(/^ +/mg, ''); module.exports = class Markdown { - static create(title, emojiTable, columnDivisions) { + static create(url, title, emojiTable, columnDivisions) { + const emojiCatalogs = Object.keys(emojiTable); return format(` # ${title} + This cheat sheet is auto-generated from <${url}> using [emoji-cheat-sheet-generator](https://github.com/ikatyang/emoji-cheat-sheet/tree/master). + + ## Table of Contents + + ${emojiCatalogs.map(catalog => `- [${catalog}](#${catalog.toLowerCase()})`).join('\n')} + ${ - Object.keys(emojiTable).map(catalog => { + emojiCatalogs.map(catalog => { const emojis = emojiTable[catalog]; return format(` - #### ${catalog} + ## ${catalog} ${this.createTable(emojis, columnDivisions)} @@ -26,8 +33,8 @@ module.exports = class Markdown { static createTableHead(columnDivisions) { return format(` - |${(' icon | emoji |').repeat(columnDivisions)} - |${(' ---- | ----- |').repeat(columnDivisions)} + | |${(' icon | emoji |').repeat(columnDivisions)} + | - |${(' ---- | ----- |').repeat(columnDivisions)} `); } @@ -40,7 +47,7 @@ module.exports = class Markdown { rowEmojis.push(''); table += format(` - |${rowEmojis.map((emoji) => ` :${emoji}: | \`:${emoji}:\` `).join(' | ')}| + | [↑](#table-of-contents) |${rowEmojis.map((emoji) => ` :${emoji}: | \`:${emoji}:\` `).join(' | ')}| `) + '\n'; }