Skip to content

Commit 8b70b32

Browse files
authored
Merge branch 'develop' into delete-ie11
2 parents 75f9f9e + 63b2535 commit 8b70b32

30 files changed

+6903
-2204
lines changed

.codesandbox/ci.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"sandboxes": ["2d17z"],
3-
"packages": [".", "packages/docsify-server-renderer"]
3+
"packages": [".", "packages/docsify-server-renderer"],
4+
"node": "16"
45
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
## Links
3131

32-
- [`develop` branch preview](https://docsifyjs.netlify.com/)
32+
- [`develop` branch preview](https://docsify-preview.vercel.app/)
3333
- [Documentation](https://docsify.js.org)
3434
- [CLI](https://github.com/docsifyjs/docsify-cli)
3535
- CDN: [UNPKG](https://unpkg.com/docsify/) | [jsDelivr](https://cdn.jsdelivr.net/npm/docsify/) | [cdnjs](https://cdnjs.com/libraries/docsify)

build/emoji.js

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
const axios = require('axios');
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
const filePaths = {
6+
emojiMarkdown: path.resolve(process.cwd(), 'docs', 'emoji.md'),
7+
emojiJS: path.resolve(
8+
process.cwd(),
9+
'src',
10+
'core',
11+
'render',
12+
'emoji-data.js'
13+
),
14+
};
15+
16+
async function getEmojiData() {
17+
const emojiDataURL = 'https://api.github.com/emojis';
18+
19+
console.info(`- Fetching emoji data from ${emojiDataURL}`);
20+
21+
const response = await axios.get(emojiDataURL);
22+
const baseURL = Object.values(response.data)
23+
.find(url => /unicode\//)
24+
.split('unicode/')[0];
25+
const data = { ...response.data };
26+
27+
// Remove base URL from emoji URLs
28+
Object.entries(data).forEach(
29+
([key, value]) => (data[key] = value.replace(baseURL, ''))
30+
);
31+
32+
console.info(`- Retrieved ${Object.keys(data).length} emoji entries`);
33+
34+
return {
35+
baseURL,
36+
data,
37+
};
38+
}
39+
40+
function writeEmojiPage(emojiData) {
41+
const isExistingPage = fs.existsSync(filePaths.emojiMarkdown);
42+
const emojiPage =
43+
(isExistingPage && fs.readFileSync(filePaths.emojiMarkdown, 'utf8')) ||
44+
`<!-- START -->\n\n<!-- END -->`;
45+
const emojiRegEx = /(<!--\s*START.*-->\n)([\s\S]*)(\n<!--\s*END.*-->)/;
46+
const emojiMatch = emojiPage.match(emojiRegEx);
47+
const emojiMarkdownStart = emojiMatch[1].trim();
48+
const emojiMarkdown = emojiMatch[2].trim();
49+
const emojiMarkdownEnd = emojiMatch[3].trim();
50+
const newEmojiMarkdown = Object.keys(emojiData.data)
51+
.reduce(
52+
(preVal, curVal) =>
53+
(preVal += `:${curVal}: ` + '`' + `:${curVal}:` + '`' + '\n\n'),
54+
''
55+
)
56+
.trim();
57+
58+
if (emojiMarkdown !== newEmojiMarkdown) {
59+
const newEmojiPage = emojiPage.replace(
60+
emojiMatch[0],
61+
`${emojiMarkdownStart}\n\n${newEmojiMarkdown}\n\n${emojiMarkdownEnd}`
62+
);
63+
64+
fs.writeFileSync(filePaths.emojiMarkdown, newEmojiPage);
65+
66+
console.info(
67+
`- ${!isExistingPage ? 'Created' : 'Updated'}: ${filePaths.emojiMarkdown}`
68+
);
69+
} else {
70+
console.info(`- No changes: ${filePaths.emojiMarkdown}`);
71+
}
72+
}
73+
74+
function writeEmojiJS(emojiData) {
75+
const isExistingPage = fs.existsSync(filePaths.emojiJS);
76+
const emojiJS = isExistingPage && fs.readFileSync(filePaths.emojiJS, 'utf8');
77+
const newEmojiJS = [
78+
'/* eslint-disable */\n',
79+
'// =============================================================================',
80+
'// DO NOT EDIT: This file is auto-generated by an /build/emoji.js',
81+
'// =============================================================================\n',
82+
`export default ${JSON.stringify(emojiData, {}, 2)}`,
83+
].join('\n');
84+
85+
if (!emojiJS || emojiJS !== newEmojiJS) {
86+
fs.writeFileSync(filePaths.emojiJS, newEmojiJS);
87+
88+
console.info(
89+
`- ${!isExistingPage ? 'Created' : 'Updated'}: ${filePaths.emojiJS}`
90+
);
91+
} else {
92+
console.info(`- No changes: ${filePaths.emojiJS}`);
93+
}
94+
}
95+
96+
(async () => {
97+
console.info('Build emoji');
98+
99+
try {
100+
const emojiData = await getEmojiData();
101+
102+
if (emojiData) {
103+
writeEmojiPage(emojiData);
104+
writeEmojiJS(emojiData);
105+
}
106+
} catch (err) {
107+
console.warn(`- Error: ${err.message}`);
108+
}
109+
})();

docs/_sidebar.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- [Write a Plugin](write-a-plugin.md)
1414
- [Markdown configuration](markdown.md)
1515
- [Language highlighting](language-highlight.md)
16+
- [Emoji](emoji.md)
1617

1718
- Guide
1819

0 commit comments

Comments
 (0)