[feat] linkcard self-hosting
This commit is contained in:
parent
76a2f37979
commit
e1eb07a11e
|
@ -280,6 +280,11 @@ footer:
|
||||||
|
|
||||||
######## Tag Plugins ########
|
######## Tag Plugins ########
|
||||||
tag_plugins:
|
tag_plugins:
|
||||||
|
# {% link %}
|
||||||
|
linkcard:
|
||||||
|
# 设置 api 可以自动提取网页标题、图标,服务部署方法:https://github.com/xaoxuu/site-info-api/
|
||||||
|
# 接口测试通过后,把按钮的 href 部分替换成 ${href} 之后填写到下方,例如:https://api.vlts.cc/site_info/v1?url=${href}
|
||||||
|
api:
|
||||||
# {% box %} / {% note %}
|
# {% box %} / {% note %}
|
||||||
note:
|
note:
|
||||||
default_color: '' # light, dark, red, orange, yellow, green, cyan, blue, purple, warning, error
|
default_color: '' # light, dark, red, orange, yellow, green, cyan, blue, purple, warning, error
|
||||||
|
|
|
@ -10,6 +10,13 @@
|
||||||
module.exports = ctx => function(args) {
|
module.exports = ctx => function(args) {
|
||||||
const full_url_for = require('hexo-util').full_url_for.bind(ctx)
|
const full_url_for = require('hexo-util').full_url_for.bind(ctx)
|
||||||
args = ctx.args.map(args, ['icon', 'desc'], ['url', 'title'])
|
args = ctx.args.map(args, ['icon', 'desc'], ['url', 'title'])
|
||||||
|
if (args.url == null) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
args.api = ctx.theme.config.tag_plugins.linkcard.api
|
||||||
|
if (args.api) {
|
||||||
|
args.api = args.api.replace('${href}', args.url)
|
||||||
|
}
|
||||||
var autofill = []
|
var autofill = []
|
||||||
if (!args.title) {
|
if (!args.title) {
|
||||||
autofill.push('title')
|
autofill.push('title')
|
||||||
|
@ -27,6 +34,9 @@ module.exports = ctx => function(args) {
|
||||||
el += ' target="_blank" rel="external nofollow noopener noreferrer"'
|
el += ' target="_blank" rel="external nofollow noopener noreferrer"'
|
||||||
}
|
}
|
||||||
el += ' cardlink'
|
el += ' cardlink'
|
||||||
|
if (args.api) {
|
||||||
|
el += ` api="${args.api}"`
|
||||||
|
}
|
||||||
el += ' autofill="'
|
el += ' autofill="'
|
||||||
el += autofill.join(',')
|
el += autofill.join(',')
|
||||||
el += '"'
|
el += '"'
|
||||||
|
|
|
@ -30,11 +30,11 @@ function setCardLink(nodes) {
|
||||||
nodes = 'forEach' in (nodes || {}) ? nodes : document.querySelectorAll('a[cardlink]')
|
nodes = 'forEach' in (nodes || {}) ? nodes : document.querySelectorAll('a[cardlink]')
|
||||||
nodes.forEach((el) => {
|
nodes.forEach((el) => {
|
||||||
// If it is not a tag element then it is not processed
|
// If it is not a tag element then it is not processed
|
||||||
if (el.nodeType !== 1) return
|
if (el.nodeType !== 1) return;
|
||||||
el.removeAttribute('cardlink');
|
el.removeAttribute('cardlink');
|
||||||
const link = el.href;
|
const api = el.getAttribute('api');
|
||||||
const api = 'https://api.vlts.cc/site_info/v1?url=';
|
if (api == null) return;
|
||||||
fetch(api + link).then(function(response) {
|
fetch(api).then(function(response) {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
return response.json();
|
return response.json();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue