-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Native emoji w/ image-based fallbacks and improved parsing (#1746)
* 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 7ba8513. * Revert "Switch “npm ci” instead of “npm i” for stability" This reverts commit d52b476. * Revert "Change emoji data from default to named export" This reverts commit 3f2dd46. * Specify codesandbox template and node version * Update codesandbox config * Revert "Revert "Replace rollup’s uglify plugin with terser"" This reverts commit e06fed4. * Revert "Revert "Revert "Replace rollup’s uglify plugin with terser""" This reverts commit 27d4952. * Update codesandbox config * Revert "Update codesandbox config" This reverts commit 5120dd2. * 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 <[email protected]>
- Loading branch information
1 parent
fd883e6
commit 35002c9
Showing
18 changed files
with
6,092 additions
and
1,956 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"sandboxes": ["2d17z"], | ||
"packages": [".", "packages/docsify-server-renderer"] | ||
"packages": [".", "packages/docsify-server-renderer"], | ||
"node": "16" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
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); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
35002c9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: