Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Putting blogroll and related-posts in separate sidebar-inner elements #593

Merged
merged 10 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ follow_me:
# Dependencies: https://github.com/sergeyzwezdin/hexo-related-posts
related_posts:
enable: false
display_in_home: false
icon: fa fa-signs-post

# Post edit
# Easily browse and edit blog source code online.
Expand Down
4 changes: 0 additions & 4 deletions layout/_macro/post.njk
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@
{### END POST BODY ###}
{#####################}

{%- if theme.related_posts.enable and (theme.related_posts.display_in_home or not is_index) %}
{{ partial('_partials/post/post-related.njk') }}
{%- endif %}

<footer class="post-footer">
{%- if is_index %}
<div class="post-eof"></div>
Expand Down
35 changes: 35 additions & 0 deletions layout/_macro/sidebar.njk
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,40 @@
</div>
{%- endif %}
</div>

{# Blogroll #}
{%- if theme.links %}
<div class="sidebar-inner sidebar-blogroll">
<div class="links-of-blogroll animated">
<div class="links-of-blogroll-title">
{%- if theme.links_settings.icon %}<i class="{{ theme.links_settings.icon }} fa-fw"></i>{% endif %}
{{ __('sidebar.links') }}
</div>
<ul class="links-of-blogroll-list">
{%- for blogrollText, blogrollURL in theme.links %}
<li class="links-of-blogroll-item">
{{ next_url(blogrollURL, blogrollText, {title: blogrollURL}) }}
</li>
{%- endfor %}
</ul>
</div>
</div>
{%- endif %}

{%- if theme.related_posts.enable %}
{%- if theme.pjax %}
<div class="pjax">
{%- endif %}
{%- if page.related_posts and page.related_posts.length > 0 %}
<div class="sidebar-inner sidebar-post-related">
<div class="animated">
{{ partial('_partials/post/post-related.njk') }}
</div>
</div>
{%- endif %}
{%- if theme.pjax %}
</div>
{%- endif %}
{%- endif %}
</aside>
{% endmacro %}
20 changes: 9 additions & 11 deletions layout/_partials/post/post-related.njk
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
{%- if page.related_posts and page.related_posts.length > 0 %}
<div class="popular-posts-header">{{ __('post.related_posts') }}</div>
<div class="links-of-blogroll-title">
{%- if theme.related_posts.icon %}<i class="{{ theme.related_posts.icon }} fa-fw"></i>{% endif %}
{{ __('post.related_posts') }}
</div>
<ul class="popular-posts">
{%- for path in page.related_posts %}
{%- set popular_post = site.posts.findOne({ path: path }) %}
<li class="popular-posts-item">
<a class="popular-posts-link" href="{{ url_for(popular_post.path) }}" rel="bookmark">
{%- if popular_post.date %}
<div class="popular-posts-date">{{ date(popular_post.date) }}</div>
{%- endif %}
{%- if popular_post.img %}
<div class="popular-posts-img"><img src="{{ popular_post.img }}" alt="{{ popular_post.title }}"></div>
{%- endif %}
<div class="popular-posts-title"><a href="{{ url_for(popular_post.path) }}" rel="bookmark">{{ popular_post.title }}</a></div>
{%- if popular_post.excerpt and popular_post.excerpt != '' %}
<div class="popular-posts-excerpt"><p>{{ popular_post.excerpt }}</p></div>
<time class="popular-posts-time">{{ date(popular_post.date) }}</time>
<br>
{%- endif %}
{{ popular_post.title }}
</a>
</li>
{%- endfor %}
</ul>
{%- endif %}
27 changes: 5 additions & 22 deletions layout/_partials/sidebar/site-overview.njk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
<div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
{%- if theme.avatar.url %}
<img class="site-author-image" itemprop="image" alt="{{ author }}"
src="{{ url_for(theme.avatar.url) }}">
Expand All @@ -8,7 +8,7 @@
</div>

{%- if theme.site_state %}
<div class="site-state-wrap site-overview-item animated">
<div class="site-state-wrap animated">
<nav class="site-state">
{%- if config.archive_dir != '/' and site.posts.length > 0 %}
<div class="site-state-item site-state-posts">
Expand Down Expand Up @@ -52,7 +52,7 @@
{%- endif %}

{%- if theme.chat.enable and (theme.chatra.enable or theme.tidio.enable or theme.gitter.enable) %}
<div class="sidebar-button site-overview-item animated">
<div class="sidebar-button animated">
<button{% if theme.gitter.enable %} class="js-gitter-toggle-chat-button"{% endif %}>
{%- if theme.chat.icon %}<i class="{{ theme.chat.icon }}"></i>{% endif %}
{{ __('widget.chat') }}
Expand All @@ -61,7 +61,7 @@
{%- endif %}

{%- if theme.social %}
<div class="links-of-author site-overview-item animated">
<div class="links-of-author animated">
{%- for name, link in theme.social %}
<span class="links-of-author-item">
{%- set sidebarURL = link.split('||')[0] | trim %}
Expand All @@ -74,25 +74,8 @@
{%- endif %}

{%- if theme.creative_commons.license and theme.creative_commons.sidebar %}
<div class="cc-license site-overview-item animated" itemprop="license">
<div class="cc-license animated" itemprop="license">
{%- set ccImage = '<img src="' + theme.vendors.creative_commons.url + '" alt="Creative Commons">' %}
{{ next_url(ccURL, ccImage, {class: 'cc-opacity'}) }}
</div>
{%- endif %}

{# Blogroll #}
{%- if theme.links %}
<div class="links-of-blogroll site-overview-item animated">
<div class="links-of-blogroll-title">
{%- if theme.links_settings.icon %}<i class="{{ theme.links_settings.icon }} fa-fw"></i>{% endif %}
{{ __('sidebar.links') }}
</div>
<ul class="links-of-blogroll-list">
{%- for blogrollText, blogrollURL in theme.links %}
<li class="links-of-blogroll-item">
{{ next_url(blogrollURL, blogrollText, {title: blogrollURL}) }}
</li>
{%- endfor %}
</ul>
</div>
{%- endif %}
1 change: 0 additions & 1 deletion source/css/_common/components/third-party/index.styl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
@import 'gitalk';
@import 'utterances';
@import 'search';
@import 'related-posts';
@import 'math';
@import 'gitter';

Expand Down
23 changes: 0 additions & 23 deletions source/css/_common/components/third-party/related-posts.styl

This file was deleted.

8 changes: 1 addition & 7 deletions source/css/_common/outline/sidebar/index.styl
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
.sidebar-inner {
color: $grey-dark;
// Init Sidebar & TOC inner dimensions on all pages and for all schemes.
$offset = (($scheme == 'Pisces') or ($scheme == 'Gemini')) ? $sidebar-offset : $sidebar-padding;
max-height: 'calc(100vh - %s)' % unit($offset * 2, 'px');
padding: $sidebar-padding 10px;
text-align: center;
flex-column();
}

.site-overview-item:not(:first-child) {
margin-top: 10px;
}

.cc-license {
.cc-opacity {
border-bottom: 0;
Expand All @@ -35,3 +28,4 @@
@import 'sidebar-toggle';
@import 'sidebar-toc';
@import 'site-state';
@import 'related-posts';
31 changes: 31 additions & 0 deletions source/css/_common/outline/sidebar/related-posts.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
if (hexo-config('related_posts.enable')) {
.sidebar-post-related {
font-size: $font-size-smaller;
padding: $sidebar-padding 0 0 0;
}

.popular-posts {
margin: 0;
padding: 1em 0;
text-align: left;

.popular-posts-item {
display: block;

.popular-posts-link {
border-bottom: 0;
display: block;
padding: 5px 20px;
transition: background .2s ease-in-out;

&:hover {
background: var(--menu-item-bg-color);
}
}

.popular-posts-time {
color: $site-state-item-name-color;
}
}
}
}
1 change: 0 additions & 1 deletion source/css/_common/outline/sidebar/sidebar-blogroll.styl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
.links-of-blogroll-title {
font-size: $font-size-small;
font-weight: 600;
margin-top: 0;
}

.links-of-blogroll-list {
Expand Down
3 changes: 2 additions & 1 deletion source/css/_common/outline/sidebar/sidebar-nav.styl
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@

.sidebar-overview-active .site-overview-wrap {
// Flexbox layout makes it possible to reorder the child
// elements of .site-overview-item through the `order` CSS property
// elements of .site-overview-wrap through the `order` CSS property
flex-column();
gap: 10px;
}

.sidebar-toc-active .post-toc-wrap {
Expand Down
6 changes: 6 additions & 0 deletions source/css/_schemes/Muse/_sidebar.styl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ if (hexo-config('sidebar.position') == 'right') {
if (not hexo-config('back2top.sidebar')) {
box-shadow: inset 0 2px 6px black;
}
max-height: 100vh;
overflow-y: auto;
position: fixed;
top: 0;
transition: all $transition-ease-out;
Expand Down Expand Up @@ -95,6 +97,10 @@ if (hexo-config('sidebar.position') == 'right') {
}
}

.popular-posts .popular-posts-item .popular-posts-link:hover {
background: none;
}

.sidebar-dimmer {
background: black;
height: 100%;
Expand Down
9 changes: 5 additions & 4 deletions source/css/_schemes/Pisces/_sidebar.styl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
+tablet-mobile() {
display: none;
}

if (hexo-config('motion.enable') and hexo-config('motion.transition.sidebar')) {
visibility: hidden;
}
}

.sidebar-inner {
Expand All @@ -20,6 +16,11 @@
box-sizing: border-box;
color: var(--text-color);
margin-top: $sidebar-offset;
max-height: 'calc(100vh - %s)' % unit($sidebar-offset * 2, 'px');

if (hexo-config('motion.enable') and hexo-config('motion.transition.sidebar')) {
visibility: hidden;
}
}

.site-state-item {
Expand Down
1 change: 1 addition & 0 deletions source/css/noscript.styl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ body { margin-top: 2rem; }

.use-motion .menu-item,
.use-motion .sidebar,
.use-motion .sidebar-inner,
.use-motion .post-block,
.use-motion .pagination,
.use-motion .comments,
Expand Down
16 changes: 10 additions & 6 deletions source/js/motion.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,20 @@ NexT.motion.middleWares = {
},

sidebar: function() {
const sidebar = document.querySelector('.sidebar');
const sequence = [];
const sidebar = document.querySelectorAll('.sidebar-inner');
const sidebarTransition = CONFIG.motion.transition.sidebar;
// Only for Pisces | Gemini.
if (sidebarTransition && (CONFIG.scheme === 'Pisces' || CONFIG.scheme === 'Gemini')) {
return [{
targets : sidebar,
complete: () => sidebar.classList.add('animated', sidebarTransition)
}];
sidebar.forEach(targets => {
sequence.push({
targets,
complete: () => targets.classList.add('animated', sidebarTransition),
deltaT : '-=100'
});
});
}
return [];
return sequence;
},

footer: function() {
Expand Down
2 changes: 2 additions & 0 deletions source/js/pjax.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ document.addEventListener('pjax:success', () => {
.init()
.add(NexT.motion.middleWares.subMenu)
.add(NexT.motion.middleWares.postList)
// Add sidebar-post-related transition.
.add(NexT.motion.middleWares.sidebar)
.bootstrap();
}
if (CONFIG.sidebar.display !== 'remove') {
Expand Down
4 changes: 2 additions & 2 deletions source/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ NexT.utils = {
parent = parent.parentNode;
}
// Scrolling to center active TOC element if TOC content is taller then viewport.
const tocElement = document.querySelector('.sidebar-panel-container');
if (!tocElement.parentNode.classList.contains('sidebar-toc-active')) return;
const tocElement = document.querySelector(CONFIG.scheme === 'Pisces' || CONFIG.scheme === 'Gemini' ? '.sidebar-panel-container' : '.sidebar');
if (!document.querySelector('.sidebar-toc-active')) return;
window.anime({
targets : tocElement,
duration : 200,
Expand Down