From c09e66f325077be8ac31904d42df071a5dd8f10e Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Sun, 1 Dec 2019 13:33:04 +0800 Subject: [PATCH] New option `sidebar.padding` --- _config.yml | 2 ++ layout/_partials/head/head.swig | 3 +-- source/css/_common/outline/sidebar/sidebar.styl | 2 +- source/css/_variables/base.styl | 1 + source/js/schemes/pisces.js | 2 +- source/js/utils.js | 2 +- 6 files changed, 7 insertions(+), 5 deletions(-) diff --git a/_config.yml b/_config.yml index 1208cd4459..ec873047bc 100644 --- a/_config.yml +++ b/_config.yml @@ -157,6 +157,8 @@ sidebar: # - remove totally remove sidebar including sidebar toggle. display: post + # Sidebar padding in pixels. + padding: 18 # Sidebar offset from top menubar in pixels (only for Pisces | Gemini). offset: 12 # Enable sidebar on narrow view (only for Muse | Mist). diff --git a/layout/_partials/head/head.swig b/layout/_partials/head/head.swig index 001a145e72..e185db7311 100644 --- a/layout/_partials/head/head.swig +++ b/layout/_partials/head/head.swig @@ -84,7 +84,6 @@ }, localsearch: {{ theme.local_search | json }}, path: '{{ config.search.path }}', - motion: {{ theme.motion | json }}, - sidebarPadding: 40 + motion: {{ theme.motion | json }} }; diff --git a/source/css/_common/outline/sidebar/sidebar.styl b/source/css/_common/outline/sidebar/sidebar.styl index f786d3c77c..d6a71c38bd 100644 --- a/source/css/_common/outline/sidebar/sidebar.styl +++ b/source/css/_common/outline/sidebar/sidebar.styl @@ -25,7 +25,7 @@ .sidebar-inner { color: $grey-dark; - padding: 20px 10px; + padding: $sidebar-padding 10px; text-align: center; } diff --git a/source/css/_variables/base.styl b/source/css/_variables/base.styl index dfd8f3cc02..462fbaea5b 100644 --- a/source/css/_variables/base.styl +++ b/source/css/_variables/base.styl @@ -213,6 +213,7 @@ $posts-collapse-margin-mobile = 20px; // Variables for sidebar section elements. // -------------------------------------------------- +$sidebar-padding = hexo-config('sidebar.padding') is a 'unit' ? unit(hexo-config('sidebar.padding'), px) : 18px; $sidebar-offset = hexo-config('sidebar.offset') is a 'unit' ? unit(hexo-config('sidebar.offset'), px) : 12px; $sidebar-nav-color = $black-light; $sidebar-nav-hover-color = $whitesmoke; diff --git a/source/js/schemes/pisces.js b/source/js/schemes/pisces.js index c967309ac0..a6a79553cc 100644 --- a/source/js/schemes/pisces.js +++ b/source/js/schemes/pisces.js @@ -43,7 +43,7 @@ var Affix = { }, checkPosition: function() { if (window.getComputedStyle(this.element).display === 'none') return; - let height = this.element.offsetHeight - CONFIG.sidebarPadding; + let height = this.element.offsetHeight - CONFIG.sidebar.padding * 2; let offset = this.offset; let offsetTop = offset.top; let offsetBottom = offset.bottom; diff --git a/source/js/utils.js b/source/js/utils.js index 2a90f7906c..d2bff0ade2 100644 --- a/source/js/utils.js +++ b/source/js/utils.js @@ -342,7 +342,7 @@ NexT.utils = { var sidebarNavHeight = sidebarNav.style.display !== 'none' ? sidebarNav.offsetHeight : 0; var sidebarOffset = CONFIG.sidebar.offset || 12; var sidebarb2tHeight = CONFIG.back2top.enable && CONFIG.back2top.sidebar ? document.querySelector('.back-to-top').offsetHeight : 0; - var sidebarSchemePadding = CONFIG.sidebarPadding + sidebarNavHeight + sidebarb2tHeight; + var sidebarSchemePadding = CONFIG.sidebar.padding * 2 + sidebarNavHeight + sidebarb2tHeight; // Margin of sidebar b2t: 8px -10px -20px, brings a different of 12px. if (NexT.utils.isPisces() || NexT.utils.isGemini()) sidebarSchemePadding += (sidebarOffset * 2) - 12; // Initialize Sidebar & TOC Height.