diff --git a/themes/fluid/layout/index.ejs b/themes/fluid/layout/index.ejs index f47e2df6..7521de1f 100644 --- a/themes/fluid/layout/index.ejs +++ b/themes/fluid/layout/index.ejs @@ -46,7 +46,7 @@ if (Array.isArray(page.banner_group) && page.banner_group.length) { - <% var excerpt = post.description || post.excerpt || (theme.index.auto_excerpt.enable && post.content) %> + <% var excerpt = post.description || post.excerpt || (theme.index.auto_excerpt.enable && !post.encrypt && post.content) %>
<%- strip_html(excerpt).substring(0, 200).trim().replace(/\n/g, ' ') %> diff --git a/themes/fluid/scripts/helpers/utils.js b/themes/fluid/scripts/helpers/utils.js index aed604c1..7581d62e 100644 --- a/themes/fluid/scripts/helpers/utils.js +++ b/themes/fluid/scripts/helpers/utils.js @@ -2,12 +2,12 @@ 'use strict'; -const crypto = require('crypto'); +const md5 = require('../utils/crypto'); const { decodeURL } = require('hexo-util'); const compareVersions = require('../../scripts/utils/compare-versions'); hexo.extend.helper.register('md5', function(string) { - return crypto.createHash('md5').update(string).digest('hex'); + return md5(string); }); hexo.extend.helper.register('require_version', function(current, require) { diff --git a/themes/fluid/scripts/helpers/wordcount.js b/themes/fluid/scripts/helpers/wordcount.js index 1d8acea6..b4230947 100644 --- a/themes/fluid/scripts/helpers/wordcount.js +++ b/themes/fluid/scripts/helpers/wordcount.js @@ -5,8 +5,16 @@ const { stripHTML } = require('hexo-util'); const getWordCount = (post) => { + const lang = post.lang.toLowerCase(); + // post.origin is the original post content of hexo-blog-encrypt + const content = stripHTML(post.origin || post.content).replace(/\r?\n|\r/g, '').replace(/\s+/g, ''); + if (!post.wordcount) { - post.wordcount = stripHTML(post.content).replace(/\r?\n|\r/g, '').replace(/\s+/g, '').length; + if (['zh-cn', 'zh-hk', 'zh-tw'].includes(lang)) { + post.wordcount = (content.match(/[\u4E00-\u9FA5]/g) || []).length; + } else { + post.wordcount = (content.replace(/[\u4E00-\u9FA5]/g, '').match(/[a-zA-Z0-9_\u0392-\u03c9\u0400-\u04FF]+|[\u4E00-\u9FFF\u3400-\u4dbf\uf900-\ufaff\u3040-\u309f\uac00-\ud7af\u0400-\u04FF]+|[\u00E4\u00C4\u00E5\u00C5\u00F6\u00D6]+|\w+/g) || []).length; + } } return post.wordcount; }; diff --git a/themes/fluid/scripts/tags/fold.js b/themes/fluid/scripts/tags/fold.js new file mode 100644 index 00000000..bbddbf8f --- /dev/null +++ b/themes/fluid/scripts/tags/fold.js @@ -0,0 +1,20 @@ +const md5 = require('../utils/crypto'); + +hexo.extend.tag.register('fold', (args, content) => { + args = args.join(' ').split('@'); + const classes = args[0] || 'default'; + const text = args[1] || ''; + const id = 'collapse-' + md5(content).slice(0, 8); + + return ` +
+ +
+ ${hexo.render.renderSync({ text: content, engine: 'markdown' }).split('\n').join('')} +
+
`; +}, { + ends: true +}); diff --git a/themes/fluid/scripts/utils/crypto.js b/themes/fluid/scripts/utils/crypto.js new file mode 100644 index 00000000..9f1007a0 --- /dev/null +++ b/themes/fluid/scripts/utils/crypto.js @@ -0,0 +1,9 @@ +'use strict'; + +const crypto = require('crypto'); + +const md5 = (content) => { + return crypto.createHash('md5').update(content).digest('hex'); +} + +module.exports = md5; diff --git a/themes/fluid/source/css/_pages/_base/color-schema.styl b/themes/fluid/source/css/_pages/_base/color-schema.styl index 11406011..661e37bf 100644 --- a/themes/fluid/source/css/_pages/_base/color-schema.styl +++ b/themes/fluid/source/css/_pages/_base/color-schema.styl @@ -20,6 +20,8 @@ --button-hover-bg-color $button-hover-bg-color --highlight-bg-color $highlight-bg-color --inlinecode-bg-color $inlinecode-bg-color + --fold-title-color $text-color + --fold-border-color $line-color dark-colors() --body-bg-color $body-bg-color-dark @@ -42,6 +44,8 @@ dark-colors() --button-hover-bg-color $button-hover-bg-color-dark --highlight-bg-color $highlight-bg-color-dark --inlinecode-bg-color $inlinecode-bg-color-dark + --fold-title-color $text-color + --fold-border-color $line-color img -webkit-filter brightness(.9) diff --git a/themes/fluid/source/css/_pages/_index/index.styl b/themes/fluid/source/css/_pages/_index/index.styl index 174791bc..c3d17cc1 100644 --- a/themes/fluid/source/css/_pages/_index/index.styl +++ b/themes/fluid/source/css/_pages/_index/index.styl @@ -41,7 +41,7 @@ .index-excerpt color var(--sec-text-color) - margin 0.5rem 0 0.5rem 0 + margin 0.5rem 0 height calc(1.4rem * 3) overflow hidden display flex @@ -73,3 +73,8 @@ .index-pin font-size 1.25rem + + .index-excerpt + height auto + max-height calc(1.4rem * 3) + margin 0.25rem 0 diff --git a/themes/fluid/source/css/_pages/_post/post-tag.styl b/themes/fluid/source/css/_pages/_post/post-tag.styl index e06819d9..5be46992 100644 --- a/themes/fluid/source/css/_pages/_post/post-tag.styl +++ b/themes/fluid/source/css/_pages/_post/post-tag.styl @@ -1,3 +1,53 @@ +// fold +.fold + margin 1rem 0 + border 0.5px solid var(--fold-border-color) + position relative + clear both + border-radius 0.125rem + + .fold-title + color var(--fold-title-color) + padding 0.5rem 0.75rem + font-size 0.9rem + font-weight bold + border-radius 0.125rem + + &:not(.collapsed) > .fold-arrow + transform rotate(90deg) + transform-origin center center + + .fold-arrow + display inline-block + margin-right 0.35rem + transition transform .3s ease-out + + .fold-content + & > * + margin 0 + + & > p + padding 1rem 1rem + +.fold-default + background rgba(#bbbbbb, 0.25) + +.fold-primary + background rgba(#b7a0e0, 0.25) + +.fold-info + background rgba(#a0c5e4, 0.25) + +.fold-success + background rgba(#aedcae, 0.25) + +.fold-warning + background rgba(#f8d6a6, 0.25) + +.fold-danger + background rgba(#eca9a7, 0.25) + + // note .note padding 0.75rem diff --git a/themes/fluid/source/js/color-schema.js b/themes/fluid/source/js/color-schema.js index 93924ca8..5b1b75c2 100644 --- a/themes/fluid/source/js/color-schema.js +++ b/themes/fluid/source/js/color-schema.js @@ -11,6 +11,7 @@ var defaultColorSchemaAttributeName = 'data-default-color-scheme'; var colorToggleButtonSelector = '#color-toggle-btn'; var colorToggleIconSelector = '#color-toggle-icon'; + var iframeSelector = 'iframe'; function setLS(k, v) { try { @@ -247,6 +248,7 @@ theme: giscusTheme, } }; + giscus.style.cssText += 'color-scheme: normal;'; giscus.contentWindow.postMessage({ 'giscus': message }, 'https://giscus.app'); } } @@ -276,4 +278,9 @@ } } }); + + Fluid.utils.waitElementLoaded(iframeSelector, function() { + applyCustomColorSchemaSettings(); + }); + })(window, document);