Skip to content

Commit

Permalink
fix: Solved that friends plugin not show normally when lazyload enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyib committed Jan 15, 2020
1 parent ac44aee commit 63f19fe
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
37 changes: 21 additions & 16 deletions scripts/tags/friends.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,33 @@ function friends(args) {
}
});

return fs.readFile(path).then(function(datas) {
if (!datas) {
return fs.readFile(path).then(function(data) {
if (!data) {
hexo.log.warn('Include file empty.');
return;
}

var datas = JSON.parse(datas);
var result = '<div class="friends-plugin">';

datas.forEach(data => {
result += `<a class="friends-plugin__item" href="${data.url}">`;
result += `<img class="friends-plugin__item-avatar" src="${data.avatar}" data-zoom="none">`;
result += '<div class="friends-plugin__item-info">';
result += `<p class="friends-plugin__item-info__name">${data.name}</p>`;
result += `<p class="friends-plugin__item-info__intro">${data.introduction}</p>`;
result += '</div>';
result += '</a>';
});
var imgClassName = 'friends-plugin__item-avatar ';
var theme = hexo.theme.config;
if (theme.lazyload && theme.lazyload.enable) {
imgClassName += `lazyload lazyload-${theme.lazyload.placeholder}`;
}

result += '</div>';
var friends = JSON.parse(data);
var renderHtml = '<div class="friends-plugin">';
friends.forEach(f => {
renderHtml +=
`<a class="friends-plugin__item" href="${f.url}">` +
`<img class="${imgClassName}" src="${f.avatar}" data-zoom="none">` +
'<div class="friends-plugin__item-info">' +
`<p class="friends-plugin__item-info__name">${f.name}</p>` +
`<p class="friends-plugin__item-info__intro">${f.introduction}</p>` +
'</div>' +
'</a>';
});
renderHtml += '</div>';

return result;
return renderHtml;
});
}

Expand Down
20 changes: 9 additions & 11 deletions source/css/_common/components/plugins/friends.styl
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
max-width: 100%;

&__item {
display: block;
display: flex;
float: left;
padding: .5rem 1rem;
width: 50%;
height: 100px;
transition: background-color .3s;
align-items: center;

&:hover {
background-color: alpha($blue-light, .1);
Expand All @@ -21,22 +22,15 @@
avatar-width = 60px;

&-avatar {
display: inline-block;
margin: 0 1rem 0 0;
border-radius: 50% !important;
width: avatar-width;
height: avatar-width;
vertical-align: middle;
}

info-margin = 20px;

&-info {
display: inline-block;
margin-left: info-margin;
padding-top: .6rem;
width: 'calc(100% - %s)' % (avatar-width + info-margin);
height: 100%;
vertical-align: middle;
overflow: hidden;
width: 100%;
color: var(--color-gray-800);

&__name,
Expand All @@ -46,6 +40,10 @@
text-overflow: ellipsis;
}

&__name {
font-weight: $font-weight-bolder;
}

&__intro {
font-size: .9em;
color: #999;
Expand Down

0 comments on commit 63f19fe

Please sign in to comment.