-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Feature: add file-name for customurl
add $fileName arg for customUrl ISSUES CLOSED: #173
- Loading branch information
1 parent
3c6b329
commit c59e2bc
Showing
5 changed files
with
29 additions
and
18 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
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 |
---|---|---|
@@ -1,13 +1,31 @@ | ||
import db from '../../datastore' | ||
|
||
export default (style, url) => { | ||
const formatCustomLink = (customLink, item) => { | ||
let fileName = item.fileName.replace(new RegExp(`\\${item.extname}$`), '') | ||
let url = item.url || item.imgUrl | ||
let formatObj = { | ||
url, | ||
fileName | ||
} | ||
let keys = Object.keys(formatObj) | ||
keys.forEach(item => { | ||
if (customLink.indexOf(`$${item}`) !== -1) { | ||
let reg = new RegExp(`\\$${item}`, 'g') | ||
customLink = customLink.replace(reg, formatObj[item]) | ||
} | ||
}) | ||
return customLink | ||
} | ||
|
||
export default (style, item) => { | ||
let url = item.url || item.imgUrl | ||
const customLink = db.read().get('settings.customLink').value() || '$url' | ||
const tpl = { | ||
'markdown': `![](${url})`, | ||
'HTML': `<img src="${url}"/>`, | ||
'URL': url, | ||
'UBB': `[IMG]${url}[/IMG]`, | ||
'Custom': customLink.replace(/\$url/g, url) | ||
'Custom': formatCustomLink(customLink, item) | ||
} | ||
return tpl[style] | ||
} |
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