From 984aaa6c770cb84e3ee08bd753a1c73db3c26325 Mon Sep 17 00:00:00 2001 From: xaoxuu Date: Sat, 27 Feb 2021 21:50:18 +0800 Subject: [PATCH] copy tag --- scripts/tags/copy.js | 50 +++++++++++++++++++ source/css/_layout/base.styl | 5 +- .../css/_layout/partial/article_footer.styl | 4 -- source/css/_layout/partial/paginator.styl | 8 +-- source/css/_layout/tag-plugins/copy.styl | 30 +++++++++++ source/css/_plugins/common/input.styl | 5 ++ source/css/_plugins/common/toast.styl | 3 +- source/js/main.js | 4 +- 8 files changed, 95 insertions(+), 14 deletions(-) create mode 100644 scripts/tags/copy.js create mode 100644 source/css/_layout/tag-plugins/copy.styl create mode 100644 source/css/_plugins/common/input.styl diff --git a/scripts/tags/copy.js b/scripts/tags/copy.js new file mode 100644 index 0000000..f00d825 --- /dev/null +++ b/scripts/tags/copy.js @@ -0,0 +1,50 @@ +/** + * copy.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/ + * 格式与官方标签插件一致使用空格分隔,中括号内的是可选参数(中括号不需要写出来) + * + * {% copy xxx %} + * {% copy git xaoxuu/hexo-theme-stellar %} + * + */ + +'use strict'; + +const { ArgsMap } = require('./utils'); + +hexo.extend.tag.register('copy', function(args) { + args = ArgsMap(args, ['width'], ['text', 'more']); + var text; + if (args.text == 'git' && args.more && args.more.length > 0) { + text = args.more; + if (text.substr(0,1) == '/') { + text = text.substring(1); + } + text = 'https://github.com/' + text + '.git'; + } else if (args.text && args.text.length > 0) { + text = args.text; + if (args.more && args.more.length > 0) { + text += ' ' + args.more; + } + } + function generate_id(text) { + return 'copy-' + text.replace(/[^a-z|0-9|.:]/gi, '') + } + + var el = ''; + el += '
'; + + el += ''; + + el += '
'; + return el; +}); diff --git a/source/css/_layout/base.styl b/source/css/_layout/base.styl index cb0ca95..fed35d8 100644 --- a/source/css/_layout/base.styl +++ b/source/css/_layout/base.styl @@ -70,14 +70,11 @@ hr opacity: .1 button - padding: 1em border: none font-weight: 600 outline: none disable-select() - &:hover - color: $color-inner - background: $color-theme + cursor: pointer img max-width: 100% diff --git a/source/css/_layout/partial/article_footer.styl b/source/css/_layout/partial/article_footer.styl index b639420..4247879 100644 --- a/source/css/_layout/partial/article_footer.styl +++ b/source/css/_layout/partial/article_footer.styl @@ -14,10 +14,6 @@ margin: 0.75rem 0 padding: 0 width: 100% - font-family: $ff-code - font-size: $fs12 - font-weight: 600 - color: var(--text-p3) p font-size: $fs14 color: var(--text-p2) diff --git a/source/css/_layout/partial/paginator.styl b/source/css/_layout/partial/paginator.styl index fd03467..cb02aad 100644 --- a/source/css/_layout/partial/paginator.styl +++ b/source/css/_layout/partial/paginator.styl @@ -1,4 +1,5 @@ -.post-list .paginator-wrap +.paginator-wrap + margin: 1rem display: flex justify-content: space-between align-items: center @@ -25,11 +26,10 @@ pointer-events: none opacity: 0.25 &.prev - border-right: 1px solid transparent + border-right: 1px solid var(--block-border) &.next - border-left: 1px solid transparent + border-left: 1px solid var(--block-border) a.paginator:hover background: var(--card) - border-color: var(--block-border) img filter: grayscale(0%) diff --git a/source/css/_layout/tag-plugins/copy.styl b/source/css/_layout/tag-plugins/copy.styl new file mode 100644 index 0000000..ee82afd --- /dev/null +++ b/source/css/_layout/tag-plugins/copy.styl @@ -0,0 +1,30 @@ +.md .tag-plugin.copy + display: flex + .link-box + background: var(--block) + border-radius: $border-block + border: 1px solid var(--block-border) + overflow: hidden + max-width: 100% + display: flex + width: 360px + &[width='max'] + width: 100% + @media screen and (max-width: $device-mobile-l) + min-width: 100% + input.copy-area + display: inline-block + padding: 1em + width: 100% + color: var(--text-p2) + button.copy-btn + border-left: 1px solid var(--block-border) + display: inline-block + background: var(--hover-block) + line-height: 0 + height: 100% + font-size: 1rem + padding: 0.5rem 1rem + color: var(--text-p2) + &:hover + background: var(--card) diff --git a/source/css/_plugins/common/input.styl b/source/css/_plugins/common/input.styl new file mode 100644 index 0000000..2fcae6f --- /dev/null +++ b/source/css/_plugins/common/input.styl @@ -0,0 +1,5 @@ +input.copy-area + font-family: $ff-code + font-size: $fs12 + font-weight: 600 + color: var(--text-p3) diff --git a/source/css/_plugins/common/toast.styl b/source/css/_plugins/common/toast.styl index 30ee552..ea1a635 100644 --- a/source/css/_plugins/common/toast.styl +++ b/source/css/_plugins/common/toast.styl @@ -1,6 +1,6 @@ div.toast max-width: 60% - padding: 2rem 3rem + padding: 1rem 3rem line-height: 1.5 color: var(--text-p1) font-weight: 500 @@ -12,4 +12,5 @@ div.toast left: 50% transform: translate(-50%, -50%) z-index: 9 + disable-select() box-shadow: $boxshadow-float diff --git a/source/js/main.js b/source/js/main.js index eb89930..37db151 100644 --- a/source/js/main.js +++ b/source/js/main.js @@ -132,7 +132,9 @@ const util = { if (el) { el.select(); document.execCommand("Copy"); - hud.toast(msg); + if (msg && msg.length > 0) { + hud.toast(msg); + } } },