ppoffice / hexo-theme-icarus

A simple, delicate, and modern theme for the static site generator Hexo.
https://ppoffice.github.io/hexo-theme-icarus/
MIT License
6.39k stars 1.55k forks source link

请问支不支持这样一种操作:一般情况下三栏模式,阅读文章时是双栏模式? #379

Closed PhoenixGS closed 5 years ago

PhoenixGS commented 5 years ago
PhoenixGS commented 5 years ago

就是说一般模式和读文章时的widgets能不能分开来设置?

PhoenixGS commented 5 years ago

@ppoffice

nameussi commented 5 years ago

@ppoffice 同想问这问题,除了在md文件中覆盖widgets实现双栏,有没有什么办法在主题层面实现主页三栏post页双栏效果?如果不复杂的话麻烦指点一下,谢谢

Angericky commented 5 years ago

同问,希望阅读文章详细内容的时候是两栏,求指点

ppoffice commented 5 years ago

@PhoenixGS @nameussi @Angericky

diff --git a/includes/helpers/layout.js b/includes/helpers/layout.js
index 7fd6c07..6bfd0b3 100644
--- a/includes/helpers/layout.js
+++ b/includes/helpers/layout.js
@@ -32,6 +32,9 @@ module.exports = function (hexo) {

     hexo.extend.helper.register('column_count', function () {
         let columns = 1;
+        if (this.page.__post === true || this.page.__page === true) {
+            return 2;
+        }
         const hasColumn = hexo.extend.helper.get('has_column').bind(this);
         columns += hasColumn('left') ? 1 : 0;
         columns += hasColumn('right') ? 1 : 0;
diff --git a/layout/common/widget.ejs b/layout/common/widget.ejs
index 9f58bd5..c6b267c 100644
--- a/layout/common/widget.ejs
+++ b/layout/common/widget.ejs
@@ -25,7 +25,7 @@
         <%- partial('widget/' + widget.type, { widget, post: page }) %>
     <% }) %>
     <% if (position === 'left') { %>
-        <div class="column-right-shadow is-hidden-widescreen <%= sticky_class('right') %>">
+        <div class="column-right-shadow <%= (page.__page !== true && page.__post !== true) ? 'is-hidden-widescreen' : '' %> <%= sticky_class('right') %>">
         <% get_widgets('right').forEach(widget => {%>
             <%- partial('widget/' + widget.type, { widget, post: page }) %>
         <% }) %>
diff --git a/layout/layout.ejs b/layout/layout.ejs
index cf7be87..b76c9e6 100644
--- a/layout/layout.ejs
+++ b/layout/layout.ejs
@@ -21,7 +21,9 @@
             <div class="columns">
                 <div class="column <%= main_column_class() %> has-order-2 column-main"><%- body %></div>
                 <%- partial('common/widget', { position: 'left' }) %>
+                <% if (page.__page !== true && page.__post !== true) { %>
                 <%- partial('common/widget', { position: 'right' }) %>
+                <% } %>
             </div>
         </div>
     </section>
PhoenixGS commented 5 years ago

@ppoffice 太感谢了

PhoenixGS commented 5 years ago

@ppoffice 还想请教一下,目录能不能有一个滚动条,否则目录太长了就看不到下面的目录了

nameussi commented 5 years ago

@ppoffice 好吧有些复杂,虽然没看懂但是还是感谢耐心解答

ppoffice commented 5 years ago

@nameussi 直接把上面红色文件名的红色行替换成绿色行就行了

ppoffice commented 5 years ago

@PhoenixGS https://github.com/ppoffice/hexo-theme-icarus/blob/master/layout/widget/toc.ejs#L29 这一行改为:

<div class="card widget" id="toc" style="max-height: 400px;overflow: auto;">

高度的400px改为你想要的值。

nameussi commented 5 years ago

@ppoffice 原来是这样,明白了,非常感谢!另外,在post页分成两栏的同时只显示部分widgets能实现吗?其实我想实现的是在post页去掉部分widgets。

ppoffice commented 5 years ago

@nameussi 例如你想去掉tagcloud widget,那么在tagcloud.ejs中修改:

+ <% if (page.__page !== true && page.__post !== true) { %>
<% if (site.tags.length) { %>
<div class="card widget">
    <div class="card-content">
        <h3 class="menu-label">
            <%= __('widget.tag_cloud') %>
        </h3>
        <%- tagcloud() %>
    </div>
</div>
<% } %>
+ <% } %>
nameussi commented 5 years ago

@ppoffice 完美解决,再次感谢

xiaohanhan1019 commented 5 years ago

@ppoffice 想请教一下,变为两栏(左,中)以后,我想保持三栏的布局,就是左边栏的大小和位置和三栏时候一摸一样,然后把右栏多出来的位置给中间栏,该怎么操作,非常感谢!

ppoffice commented 5 years ago

@xiaohanhan1019 改下下面两行的数字 https://github.com/ppoffice/hexo-theme-icarus/blob/master/layout/layout.ejs#L13 https://github.com/ppoffice/hexo-theme-icarus/blob/master/layout/common/widget.ejs#L5

xiaohanhan1019 commented 5 years ago

@ppoffice 我试过这个方法,但整体页面的大小还是按照两栏的大小,左右的空白边距明显比三栏大了很多。

ppoffice commented 5 years ago

@xiaohanhan1019 https://github.com/ppoffice/hexo-theme-icarus/blob/master/source/css/style.styl#L4-L7

xiaohanhan1019 commented 5 years ago

@ppoffice 解决了,感谢!

ileadall42 commented 5 years ago

Nice!

Zohar727 commented 5 years ago

@PhoenixGS @nameussi @Angericky

diff --git a/includes/helpers/layout.js b/includes/helpers/layout.js
index 7fd6c07..6bfd0b3 100644
--- a/includes/helpers/layout.js
+++ b/includes/helpers/layout.js
@@ -32,6 +32,9 @@ module.exports = function (hexo) {

     hexo.extend.helper.register('column_count', function () {
         let columns = 1;
+        if (this.page.__post === true || this.page.__page === true) {
+            return 2;
+        }
         const hasColumn = hexo.extend.helper.get('has_column').bind(this);
         columns += hasColumn('left') ? 1 : 0;
         columns += hasColumn('right') ? 1 : 0;
diff --git a/layout/common/widget.ejs b/layout/common/widget.ejs
index 9f58bd5..c6b267c 100644
--- a/layout/common/widget.ejs
+++ b/layout/common/widget.ejs
@@ -25,7 +25,7 @@
         <%- partial('widget/' + widget.type, { widget, post: page }) %>
     <% }) %>
     <% if (position === 'left') { %>
-        <div class="column-right-shadow is-hidden-widescreen <%= sticky_class('right') %>">
+        <div class="column-right-shadow <%= (page.__page !== true && page.__post !== true) ? 'is-hidden-widescreen' : '' %> <%= sticky_class('right') %>">
         <% get_widgets('right').forEach(widget => {%>
             <%- partial('widget/' + widget.type, { widget, post: page }) %>
         <% }) %>
diff --git a/layout/layout.ejs b/layout/layout.ejs
index cf7be87..b76c9e6 100644
--- a/layout/layout.ejs
+++ b/layout/layout.ejs
@@ -21,7 +21,9 @@
             <div class="columns">
                 <div class="column <%= main_column_class() %> has-order-2 column-main"><%- body %></div>
                 <%- partial('common/widget', { position: 'left' }) %>
+                <% if (page.__page !== true && page.__post !== true) { %>
                 <%- partial('common/widget', { position: 'right' }) %>
+                <% } %>
             </div>
         </div>
     </section>

按照您提供的修改内容修改代码后,文章页的profile组件的布局错乱了,width被撑到了整个屏幕宽度

ppoffice commented 5 years ago

434

AlphaLxy commented 5 years ago

@nameussi @xiaohanhan1019

也可以通过修改 get_widgets 实现在特定页面返回两栏布局,然后修改两栏的宽度即可,https://github.com/AlphaLxy/hexo-theme-icarus/commit/7f86d9e0b9f60fba7f11eea305f36a0665140460

效果可以参考 https://www.alphalxy.com/,这样也可以实现不同的页面显示不同的 widget,根据 widget.type 过滤即可,例如:

if (position === 'left') {
    return widgets.filter(widget => widget.hasOwnProperty('position') 
           && (widget.type === 'toc' || widget.type === 'profile'));
} else {
    return []
}
nameussi commented 5 years ago

@AlphaLxy 点进去看了你的好多修改都挺不错的,所以想请教一下怎么修改文章头图的高度问题 #460

AlphaLxy commented 5 years ago

@AlphaLxy 点进去看了你的好多修改都挺不错的,所以想请教一下怎么修改文章头图的高度问题 #460

修改都记录在这里了 https://www.alphalxy.com/2019/03/customize-icarus/,也可以通过配置关闭文章开头的图片

molu-ggg commented 5 years ago

--- a/layout/layout.ejs +++ b/layout/layout.ejs 我没找到这个代码额

V2beach commented 4 years ago

学习一个

yinongqiu commented 4 years ago

--- a/layout/layout.ejs +++ b/layout/layout.ejs 我没找到这个代码额

这个是他把原来的layout.ejs文件替换成了修改后的新的 layout.ejs文件吧

Moosphan commented 4 years ago

找不到相关配置文件了,项目改动比较大了吧