UNPKG

hexo-butterfly-tag-plugins-plus-chinese

Version:

A number of tag plugins for theme-butterfly

918 lines (830 loc) 30 kB
'use strict' const urlFor = require('hexo-util').url_for.bind(hexo) hexo.extend.filter.register('after_generate', function (locals) { // 首先获取整体的配置项名称 const config = hexo.config.tag_plugins || hexo.theme.config.tag_plugins // 如果配置开启 if (!(config && config.enable)) return // 集体声明配置项 const data = { issues: config.issues ? config.issues : false, animaCDN: config.CDN.anima ? urlFor(config.CDN.anima) : 'https://unpkg.com/hexo-butterfly-tag-plugins-plus-chinese@latest/lib/assets/font-awesome-animation.min.css', jqueryCDN: config.CDN.jquery ? urlFor(config.CDN.jquery) : 'https://unpkg.com/jquery@latest/dist/jquery.min.js', issuesCDN: config.CDN.issues ? urlFor(config.CDN.issues) : 'https://unpkg.com/hexo-butterfly-tag-plugins-plus-chinese@latest/lib/assets/issues.js', iconfontCDN: config.CDN.iconfont, carouselCDN: config.CDN.carousel, tag_plugins_css: config.CDN.tag_plugins_css ? urlFor(config.CDN.tag_plugins_css) : 'https://unpkg.com/hexo-butterfly-tag-plugins-plus-chinese@latest/lib/tag_plugins.css' } //cdn资源声明 //样式资源 //head引入资源 const css_text = `<link rel="stylesheet" href="${data.animaCDN}" media="defer" onload="this.media='all'"><link rel="stylesheet" href="${data.tag_plugins_css}" media="defer" onload="this.media='all'">` const carousel_cdn = `<script src="${data.carouselCDN}"></script>` //bottom引入资源 const js_text = `<script defer src="${data.jqueryCDN}"></script><script defer src="${data.issuesCDN}"></script>` //iconfont symbol引入 const iconfont_symbol = `<script async src="${data.iconfontCDN}"></script>` // 注入脚本资源 hexo.extend.injector.register('head_end', css_text, "default"); if (data.carouselCDN){ hexo.extend.injector.register('head_end', carousel_cdn, "default"); } // 注入样式资源 if (data.issues){ hexo.extend.injector.register('body_end', js_text, "default"); } if (data.iconfontCDN){ hexo.extend.injector.register('body_end', iconfont_symbol, "default"); } }, hexo.extend.helper.register('priority', function(){ // 过滤器优先级,priority 值越低,过滤器会越早执行,默认priority是10 const pre_priority = hexo.config.tag_plugins.priority ? hexo.config.tag_plugins.priority : hexo.theme.config.tag_plugins.priority const priority = pre_priority ? pre_priority : 10 return priority }) ) //btns.js function postBtns(args, content) { let style = args.join(' ') let grid = '' style.indexOf("方") > -1 && (grid += "rounded "), style.indexOf("圆") > -1 && (grid += "circle "), style.indexOf("2格") > -1 && (grid += "grid2 "), style.indexOf("3格") > -1 && (grid += "grid3"), style.indexOf("4格") > -1 && (grid += "grid4 "), style.indexOf("5格") > -1 && (grid += "grid5 "), style.indexOf("居中") > -1 && (grid += "center "), style.indexOf("宽") > -1 && (grid += "wide "), style.indexOf("填充") > -1 && (grid += "fill "), style.indexOf("居中分散") > -1 && (grid += "around "), "" == grid && (grid = style) return `<div class="btns ${grid}"> ${content} </div>`; } function postCell(args) { args = args.join(' ').split(',') let text = args[0] || '' let url = args[1] || '' text = text.trim() url = url.trim() if (url.length > 0) { url = "href='" + url + "'" } let icon = '' let img = 'https://unpkg.com/hexo-butterfly-tag-plugins-plus-chinese@latest/lib/assets/default.svg' if (args.length > 2) { if (args[2].indexOf(' fa-') > -1) { icon = args[2].trim() } else { img = args[2].trim() } } if (icon.length > 0) { return `<a class="button" ${url} title='${text}'><i class='${icon}'></i>${text}</a>` } else { return `<a class="button" ${url} title='${text}'><img src='${img}'>${text}</a>` } } hexo.extend.tag.register('按钮组', postBtns, {ends: true}); hexo.extend.tag.register('btns', postBtns, {ends: true}); hexo.extend.tag.register('按钮', postCell); hexo.extend.tag.register('cell', postCell); //checkbox.js function postCheckbox(args) { args = args.join(' ').split(',') var state = args[0].trim() var colour = '' var text = '' var checked = false if (args.length == 1) { text = (args[0] || '').trim() } else if (args.length == 2) { state.indexOf("v") > -1 && (colour += "checked ", checked = true), state.indexOf("+") > -1 && (colour += "plus checked ", checked = true), state.indexOf("-") > -1 && (colour += "minus checked ", checked = true), state.indexOf("x") > -1 && (colour += "times checked ", checked = true), state.indexOf("红色") > -1 && (colour += "red "), state.indexOf("黄色") > -1 && (colour += "yellow "), state.indexOf("绿色") > -1 && (colour += "green "), state.indexOf("青色") > -1 && (colour += "cyan "), state.indexOf("蓝色") > -1 && (colour += "blue "), state.indexOf("手写") > -1 && (colour += "handwriting "), state.indexOf("黑体") > -1 && (colour += "SimHei "), state.indexOf("宋体") > -1 && (colour += "SimSun "), state.indexOf("楷体") > -1 && (colour += "KaiTi "), state.indexOf("checked") > -1 && (checked = true), ""==colour&&(colour=state) text = (args[1] || '').trim() } if (text.length > 0) { return `<div class='checkbox ${colour}'><input type="checkbox" ${checked ? 'checked="checked"' : ''}/> ${hexo.render.renderSync({ text: text, engine: 'markdown' }).split('\n').join('')} </div>` } } function postRadio(args) { args = args.join(' ').split(',') var state = args[0].trim() var colour = '' var text = '' var checked = false if (args.length == 1) { text = (args[0] || '').trim() } else if (args.length == 2) { state.indexOf("v") > -1 && (colour += "checked ", checked = true), state.indexOf("红色") > -1 && (colour += "red "), state.indexOf("黄色") > -1 && (colour += "yellow "), state.indexOf("绿色") > -1 && (colour += "green "), state.indexOf("青色") > -1 && (colour += "cyan "), state.indexOf("蓝色") > -1 && (colour += "blue "), state.indexOf("手写") > -1 && (colour += "handwriting "), state.indexOf("黑体") > -1 && (colour += "SimHei "), state.indexOf("宋体") > -1 && (colour += "SimSun "), state.indexOf("楷体") > -1 && (colour += "KaiTi "), state.indexOf("checked") > -1 && (checked = true), ""==colour&&(colour=state) text = (args[1] || '').trim() } if (text.length > 0) { return `<div class='checkbox ${colour}'><input type="radio" ${checked ? 'checked="checked"' : ''}/> ${hexo.render.renderSync({ text: text, engine: 'markdown' }).split('\n').join('')} </div>` } } // {% checkbox text %} // {% checkbox checked, text %} // {% checkbox color checked, text %} hexo.extend.tag.register('复选', postCheckbox); hexo.extend.tag.register('checkbox', postCheckbox); hexo.extend.tag.register('单选', postRadio); hexo.extend.tag.register('radio', postRadio); //folding.js function postFolding(args, content) { args = args.join(' ').split(','); let style = '' let colour = args[0].trim() let title = '' if (args.length == 1) { title = args[0].trim() } else if (args.length == 2) { colour.indexOf("打开") > -1 && (style += "open "), colour.indexOf("红色") > -1 && (style += "red "), colour.indexOf("橙色") > -1 && (style += "orange "), colour.indexOf("黄色") > -1 && (style += "yellow "), colour.indexOf("绿色") > -1 && (style += "green "), colour.indexOf("青色") > -1 && (style += "cyan "), colour.indexOf("蓝色") > -1 && (style += "blue "), colour.indexOf("紫色") > -1 && (style += "purple "), "" == style && (style = colour) title = args[1].trim() } if (colour != undefined) { return `<details class="folding-tag" ${style}><summary> ${title} </summary> <div class='content'> ${hexo.render.renderSync({ text: content, engine: 'markdown' }).split('\n').join('')} </div> </details>` } else { return `<details class="folding-tag"><summary> ${title} </summary> <div class='content'> ${hexo.render.renderSync({ text: content, engine: 'markdown' }).split('\n').join('')} </div> </details>` } } hexo.extend.tag.register('折叠', postFolding, {ends: true}) hexo.extend.tag.register('folding', postFolding, {ends: true}) //ghbdage.js /*{% bdage right,left,[logo]||[color],[link],[title]||option %}*/ function bdage (args) { args = args.join(' ').split('||') let base= args[0]?args[0].split(','):'' let left = base[0]?encodeURI(base[0].trim()):'' let right = base[1]?encodeURI(base[1].trim()):'' let logo = base[2]?base[2].trim():'' let message = args[1]?args[1].split(','):'' let color = message[0]?message[0].trim():'orange' let link = message[1]?message[1].trim():'' let title = message[2]?message[2].trim():'' let option = args[2]?args[2].trim():'' return `<object class="ghbdage" style="margin-inline:5px" title="${title}" standby="loading..." data="https://img.shields.io/badge/${left}-${right}-orange?logo=${logo}&color=${color}&link=${link}&${option}"></object>` } hexo.extend.tag.register('徽标',bdage); hexo.extend.tag.register('bdage',bdage); //ghcard.js /** * https://github.com/anuraghazra/github-readme-stats */ // {% ghcard volantis-x %} // {% ghcard volantis-x/hexo-theme-volantis %} function ghCard(args) { args = args.join(' ').split(', '); let path = args[0].trim(); let card = ''; card += '<a class="ghcard" rel="external nofollow noopener noreferrer" href="https://github.com/' + path + '">'; let url = ''; if (path.includes('/')) { // is repo let ps = path.split('/'); url += 'https://github-readme-stats.vercel.app/api/pin/?username=' + ps[0] + "&repo=" + ps[1]; } else { // is user url += 'https://github-readme-stats.vercel.app/api/?username=' + path; } if (args.length > 1) { for (let i = 1; i < args.length; i++) { let tmp = args[i].trim(); url += "&" + tmp; } } if (!url.includes('&show_owner=')) { url += '&show_owner=true'; } card += '<img src="' + url + '"/>'; card += '</a>'; return card; } hexo.extend.tag.register('gh卡片', ghCard); hexo.extend.tag.register('ghcard', ghCard); function ghCardGroup(args, content) { let ret = ''; // wrap ret += '<div class="ghcard-group">'; ret += content; ret += '</div>'; return ret; } hexo.extend.tag.register('gh卡片组', ghCardGroup, {ends: true}); hexo.extend.tag.register('ghcardgroup', ghCardGroup, {ends: true}); //iconfont.js function iconFont(args) { args = args.join(' ').split(',') let p0 = args[0] let p1 = args[1]?args[1]:1 return `<svg class="icon" style="width:${p1}em; height:${p1}em" aria-hidden="true"><use xlink:href="#${p0}"></use></svg>`; } hexo.extend.tag.register('阿里图标',iconFont); hexo.extend.tag.register('icon',iconFont); //image.js // {% image url %} // {% image url, alt=haha %} // {% image url, width=50% %} // {% image url, height=32px %} // {% image url, bg=#eee %} // {% image url, alt=haha, width=400px %} // {% image url, alt=haha, width=400px, bg=#eee %} function imaGe(args) { args = args.join(' ').split(', '); let url = args[0].trim(); let alt = ''; let bg = ''; let style = ''; if (args.length > 1) { for (let i = 1; i < args.length; i++) { let tmp = args[i].trim(); if (tmp.includes('描述=')) { alt = tmp.substring(3, tmp.length); } else if (tmp.includes('宽=')) { style += 'width:' + tmp.substring(2, tmp.length) + ';'; } else if (tmp.includes('高=')) { style += 'height:' + tmp.substring(2, tmp.length) + ';'; } else if (tmp.includes('背景=')) { bg = tmp.substring(3, tmp.length); } else if (tmp.includes('alt=')) { alt = tmp.substring(4, tmp.length); } else if (tmp.includes('width=')) { style += 'width:' + tmp.substring(6, tmp.length) + ';'; } else if (tmp.includes('height=')) { style += 'height:' + tmp.substring(7, tmp.length) + ';'; } else if (tmp.includes('bg=')) { bg = tmp.substring(3, tmp.length); } } } function img(url, alt, style) { let img = ''; img += '<img class="img" src="' + url + '"'; if (alt.length > 0) { img += ' alt="' + alt + '"'; } if (style.length > 0) { img += ' style="' + style + '"'; } img += '/>'; return img; } let ret = ''; // wrap ret += '<div class="img-wrap">'; // bg ret += '<div class="img-bg"'; if (bg.length > 0) { ret += ' style="background:' + bg + '"'; } ret += '>'; ret += img(url, alt, style); ret += '<div class="img-alt is-center">' + alt + '</div>' ret += '</div>'; if (alt.length > 0) { ret += '<span class="image-caption">' + alt + '</span>'; } ret += '</div>'; return ret; } hexo.extend.tag.register('图片', imaGe); hexo.extend.tag.register('image', imaGe); // {% inlineimage url %} // {% inlineimage url, height=22px %} function inlineImage(args) { args = args.join(' ').split(', '); let url = args[0].trim(); let ret = ''; ret += '<img no-lazy class="inline" src="' + url + '"'; let style = ''; if (args.length > 1) { for (let i = 1; i < args.length; i++) { let tmp = args[i].trim(); if (tmp.includes('高=')) { style += 'height:' + tmp.substring(2, tmp.length) + ';'; } else if (tmp.includes('height=')) { style += 'height:' + tmp.substring(7, tmp.length) + ';'; } } } if (style.length > 0) { ret += ' style="' + style + '"'; } else { ret += ' style="height:1.5em"'; } ret += '/>'; return ret; } hexo.extend.tag.register('行内图片', inlineImage); hexo.extend.tag.register('inlineimage', inlineImage); //inline-labels.js function postU(args) { return `<u>${args.join(' ')}</u>`; } function postEmp(args) { return `<emp>${args.join(' ')}</emp>`; } function postWavy(args) { return `<wavy>${args.join(' ')}</wavy>`; } function postDel(args) { return `<del>${args.join(' ')}</del>`; } function postKbd(args) { return `<kbd>${args.join(' ')}</kbd>`; } function postPsw(args) { return `<psw>${args.join(' ')}</psw>`; } hexo.extend.tag.register('下划线', postU); hexo.extend.tag.register('u', postU); hexo.extend.tag.register('着重号', postEmp); hexo.extend.tag.register('emp', postEmp); hexo.extend.tag.register('波浪线', postWavy); hexo.extend.tag.register('wavy', postWavy); hexo.extend.tag.register('删除线', postDel); hexo.extend.tag.register('del', postDel); hexo.extend.tag.register('按键', postKbd); hexo.extend.tag.register('kbd', postKbd); hexo.extend.tag.register('密码', postPsw); hexo.extend.tag.register('psw', postPsw); //issues.js // 从 issues 加载动态数据 // {% issues sites/timeline/friends | api=xxx | group=key:a,b,c %} // 例如: // {% issues sites | api=https://api.github.com/repos/volantis-x/examples/issues?sort=updated&state=open&page=1&per_page=100 | group=version:latest,v6,v5,v4,v3,v2,v1,v0 %} function DataCollection(args) { args = args.join(' ').split(' | '); // 所有支持的参数 let type = args[0].trim(); let api = ''; let group = ''; // 解析 if (args.length > 1) { for (let i = 1; i < args.length; i++) { let tmp = args[i].trim(); if (tmp.includes('type=')) { type = tmp.substring(5, tmp.length); } else if (tmp.includes('api=')) { api = tmp.substring(4, tmp.length); } else if (tmp.includes('group=')) { group = tmp.substring(6, tmp.length); } } } if (type.length == 0 || api.length == 0) { return; } // 布局 let ret = '<div class="issues-api ' + type + '"'; ret += 'api="' + api + '"'; if (group.length > 0) { ret += 'group="' + group + '"'; } ret += '></div>'; return ret; } hexo.extend.tag.register('数据集合', DataCollection); hexo.extend.tag.register('issues', DataCollection); //link.js // {% link title, url %} // {% link title, url, img %} function links(args) { var configtemp = hexo.config.tag_plugins || hexo.theme.config.tag_plugins args = args.join(' ').split(',') let text = '' let url = '' let img = '' if (args.length < 2) { return } else if (args.length == 2) { text = args[0].trim() url = args[1].trim() } else if (args.length == 3) { text = args[0].trim() url = args[1].trim() img = args[2].trim() } let result = ''; // 发现如果不套一层 div 在其它可渲染 md 的容器中容易被分解 result += '<div class="tag link"><a class="link-card" title="' + text + '" href="' + url + '">'; // left result += '<div class="left">'; result += '<img src="' + (img || configtemp.link.placeholder) + '"/>'; result += '</div>'; // right result += '<div class="right"><p class="text">' + text + '</p><p class="url">' + url + '</p></div>'; result += '</a></div>'; return result; } hexo.extend.tag.register('链接', links); hexo.extend.tag.register('link', links); function linkGroup(args, content) { let ret = ''; ret += '<div class="link-group">'; ret += content; ret += '</div>'; return ret; } hexo.extend.tag.register('链接组', linkGroup, {ends: true}); hexo.extend.tag.register('linkgroup', linkGroup, {ends: true}); //media.js function postAudio(args) { let src = args[0].trim() return `<div class="audio"><audio controls preload><source src='${src}' type='audio/mp3'>Your browser does not support the audio tag.</audio></div>`; } function postVideo(args) { let src = args[0].trim() return `<div class="video"><video controls preload><source src='${src}' type='video/mp4'>Your browser does not support the video tag.</video></div>`; } function postVideos(args, content) { args = args.join(' ').split(',') var cls = args[0] if (cls.length > 0) { cls = ' ' + cls } var col = Number(args[1]) || 0; if (col > 0) { return `<div class="videos${cls}" col='${col}'>${content}</div>` } else { return `<div class="videos${cls}">${content}</div>` } } hexo.extend.tag.register('音频', postAudio); hexo.extend.tag.register('视频', postVideo); hexo.extend.tag.register('视频组', postVideos, {ends: true}); hexo.extend.tag.register('audio', postAudio); hexo.extend.tag.register('video', postVideo); hexo.extend.tag.register('videos', postVideos, {ends: true}); //notation.js function Nota(args) { args = args.join(' ').split(',') let p0 = args[0].trim() let p1 = args[1].trim() return `<span class='nota' data-nota='${p1}'>${p0}</span>`; } hexo.extend.tag.register('注释', Nota); hexo.extend.tag.register('nota', Nota); // {% nota 注释词汇 ,'注释内容,使用逗号间隔开了即可' %} //bubble.js function bubble (args) { args = args.join(' ').split(',') let content = args[0] let notation = args[1] let color = args[2] ? args[2] : '#71a4e3' return `<span class="bubble-content">${content}</span><span class="bubble-notation"><span class="bubble-item" style="background-color:${color};">${notation}</span></span>` } hexo.extend.tag.register('气泡注释', bubble, { ends: false }) hexo.extend.tag.register('bubble', bubble, { ends: false }) /** * bubble * {% bubble content,notation[,background-color] %} */ //reference.js /* {% referto 'id','literature' %} {% referfrom 'id','literature','url' %} */ function referto (args) { args = args.join(' ').split(',') let referid = args[0] let literature = args[1] return `<span class="hidden-anchor" id="referto_${referid}"></span><sup class="reference"><a href="#referfrom_${referid}">${referid}</a></sup><span class="reference-bubble"><span class="reference-item"><span class="reference-literature">${literature}</span><span class="reference-title">参考资料</span></span></span>`; } function referfrom (args) { args = args.join(' ').split(',') let fromid = args[0] let fromliterature = args[1] let referurl = args[2] ? urlFor(args[2]) : 'javascript:void' return `<div class="reference-source"><span class="hidden-anchor" id="referfrom_${fromid}"></span><a class="reference-anchor" href="#referto_${fromid}">${fromid}<div class="reference-anchor-up fa-solid fa-angles-up"></div></a><a class="reference-link" href="${referurl}">${fromliterature}</a></div>`; } hexo.extend.tag.register('引用',referto); hexo.extend.tag.register('referto',referto); hexo.extend.tag.register('文献',referfrom); hexo.extend.tag.register('referfrom',referfrom); //poem.js function poem(args, content) { args = args.join(' ').split(',') let p0 = args[0] let p1 = args[1] ? args[1] : '' let styl = '' if (args.length > 2) { if (args[2].trim() == "手写") { styl = 'handwriting' } else if (args[2].trim() == "黑体") { styl = 'SimHei' } else if (args[2].trim() == "楷体") { styl = 'SimSun' } else if (args[2].trim() == "宋体") { styl = 'KaiTi' }else { styl = args[2].trim() } } return `<div class='poem ${styl}'><div class='poem-title'>${p0}</div><div class='poem-author'>${p1}</div>${hexo.render.renderSync({ text: content, engine: 'markdown' })}</div>` } hexo.extend.tag.register('诗词',poem,{ ends: true }); hexo.extend.tag.register('poem',poem,{ ends: true }); //progress.js function postprogress(args) { args = args.join(',').split(',') if (args.length > 1) { let pwidth = args[0].trim() let pcolor = args[1].trim() switch (pcolor) { case "红色": pcolor = 'red' break case "黄色": pcolor = 'yellow' break case "绿色": pcolor = 'green' break case "青色": pcolor = 'cyan' break case "蓝色": pcolor = 'blue' break case "灰色": pcolor = 'gray' break default: break } let text = args[2].trim() return `<div class="progress"><div class="progress-bar-animated progress-bar progress-bar-striped bg-${pcolor}" style="width: ${pwidth}%" aria-valuenow="${pwidth}" aria-valuemin="0" aria-valuemax="100">${hexo.render.renderSync({text: text, engine: 'markdown'}).split('\n').join('')}</div></div>`; } } hexo.extend.tag.register('进度条', postprogress); hexo.extend.tag.register('progress', postprogress); //site.js function postSiteCardGroup(args, content) { if (args.length > 0) { return `<div class="site-card-group"><p class='p h2'>${args}</p>${content}</div>`; } else { return `<div class="site-card-group">${content}</div>`; } } function postSiteCard(args) { args = args.join(' ').split(', ') // 所有支持的参数 let title = args[0].trim(); let url = ''; let screenshot = ''; let avatar = ''; let description = ''; // 解析 if (args.length > 1) { for (let i = 1; i < args.length; i++) { let tmp = args[i].trim(); if (tmp.includes('链接=')) { url = tmp.substring(3, tmp.length); } else if (tmp.includes('背景=')) { screenshot = tmp.substring(3, tmp.length); } else if (tmp.includes('头像=')) { avatar = tmp.substring(3, tmp.length); } else if (tmp.includes('描述=')) { description = tmp.substring(3, tmp.length); } else if (tmp.includes('url=')) { url = tmp.substring(4, tmp.length); } else if (tmp.includes('screenshot=')) { screenshot = tmp.substring(11, tmp.length); } else if (tmp.includes('avatar=')) { avatar = tmp.substring(7, tmp.length); } else if (tmp.includes('description=')) { description = tmp.substring(12, tmp.length); } } } // 布局 let result = ''; result += '<a class="site-card" href="' + url + '">'; result += '<div class="img"><img class="no-lightbox" src="' + screenshot + '"/></div>'; result += '<div class="info">'; if (avatar.length > 0) { result += '<img class="no-lightbox" src="' + avatar + '"/>'; } else { } result += '<span class="title">' + title + '</span>'; if (description.length > 0) { result += '<span class="desc">' + description + '</span>'; } else { } result += '</div></a>'; return result; } // {% site link, img, title %} // {% site link, img, title, description %} hexo.extend.tag.register('网站', postSiteCard); hexo.extend.tag.register('网站组', postSiteCardGroup, {ends: true}); hexo.extend.tag.register('site', postSiteCard); hexo.extend.tag.register('sitegroup', postSiteCardGroup, {ends: true}); //span.js function postP(args) { args = args.join(' ').split(',') let p0 = args[0].trim() let p1 = args[1].trim() let ps = '' p0.indexOf("居中") > -1 && (ps += "center "), p0.indexOf("居左") > -1 && (ps += "left "), p0.indexOf("居右") > -1 && (ps += "right "), p0.indexOf("1") > -1 && (ps += "small "), p0.indexOf("2") > -1 && (ps += "h4 "), p0.indexOf("3") > -1 && (ps += "h3 "), p0.indexOf("4") > -1 && (ps += "h2 "), p0.indexOf("5") > -1 && (ps += "h1 "), p0.indexOf("6") > -1 && (ps += "large "), p0.indexOf("7") > -1 && (ps += "huge "), p0.indexOf("8") > -1 && (ps += "ultra "), p0.indexOf("红色") > -1 && (ps += "red "), p0.indexOf("黄色") > -1 && (ps += "yellow "), p0.indexOf("绿色") > -1 && (ps += "green "), p0.indexOf("青色") > -1 && (ps += "cyan "), p0.indexOf("蓝色") > -1 && (ps += "blue "), p0.indexOf("灰色") > -1 && (ps += "gray "), p0.indexOf("手写") > -1 && (ps += "handwriting "), p0.indexOf("黑体") > -1 && (ps += "SimHei "), p0.indexOf("宋体") > -1 && (ps += "SimSun "), p0.indexOf("楷体") > -1 && (ps += "KaiTi "), "" == ps && (ps = p0) return `<p class='p ${ps}'>${p1}</p>` } function postSpan(args) { args = args.join(' ').split(',') let p0 = args[0].trim() let p1 = args[1].trim() let ps = '' p0.indexOf("居中") > -1 && (ps += "center "), p0.indexOf("居左") > -1 && (ps += "left "), p0.indexOf("居右") > -1 && (ps += "right "), p0.indexOf("1") > -1 && (ps += "small "), p0.indexOf("2") > -1 && (ps += "h4 "), p0.indexOf("3") > -1 && (ps += "h3 "), p0.indexOf("4") > -1 && (ps += "h2 "), p0.indexOf("5") > -1 && (ps += "h1 "), p0.indexOf("6") > -1 && (ps += "large "), p0.indexOf("7") > -1 && (ps += "huge "), p0.indexOf("8") > -1 && (ps += "ultra "), p0.indexOf("红色") > -1 && (ps += "red "), p0.indexOf("黄色") > -1 && (ps += "yellow "), p0.indexOf("绿色") > -1 && (ps += "green "), p0.indexOf("青色") > -1 && (ps += "cyan "), p0.indexOf("蓝色") > -1 && (ps += "blue "), p0.indexOf("灰色") > -1 && (ps += "gray "), p0.indexOf("手写") > -1 && (ps += "handwriting "), p0.indexOf("黑体") > -1 && (ps += "SimHei "), p0.indexOf("宋体") > -1 && (ps += "SimSun "), p0.indexOf("楷体") > -1 && (ps += "KaiTi "), "" == ps && (ps = p0) return `<span class='p ${ps}'>${p1}</span>` } hexo.extend.tag.register('段', postP); hexo.extend.tag.register('行', postSpan); hexo.extend.tag.register('p', postP); hexo.extend.tag.register('span', postSpan); //tip.js function tip (args, content) { args = args.join(' ').split(',') let tipclass = '' let tipanima = '' if (args.length == 1) { tipclass = args[0].trim() switch (tipclass) { case "信息": tipclass = 'info' break case "正确": tipclass = 'success' break case "错误": tipclass = 'error' break case "警告": tipclass = 'warning' break case "突然": tipclass = 'bolt' break case "禁止": tipclass = 'ban' break case "家": tipclass = 'home' break case "循环": tipclass = 'sync' break case "设置": tipclass = 'cogs' break case "钥匙": tipclass = 'key' break case "提醒": tipclass = 'bell' break default: break } } else if (args.length == 2) { tipclass = args[0].trim() switch (tipclass) { case "信息": tipclass = 'info' break case "正确": tipclass = 'success' break case "错误": tipclass = 'error' break case "警告": tipclass = 'warning' break case "突然": tipclass = 'bolt' break case "禁止": tipclass = 'ban' break case "家": tipclass = 'home' break case "循环": tipclass = 'sync' break case "设置": tipclass = 'cogs' break case "钥匙": tipclass = 'key' break case "提醒": tipclass = 'bell' break default: break } tipanima = args[1].trim() } return `<div class="tip ${tipclass} ${tipanima}">${hexo.render.renderSync({ text: content, engine: 'markdown' })}</div>` } hexo.extend.tag.register('上标',tip, { ends: true }) hexo.extend.tag.register('tip',tip, { ends: true }) //carousel.js function carousel (args, content) { args = args.join(' ').split(',') let carouselId = args[0] let carouselname = args[1]?args[1]:'carousel' return `<div id='${carouselId}' class='carousel'><div id="${carouselId}-drag-container" class="drag-container"><div id="${carouselId}-spin-container" class="spin-container">${hexo.render.renderSync({ text: content, engine: 'markdown' }).replace(/^(\s|<p>)+|(\s|<\/p>)+$/g, '')}<p>${carouselname}</p></div><div id="${carouselId}-carousel-ground" class="carousel-ground"></div></div></div><script type="text/javascript">carouselinit('${carouselId}');</script>` } hexo.extend.tag.register('旋转相册',carousel,{ ends: true }); hexo.extend.tag.register('carousel',carousel,{ ends: true });