mirror of
https://github.com/docsifyjs/docsify.git
synced 2025-12-08 19:55:52 +00:00
* Render native emoji with image fallback Fix #779 * Deprecate emoji plugin * Add emoji tests * Remove console.log statement * Fix emoji image alt attribute * Set nativeEmoji to false by default (non-breaking) * Fix parsing emoji in HTML comments and script tags * Add nativeEmoji and update noEmoji details * Add Emoji plugin deprecation notice * Fix ESLint issues * Create build:emoji task - Auto-generate emoji data from GitHub API - Auto-generate emoji markdown for website - Add emoji page to navigation * Fix rendering of GitHub emoji without unicode * Adjust and match size of native and image emoji * Update emoji test snapshot * Update docs test snapshot * Fix ci/codesandbox error * Update native emoji font-stack * Fix rendering of native multi-character emoji * Kick GitHub Workflow * Replace rollup’s uglify plugin with terser * Switch “npm ci” instead of “npm i” for stability * Change emoji data from default to named export * Revert "Replace rollup’s uglify plugin with terser" This reverts commit 7ba85136361c72839516900d91cca806fac94fee. * Revert "Switch “npm ci” instead of “npm i” for stability" This reverts commit d52b476a387250740d934e8fd7df7ba274dd17a0. * Revert "Change emoji data from default to named export" This reverts commit 3f2dd467cf9c7a74d8c53c2ee52cc63837b00a3c. * Specify codesandbox template and node version * Update codesandbox config * Revert "Revert "Replace rollup’s uglify plugin with terser"" This reverts commit e06fed49f0383c485e01f1758228849ad0085bc8. * Revert "Revert "Revert "Replace rollup’s uglify plugin with terser""" This reverts commit 27d49521f61976dedcbbf210e1811839853e0e47. * Update codesandbox config * Revert "Update codesandbox config" This reverts commit 5120dd23d45fbd4b2c893db33acbf7014e57c023. * Fix codesandbox uglify error * Emoji docs tweaks * Restore and update emoji plugin code * Restore and update emoji plugin docs * Prettier updates * Match lowercase shortcodes only Co-authored-by: Koy Zhuang <369491420@qq.com>
92 lines
2.4 KiB
JavaScript
92 lines
2.4 KiB
JavaScript
const axios = require('axios');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const filePaths = {
|
|
emojiMarkdown: path.resolve(process.cwd(), 'docs', 'emoji.md'),
|
|
emojiJS: path.resolve(
|
|
process.cwd(),
|
|
'src',
|
|
'core',
|
|
'render',
|
|
'emojify-data.js'
|
|
),
|
|
};
|
|
|
|
async function getEmojiData() {
|
|
const emojiDataURL = 'https://api.github.com/emojis';
|
|
const response = await axios.get(emojiDataURL);
|
|
const baseURL = Object.values(response.data)
|
|
.find(url => /unicode\//)
|
|
.split('unicode/')[0];
|
|
const data = { ...response.data };
|
|
|
|
// Remove base URL from emoji URLs
|
|
Object.entries(data).forEach(
|
|
([key, value]) => (data[key] = value.replace(baseURL, ''))
|
|
);
|
|
|
|
return {
|
|
baseURL,
|
|
data,
|
|
};
|
|
}
|
|
|
|
function writeEmojiPage(emojiData) {
|
|
const emojiPage =
|
|
(fs.existsSync(filePaths.emojiMarkdown) &&
|
|
fs.readFileSync(filePaths.emojiMarkdown, 'utf8')) ||
|
|
`<!-- START -->\n\n<!-- END -->`;
|
|
const emojiRegEx = /(<!--\s*START.*-->\n)([\s\S]*)(\n<!--\s*END.*-->)/;
|
|
const emojiMatch = emojiPage.match(emojiRegEx);
|
|
const emojiMarkdownStart = emojiMatch[1].trim();
|
|
const emojiMarkdown = emojiMatch[2].trim();
|
|
const emojiMarkdownEnd = emojiMatch[3].trim();
|
|
const newEmojiMarkdown = Object.keys(emojiData.data)
|
|
.reduce(
|
|
(preVal, curVal) =>
|
|
(preVal += `:${curVal}: ` + '`' + `:${curVal}:` + '`' + '\n\n'),
|
|
''
|
|
)
|
|
.trim();
|
|
|
|
if (emojiMarkdown !== newEmojiMarkdown) {
|
|
const newEmojiPage = emojiPage.replace(
|
|
emojiMatch[0],
|
|
`${emojiMarkdownStart}\n${newEmojiMarkdown}\n${emojiMarkdownEnd}`
|
|
);
|
|
|
|
fs.writeFileSync(filePaths.emojiMarkdown, newEmojiPage);
|
|
console.info(`- Created new file: ${filePaths.emojiMarkdown}`);
|
|
} else {
|
|
console.info(`- No changes to file: ${filePaths.emojiMarkdown}`);
|
|
}
|
|
}
|
|
|
|
function writeEmojiJS(emojiData) {
|
|
const emojiJS =
|
|
fs.existsSync(filePaths.emojiJS) &&
|
|
fs.readFileSync(filePaths.emojiJS, 'utf8');
|
|
const newEmojiJS = `export default ${JSON.stringify(emojiData, {}, 2)}`;
|
|
|
|
if (!emojiJS || emojiJS !== newEmojiJS) {
|
|
fs.writeFileSync(filePaths.emojiJS, newEmojiJS);
|
|
console.info(`- Created new file: ${filePaths.emojiJS}`);
|
|
} else {
|
|
console.info(`- No changes to file: ${filePaths.emojiJS}`);
|
|
}
|
|
}
|
|
|
|
(async () => {
|
|
console.log('Build emoji');
|
|
|
|
try {
|
|
const emojiData = await getEmojiData();
|
|
|
|
writeEmojiPage(emojiData);
|
|
writeEmojiJS(emojiData);
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
})();
|