Skip to content

Commit a05b7ed

Browse files
committed
refactor: 不再打包 emot.js 而是将它内置评论系统中
1 parent 6b21a16 commit a05b7ed

File tree

4 files changed

+9
-23
lines changed

4 files changed

+9
-23
lines changed

rollup.config.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,5 @@ export default [
8585
file: production ? 'dist/discuss.admin.js' : 'public/dist/discuss.admin.js'
8686
},
8787
plugins
88-
},
89-
{
90-
input: 'src/client/emot.js',
91-
output: {
92-
sourcemap: true,
93-
format: 'iife',
94-
name: 'discussEmot',
95-
file: production ? 'dist/emot.js' : 'public/dist/emot.js'
96-
},
97-
plugins
9888
}
9989
]
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { version } from '../../package.json'
1+
import { version } from '../../../package.json'
22

33
const key = [
44
'应援',
@@ -133,7 +133,7 @@ const key = [
133133
'偷偷看'
134134
]
135135

136-
export default window.DiscussEmot = (emotCDN) => {
136+
export default (emotCDN) => {
137137
emotCDN = (emotCDN || 'https://unpkg.com').replace(/\/$/, '') + `/discuss@${version}/assets/emot/`
138138
const items = {}
139139
for (const i of key) items[i] = emotCDN + i + '.png'
@@ -176,7 +176,7 @@ export default window.DiscussEmot = (emotCDN) => {
176176
太可怕了: 'ヽ(*。>Д<)o゜'
177177
}
178178
},
179-
['<img src="' + items['鼓掌'] + '">']: {
179+
[`<img src=${items['鼓掌']}>`]: {
180180
type: 'image',
181181
items: items
182182
}

src/client/lib/import.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ scriptUrl = scriptUrl
1111
.replace(/\/[^/]+$/, '/') // 去除文件名
1212

1313
window.DChunk = []
14-
const map = { emot: 'emot.js', admin: 'discuss.admin.js' }
14+
const map = { admin: 'discuss.admin.js' }
1515
const loadScript = (chunk, callback) => {
1616
if (window.DChunk.includes(chunk)) return callback()
1717
window.DChunk.push(chunk)

src/client/view/submit.svelte

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { onMount, afterUpdate, createEventDispatcher } from 'svelte'
33
import { options, msg, lazy } from '../lib/stores'
44
import request from '../lib/request'
5-
import loadScript from '../lib/import'
5+
import emotFn from '../lib/emot'
66
import Emotion from '../../../assets/svg/Emotion.svg'
77
import Loading from '../../../assets/svg/Loading.svg'
88
import Setting from '../../../assets/svg/Setting.svg'
@@ -93,9 +93,7 @@
9393
if (/\.json$/.test(emot)) {
9494
emotMaps = await request({ url: emot, method: 'GET' })
9595
} else if (!emot) {
96-
loadScript('emot', () => {
97-
emotMaps = window.discussEmot(D.emotCDN)
98-
})
96+
emotMaps = emotFn(D.emotCDN)
9997
} else {
10098
emotMaps = emot
10199
}
@@ -117,12 +115,10 @@
117115
function ParseEmot() {
118116
getEmotAll()
119117
let content = metas.content.value
120-
const reg = /\[(?<emot>.*?)\]/g
121118
const emots = []
122-
const arr = content.matchAll(reg)
123-
for (const item of arr) {
124-
emots.push(item.groups.emot)
125-
}
119+
content.replace(/\[(.*?)\]/g, ($0, $1) => {
120+
emots.push($1)
121+
})
126122
127123
for (const emot of emots) {
128124
const link = emotAll[emot]

0 commit comments

Comments
 (0)