You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
877 B
40 lines
877 B
'use strict'; |
|
|
|
const { htmlTag } = require('hexo-util'); |
|
const qs = require('querystring'); |
|
const { default: moize } = require('moize'); |
|
|
|
function mailToHelper(path, text, options = {}) { |
|
if (Array.isArray(path)) path = path.join(','); |
|
if (!text) text = path; |
|
|
|
const attrs = Object.assign({ |
|
href: `mailto:${path}`, |
|
title: text |
|
}, options); |
|
|
|
if (attrs.class && Array.isArray(attrs.class)) { |
|
attrs.class = attrs.class.join(' '); |
|
} |
|
|
|
const data = {}; |
|
|
|
['subject', 'cc', 'bcc', 'body'].forEach(i => { |
|
const item = attrs[i]; |
|
|
|
if (item) { |
|
data[i] = Array.isArray(item) ? item.join(',') : item; |
|
attrs[i] = null; |
|
} |
|
}); |
|
|
|
const querystring = qs.stringify(data); |
|
if (querystring) attrs.href += `?${querystring}`; |
|
|
|
return htmlTag('a', attrs, text); |
|
} |
|
|
|
module.exports = moize(mailToHelper, { |
|
maxSize: 10, |
|
isDeepEqual: true |
|
});
|
|
|