Skip to content

Commit

Permalink
Merge branch 'master' into demo
Browse files Browse the repository at this point in the history
# Conflicts:
#	themes/fluid/scripts/tags/fold.js
#	themes/fluid/scripts/utils/crypto.js
  • Loading branch information
cellargalaxy committed Nov 19, 2023
2 parents 6e33044 + e025707 commit d10ec57
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 5 deletions.
2 changes: 1 addition & 1 deletion themes/fluid/layout/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ if (Array.isArray(page.banner_group) && page.banner_group.length) {
</a>
</h2>
<% 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) %>
<a class="index-excerpt <%= index_img ? '' : 'index-excerpt__noimg' %>" href="<%= post_url %>" target="<%- theme.index.post_url_target %>">
<div>
<%- strip_html(excerpt).substring(0, 200).trim().replace(/\n/g, ' ') %>
Expand Down
4 changes: 2 additions & 2 deletions themes/fluid/scripts/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 9 additions & 1 deletion themes/fluid/scripts/helpers/wordcount.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
20 changes: 20 additions & 0 deletions themes/fluid/scripts/tags/fold.js
Original file line number Diff line number Diff line change
@@ -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 `
<div class="fold">
<div class="fold-title fold-${classes.trim()} collapsed" data-toggle="collapse" href="#${id}" role="button" aria-expanded="false" aria-controls="${id}">
<div class="fold-arrow">▶</div>${text}
</div>
<div class='fold-content collapse' id="${id}">
${hexo.render.renderSync({ text: content, engine: 'markdown' }).split('\n').join('')}
</div>
</div>`;
}, {
ends: true
});
9 changes: 9 additions & 0 deletions themes/fluid/scripts/utils/crypto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

const crypto = require('crypto');

const md5 = (content) => {
return crypto.createHash('md5').update(content).digest('hex');
}

module.exports = md5;
4 changes: 4 additions & 0 deletions themes/fluid/source/css/_pages/_base/color-schema.styl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion themes/fluid/source/css/_pages/_index/index.styl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -73,3 +73,8 @@

.index-pin
font-size 1.25rem

.index-excerpt
height auto
max-height calc(1.4rem * 3)
margin 0.25rem 0
50 changes: 50 additions & 0 deletions themes/fluid/source/css/_pages/_post/post-tag.styl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 7 additions & 0 deletions themes/fluid/source/js/color-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -247,6 +248,7 @@
theme: giscusTheme,
}
};
giscus.style.cssText += 'color-scheme: normal;';
giscus.contentWindow.postMessage({ 'giscus': message }, 'https://giscus.app');
}
}
Expand Down Expand Up @@ -276,4 +278,9 @@
}
}
});

Fluid.utils.waitElementLoaded(iframeSelector, function() {
applyCustomColorSchemaSettings();
});

})(window, document);

0 comments on commit d10ec57

Please sign in to comment.