Skip to content

Commit

Permalink
Feature: Custom sidebar display behavior. hexojs#20, hexojs#74, hexoj…
Browse files Browse the repository at this point in the history
  • Loading branch information
iissnan committed May 12, 2015
1 parent 99d5fa5 commit e2cb7d8
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 7 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,13 @@ menu:
tags: /tags
#about: /about


# Favicon
# 从`Next 0.2`起,favicon将不再放置于主题之内。
# 请将你的favicon放置在`hexo-site/source/`目录下。
favicon: /favicon.ico


# 设置为`false`不显示`rss`链接
# 留空,并且通过`hexo-site-feed`插件配置使用默认的feed
# 设置成特定的`url`,适用于通过第三方服务定制feed的情况。
Expand All @@ -157,18 +159,30 @@ icon_font: default
# available: normal | night | night eighties | night blue | night bright
highlight_theme: normal


# MathJax support
# 开启数学公式渲染支持,默认关闭。设置为 `true` 开启。
mathjax:


# Mist
# 使用 Mist 主题
#scheme: Mist


# Sidebar 侧栏行为,可选值有
# - post 默认值,在文章页面自动展开侧栏
# - always 在所有页面自动展开侧栏
# - hide 在手动点击侧栏的开关按钮时展开
sidebar: post
#sidebar: always
#sidebar: hide


# `阅读全文` 按钮跳转之后是否自动滚动页面到设置 `<!-- more -->` 的地方。
scroll_to_more: true


# 是否为侧边栏文章的目录自动添加索引,默认开启。设置为 `false` 关闭。
toc_list_number: true
```
Expand Down
9 changes: 9 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ mathjax:
#scheme: Mist


# Sidebar, available value:
# - post expand on posts automatically. Default.
# - always expand for all pages automatically
# - hide expand only when click on the sidebar toggle icon.
sidebar: post
#sidebar: always
#sidebar: hide


# Automatically scroll page to section which is under <!-- more --> mark.
scroll_to_more: true

Expand Down
9 changes: 9 additions & 0 deletions layout/_layout.swig
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@

{% block script_extra %}{% endblock %}

<script type="text/javascript">
var HEXO_SIDEBAR_CONFIGURATION = '{{ theme.sidebar }}';
$(document).ready(function () {
if (HEXO_SIDEBAR_CONFIGURATION === 'always') {
displaySidebar();
}
});
</script>

{% include '_scripts/mathjax.swig' %}
{% block comment_system %}{% endblock %}

Expand Down
6 changes: 6 additions & 0 deletions layout/_scripts/helpers.swig
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@
function escapeSelector (selector) {
return selector.replace(/[!"$%&'()*+,.\/:;<=>?@[\\\]^`{|}~]/g, "\\$&")
}

function displaySidebar () {
setTimeout(function () {
$('.sidebar-toggle').trigger('click');
}, 800);
}
</script>
4 changes: 2 additions & 2 deletions layout/_scripts/motion/global.swig
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
var sidebarToogleLine3rdStatusClose = {width: '100%', rotateZ: '45deg', top: '-5px'};

LogoAndMenuMotion();
sidebatToggleMotion();
sidebarToggleMotion();
postsListMotion();
backToTopMotion();

Expand Down Expand Up @@ -103,7 +103,7 @@
$('.post').velocity('transition.slideDownIn', postMotionOptions);
}

function sidebatToggleMotion () {
function sidebarToggleMotion () {
sidebarToggle.on('click', function () {
isSidebarVisible ? sidebarHideMotion() : sidebarShowMotion();
isSidebarVisible = !isSidebarVisible;
Expand Down
7 changes: 2 additions & 5 deletions layout/_scripts/pages/post-details.swig
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,8 @@
});

// Expand sidebar on post detail page by default, when post has a toc.
var $tocContent = $('.post-toc-content');
if ($tocContent.length > 0 && $tocContent.html().trim().length > 0 && isDesktop()) {
setTimeout(function () {
$('.sidebar-toggle').trigger('click');
}, 800);
if (isDesktop() && HEXO_SIDEBAR_CONFIGURATION === 'post') {
displaySidebar();
}
});
</script>
Expand Down

0 comments on commit e2cb7d8

Please sign in to comment.