From baf6952254f9635b881bd7f0b97f60a49454ff43 Mon Sep 17 00:00:00 2001 From: xaoxuu Date: Fri, 19 Nov 2021 20:25:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96link=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/tags/link.js | 53 +++++++++++++++++------- source/css/_layout/tag-plugins/link.styl | 49 ++++++++++++++++++---- 2 files changed, 79 insertions(+), 23 deletions(-) diff --git a/scripts/tags/link.js b/scripts/tags/link.js index 9be68bd..87812a8 100644 --- a/scripts/tags/link.js +++ b/scripts/tags/link.js @@ -1,36 +1,59 @@ /** - * link.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/ + * link.js v1.1 | https://github.com/xaoxuu/hexo-theme-stellar/ * 格式与官方标签插件一致使用空格分隔,中括号内的是可选参数(中括号不需要写出来) * - * {% link url title [description] [img:src] %} + * {% link url title [description] [icon:src] %} */ 'use strict'; hexo.extend.tag.register('link', function(args) { - args = hexo.args.map(args, ['img'], ['url', 'title', 'description']); + args = hexo.args.map(args, ['icon'], ['url', 'title', 'description']); var el = ''; el += ''; - // right - el += '
'; - if (hexo.theme.config.plugins.lazyload && hexo.theme.config.plugins.lazyload.enable) { - el += '
'; - } else { - el += '
'; + function loadIcon() { + var el = ''; + if (hexo.theme.config.plugins.lazyload && hexo.theme.config.plugins.lazyload.enable) { + el += '
'; + } else { + el += '
'; + } + return el; + } + function loadTitle() { + return '' + args.title + ''; + } + function loadDesc() { + return '' + (args.description || args.url) + ''; } - el += '
'; + if (args.description) { + // top + el += '
'; + el += loadIcon(); + el += '' + args.url + ''; + el += '
'; + // bottom + el += '
'; + el += loadTitle() + loadDesc(); + el += '
'; + } else { + // left + el += '
'; + el += loadTitle() + loadDesc(); + el += '
'; + // right + el += '
'; + el += loadIcon(); + el += '
'; + } // end el += '
'; diff --git a/source/css/_layout/tag-plugins/link.styl b/source/css/_layout/tag-plugins/link.styl index 8946686..eb0d639 100644 --- a/source/css/_layout/tag-plugins/link.styl +++ b/source/css/_layout/tag-plugins/link.styl @@ -1,5 +1,5 @@ .md .tag-plugin.link - max-width: 360px + max-width: 400px margin: 1em auto display: flex justify-content: center @@ -24,26 +24,59 @@ box-shadow: $boxshadow-card-float transform: translateY(-1px) +.md .link-card.plain + flex-direction: row + +.md .link-card.rich + flex-direction: column + align-items: flex-start + width: 400px .md .link-card - div.left,div.right + > div pointer-events: none - div.right + >.top + display: flex + margin: .75rem 1rem .25rem + overflow: hidden + max-width: 'calc(100% - %s * 2)' % 1rem + align-items: center + .img + line-height: 0 + height: 16px + width: 20px + margin-right: 4px + background-repeat: no-repeat + background-size: contain + background-position: left center + .url + opacity: .75 + span + txt-ellipsis() + max-width: 100% + >.bottom + margin: 0 1rem .75rem 1rem + >.right width: 2.5rem height: 2.5rem - margin: 0.75rem + margin: .75rem overflow: hidden flex-shrink: 0 - div.left + >.left overflow: hidden - margin-left: 1rem + margin: .5rem 0 .5rem 1rem + .url + flex-shrink: 0 + txt-ellipsis() span margin: 0 display: block - txt-ellipsis() span.title font-weight: 500 color: var(--text-p1) + line-height: 1.2 + margin: 4px 0 span.url - flex-shrink: 0 color: var(--text-p3) + line-height: 1.4 + margin: 2px 0