-
-
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.
Merge branch 'develop' into delete-ie11
- Loading branch information
Showing
30 changed files
with
6,903 additions
and
2,204 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
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,109 @@ | ||
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', | ||
'emoji-data.js' | ||
), | ||
}; | ||
|
||
async function getEmojiData() { | ||
const emojiDataURL = 'https://api.github.com/emojis'; | ||
|
||
console.info(`- Fetching emoji data from ${emojiDataURL}`); | ||
|
||
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, '')) | ||
); | ||
|
||
console.info(`- Retrieved ${Object.keys(data).length} emoji entries`); | ||
|
||
return { | ||
baseURL, | ||
data, | ||
}; | ||
} | ||
|
||
function writeEmojiPage(emojiData) { | ||
const isExistingPage = fs.existsSync(filePaths.emojiMarkdown); | ||
const emojiPage = | ||
(isExistingPage && 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\n${newEmojiMarkdown}\n\n${emojiMarkdownEnd}` | ||
); | ||
|
||
fs.writeFileSync(filePaths.emojiMarkdown, newEmojiPage); | ||
|
||
console.info( | ||
`- ${!isExistingPage ? 'Created' : 'Updated'}: ${filePaths.emojiMarkdown}` | ||
); | ||
} else { | ||
console.info(`- No changes: ${filePaths.emojiMarkdown}`); | ||
} | ||
} | ||
|
||
function writeEmojiJS(emojiData) { | ||
const isExistingPage = fs.existsSync(filePaths.emojiJS); | ||
const emojiJS = isExistingPage && fs.readFileSync(filePaths.emojiJS, 'utf8'); | ||
const newEmojiJS = [ | ||
'/* eslint-disable */\n', | ||
'// =============================================================================', | ||
'// DO NOT EDIT: This file is auto-generated by an /build/emoji.js', | ||
'// =============================================================================\n', | ||
`export default ${JSON.stringify(emojiData, {}, 2)}`, | ||
].join('\n'); | ||
|
||
if (!emojiJS || emojiJS !== newEmojiJS) { | ||
fs.writeFileSync(filePaths.emojiJS, newEmojiJS); | ||
|
||
console.info( | ||
`- ${!isExistingPage ? 'Created' : 'Updated'}: ${filePaths.emojiJS}` | ||
); | ||
} else { | ||
console.info(`- No changes: ${filePaths.emojiJS}`); | ||
} | ||
} | ||
|
||
(async () => { | ||
console.info('Build emoji'); | ||
|
||
try { | ||
const emojiData = await getEmojiData(); | ||
|
||
if (emojiData) { | ||
writeEmojiPage(emojiData); | ||
writeEmojiJS(emojiData); | ||
} | ||
} catch (err) { | ||
console.warn(`- Error: ${err.message}`); | ||
} | ||
})(); |
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.