mirror of
https://github.com/wahyd4/vuepress.git
synced 2026-08-13 15:25:51 +10:00
25 lines
551 B
JavaScript
25 lines
551 B
JavaScript
module.exports = function parseSlots (str) {
|
|
const map = {}
|
|
str.split('|slot|')
|
|
.filter(v => v.trim())
|
|
.forEach(v => {
|
|
let slotKey
|
|
let content
|
|
if (v.startsWith('$$')) {
|
|
content = v.slice(2)
|
|
const endIndex = content.indexOf('$$')
|
|
slotKey = content.slice(0, endIndex)
|
|
content = content.slice(endIndex + 2)
|
|
} else {
|
|
slotKey = 'default'
|
|
content = v
|
|
}
|
|
if (!map[slotKey]) {
|
|
map[slotKey] = ''
|
|
}
|
|
map[slotKey] += content
|
|
})
|
|
return map
|
|
}
|
|
|