Skip to content

Commit

Permalink
Merge pull request #48 from DuoSco/dev
Browse files Browse the repository at this point in the history
Bug Repair
  • Loading branch information
王卓Sco authored Dec 1, 2023
2 parents 5856dd8 + 876c96d commit 7d255be
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 63 deletions.
2 changes: 1 addition & 1 deletion layout/archive.pug
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extends includes/layout.pug
block content
main.layout#content-inner
div#archive
div.article-sort-title #{__('page.archives')}<sup>#{page.posts.length}</sup>
div.article-sort-title #{__('page.archives')}<sup>#{page.posts.find({ parent: { $exists: false } }).length}</sup>
div.article-sort
include includes/mixins/articleSort
include includes/mixins/pagination
Expand Down
2 changes: 1 addition & 1 deletion layout/category.pug
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ block content
div.category-bar-items#category-bar-items
include includes/widgets/home/categoryBar
div.recent-posts#recent-posts
each post in site.posts.find({ parent: { $exists: false } }).data
each post in page.posts.find({ parent: { $exists: false } }).data
include includes/widgets/home/postList
include includes/mixins/pagination
include includes/widgets/aside/aside
2 changes: 1 addition & 1 deletion layout/includes/console.pug
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ div#console(style="zoom: 1")
div.author-content-item-tips= "标签"
div.author-content-item-title= "寻找感兴趣的领域"
div.card-tag-cloud
each tag in site.tags.data
each tag in site.tags.find({ parent: { $exists: false } }).data
a(href=url_for(tag.path), style="font-size: 0.8rem; color: #d3d3d3")= tag.name
sup= tag.length

Expand Down
3 changes: 3 additions & 0 deletions layout/includes/head/config.pug
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ script.
url: '!{theme.comment.twikoo.envId}',
accessToken: '!{theme.comment.twikoo.accessToken}'
},
waline: {
url: '!{theme.comment.waline.envId}',
}
},
rightside: {
enable: !{theme.rightside.enable}
Expand Down
12 changes: 8 additions & 4 deletions layout/includes/inject/body.pug
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,18 @@ if theme.aside.welcome.enable
script(src='/js/txmap.js')

if theme.comment.enable
if theme.comment.type === 'twikoo'
script(src='/js/extend/comment/twikoo.js')
script(src='/js/commentBarrage.js')
case theme.comment.type
when 'twikoo'
script(src='/js/extend/comment/twikoo.js')
script(src='/js/commentBarrage.js')
when 'waline'
script(src='/js/extend/comment/waline.js')


// pjax
include ../widgets/third-party/pjax.pug

// inject custom body
if theme.extends.body
each item in theme.extends.body
!= item
!= item
8 changes: 4 additions & 4 deletions layout/includes/mixins/articleSort.pug
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
- let year
each post in page.posts.data
- if(year !== moment(post.date).year())
- year = moment(post.date).year()
div.article-sort-item.year #{year}
each post in page.posts.find({ parent: { $exists: false } }).data
if(year !== post.date.year())
- year = post.date.year()
div.article-sort-item.year #{year}
div.article-sort-item
a.article-sort-item-img(href=url_for(post.path) title=post.title)
img(src=post.cover alt=post.title)
Expand Down
2 changes: 1 addition & 1 deletion layout/tag.pug
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ block content
main.layout#content-inner
div#tag
div#tag-page-tags
each tag in site.tags.find({ parent: { $exists: false } }).data
each tag in page.tags.find({ parent: { $exists: false } }).data
a(id=tag.name class=(tag.name === page.tag ? 'select' : '') href=url_for(tag.path))
span.tags-punctuation
| #{tag.name}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hexo-theme-solitude",
"version": "1.2.4",
"version": "1.2.5",
"description": "A beautiful, powerful, and efficient Hexo theme developed by the DuoSco team",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down
61 changes: 61 additions & 0 deletions source/js/extend/comment/waline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const changeContent = (content) => {
if (content === '') return content

content = content.replace(/<img.*?src="(.*?)"?[^\>]+>|<a[^>]+?href=["']?([^"']+)["']?[^>]*>([^<]+)<\/a>|<pre><code>.*?<\/pre>|<[^>]+>/g, (match, img, link, code) => {
if (img) return '[图片]';
if (link) return '[链接]';
if (code) return '[代码]';
return '';
})

if (content.length > 150) {
content = content.substring(0, 150) + '...'
}
return content
}

const $asideList = document.querySelector('#card-newest-comments .aside-list')
const newestCommentInit = () => {
if ($asideList) {
getComment()
}
}

const getComment = () => {
Waline.RecentComments(
options = {
serverURL: GLOBAL_CONFIG.comment.waline.url,
count: 6,
}
).then(function (res) {
const walineArray = res.comments.map(item => ({
'content': changeContent(item.comment),
'avatar': item.avatar,
'nick': item.nick,
'url': `${item.url}#${item.objectId}`,
'date': new Date(item.insertedAt).toISOString()
}))
generateHtml(walineArray)
}).catch(
$asideList.innerHTML = "无法获取评论,请确认相关配置是否正确"
)
}

const generateHtml = array => {
const $dom = document.querySelector('#card-newest-comments .aside-list')
$dom.innerHTML = array.length ? array.map(item => `
<div class='aside-list-item'>
<a href='${item.url}' class='thumbnail'>
<img src='${item.avatar}' alt='${item.nick}'>
<div class='name'><span>${item.nick}</span></div>
</a>
<div class='content'>
<a class='comment' href='${item.url}'>${item.content}</a>
<time class="datetime" datetime="${item.date}"></time>
</div>
</div>
`).join('') : '没有评论'
window.lazyLoadInstance && window.lazyLoadInstance.update()
window.pjax && window.pjax.refresh($dom)
changeTimeFormat()
}
101 changes: 51 additions & 50 deletions source/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -911,63 +911,64 @@ let sco = {
*/
class hightlight {
static createEle(langEl, item) {
const fragment = document.createDocumentFragment();
const highlightCopyEle = '<i class="scoicon sco-copy-fill"></i>';
const highlightExpandEle = '<i class="scoicon sco-arrow-down expand" style="font-size: 16px"></i>';

const hlTools = document.createElement('div');
hlTools.className = 'highlight-tools';
hlTools.innerHTML = `${highlightExpandEle}${langEl}${highlightCopyEle}`;

const itemHeight = item.clientHeight;
const $table = item.querySelector('table');
const $expand = item.getElementsByClassName('code-expand-btn');

let expand = true;
hlTools.children[0].addEventListener('click', () => {
expand = !expand;
hlTools.children[0].classList.toggle('closed');
$table.style.display = expand ? 'none' : 'block';
if ($expand.length !== 0) {
$expand[0].style.display = expand ? 'none' : 'block';
}
if (!expand) {
$table.style.height = itemHeight < 200 ? 'auto' : '200px';
if (itemHeight >= 200) {
item.classList.remove("expand-done");
const fragment = document.createDocumentFragment()
const highlightCopyEle = '<i class="scoicon sco-copy-fill"></i>'
const highlightExpandEle = '<i class="scoicon sco-arrow-down expand" style="font-size: 16px"></i>'

const hlTools = document.createElement('div')
hlTools.className = `highlight-tools`
hlTools.innerHTML = highlightExpandEle + langEl + highlightCopyEle
let expand = true
hlTools.children[0].addEventListener('click', (e) => {
if (expand) {
hlTools.children[0].classList.add('closed')
$table.setAttribute('style', 'display:none')
if ($expand.length !== 0) {
$expand[0].setAttribute('style', 'display:none')
}
} else {
hlTools.children[0].classList.remove('closed')
$table.setAttribute('style', 'display:block')
if ($expand.length !== 0) {
$expand[0].setAttribute('style', 'display:block')
}
if (itemHeight < 200) {
$table.setAttribute('style', 'height: auto')
} else {
$table.setAttribute('style', 'height:200px')
ele.classList.remove("expand-done")
}
}
});

hlTools.children[2].addEventListener('click', () => {
utils.copy($table.querySelector('.code').innerText);
});

fragment.appendChild(hlTools);

expand = !expand
})
hlTools.children[2].addEventListener('click', (e) => {
utils.copy($table.querySelector('.code').innerText)
})
const ele = document.createElement('div')
fragment.appendChild(hlTools)
const itemHeight = item.clientHeight, $table = item.querySelector('table'),
$expand = item.getElementsByClassName('code-expand-btn')
if (GLOBAL_CONFIG.hightlight.limit && itemHeight > GLOBAL_CONFIG.hightlight.limit + 30) {
$table.style.height = `${GLOBAL_CONFIG.hightlight.limit}px`;
const ele = document.createElement('div');
ele.className = 'code-expand-btn';
ele.innerHTML = '<i class="scoicon sco-show-line" style="font-size: 1.2rem"></i>';
$table.setAttribute('style', `height: ${GLOBAL_CONFIG.hightlight.limit}px`)
ele.className = 'code-expand-btn'
ele.innerHTML = '<i class="scoicon sco-show-line" style="font-size: 1.2rem"></i>'
ele.addEventListener('click', (e) => {
$table.style.height = `${itemHeight}px`;
const target = e.target.className !== 'code-expand-btn' ? e.target.parentNode : e.target;
target.classList.add('expand-done');
});
fragment.appendChild(ele);
$table.setAttribute('style', `height: ${itemHeight}px`)
e.target.className !== 'code-expand-btn' ? e.target.parentNode.classList.add('expand-done') : e.target.classList.add('expand-done')
})
fragment.appendChild(ele)
}
item.insertBefore(fragment, item.firstChild);
item.insertBefore(fragment, item.firstChild)
}

static init() {
const $figureHighlight = document.querySelectorAll('figure.highlight');
$figureHighlight.forEach(item => {
let langName = item.classList[1] || 'Code';
if (langName === 'plaintext') langName = 'Code';
const highlightLangEle = `<div class="code-lang">${langName.toUpperCase()}</div>`;
this.createEle(highlightLangEle, item);
});
const $figureHighlight = document.querySelectorAll('figure.highlight'), that = this
$figureHighlight.forEach(function (item) {
let langName = item.getAttribute('class').split(' ')[1]
if (langName === 'plaintext' || langName === undefined) langName = 'Code'
const highlightLangEle = `<div class="code-lang">${langName.toUpperCase()}</div>`
that.createEle(highlightLangEle, item)
})
}
}

Expand Down Expand Up @@ -1043,9 +1044,9 @@ window.refreshFn = () => {
sco.initConsoleState()
if (document.getElementById('history-baidu')) sco.card_history() // 那年今日
if (document.getElementById('welcome-info')) sco.card_welcome() // 个性定位
GLOBAL_CONFIG.comment.enable && newestCommentInit() // 最新评论
if (GLOBAL_CONFIG.comment.type === "twikoo" && PAGE_CONFIG.comment) {
initializeCommentBarrage() // 热评
GLOBAL_CONFIG.comment.enable && newestCommentInit()
}
}

Expand Down

0 comments on commit 7d255be

Please sign in to comment.