-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
34 lines (29 loc) · 775 Bytes
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function dropTitle(content) {
return content.replace(/#.+?##/s, '##')
}
function dropAnchor(content) {
return content.replace(/<a.+<\/a>\n/g, '\n')
}
function replaceBrWithNewline(content) {
return content.replace(/<br \/>/g, '\n')
}
function processImg(content) {
return content
//return content.replace(
// /!\[\S*\]\((.*?)\)/g,
// '<img src="$1" referrerpolicy="no-referrer">'
//)
}
function getYuqueSlug(url) {
let lastSlashContent = url.split('/').pop()
if (lastSlashContent.includes('?')) return lastSlashContent.split('?').shift()
if (lastSlashContent.includes('#')) return lastSlashContent.split('#').shift()
return lastSlashContent
}
module.exports = {
dropTitle,
dropAnchor,
replaceBrWithNewline,
processImg,
getYuqueSlug
}