github中page.type是什么?怎么无法获取呢

{% if page.type == 'archives' %}
{% assign title = '归档' %}
{% assign icon = 'archive' %}
{% endif %}

{% if page.type == 'categories' %}
{% assign title = '分类' %}
{% assign icon = 'category' %}
{% endif %}

{% if page.type == 'tags' %}
{% assign title = '标签' %}
{% assign icon = 'tag' %}
{% endif %}

<div class="archive-title" >
  <h2 class="{{ icon }}-icon"><span class='archive-folder'>{{ title }}</span></h2>
  {% if page.type == 'archives' %}
  <div class="archiveslist archive-float clearfix">
    {% assign count = 1 %}
    {% for post in site.posts  %}
    {% capture this_date %}{{ post.date }}{% endcapture %}
    {% capture next_date %}{{ post.previous.date }}{% endcapture %}
    {% capture this_date_str %}{{ this_date | date: "%Y-%m" }}{% endcapture %}
    {% capture next_date_str %}{{ next_date | date: "%Y-%m" }}{% endcapture %}
    {% if this_date_str != next_date_str %}
    <ul class="archive-list">
    <li class="archive-list-item">
    <a class="archive-list-link" href="#{{ this_date | date: "%Y-%m" }}">{{ this_date | date: "%Y 年 %m 月" }}</a>
    <span class="archive-list-count">{{ count }}</span>
    {% assign count = 1 %}
    {% else %}
    {% assign count = count | plus: 1 %}
    {% endif %}
        
    </li>
    {% endfor %}
    </ul>
 </div>
  {% endif %}
  {% if page.type == 'categories' %}
  
  <ul class="archive-list">
  <div class="archiveslist archive-float clearfix">
    {% for category in site.categories  %}
    <li class="archive-list-item">
    <a class="archive-list-link" href="#{{ category[0] }}">{{ category[0] }}</a>
    <span class="archive-list-count">{{ category[1] | size }}</span>
    </li>
    {% endfor %}
 </div>
 </ul>
 {% endif %}
 
  {% if page.type == 'tags' %}
  
  <ul class="archive-list">
  <div class="archiveslist archive-float clearfix">
    {% for tag in site.tags  %}
    <li class="archive-list-item">
    <a class="archive-list-link" href="#{{ tag[0] }}">{{ tag[0] }}</a>
    <span class="archive-list-count">{{ tag[1] | size }}</span>
    </li>
    {% endfor %}
 </div>
 </ul>
 {% endif %}
 
</div>
<div id="main" class="archive-part clearfix">
  <div id="archive-page">
  {% for post in site.posts %}
  {% assign item = post %}
  {% assign index = true %}
  {% include _partial/article_row.html %}
  {% endfor %}
<!--
<% if (page.total > 1){ %>
  <nav id="page-nav" class="clearfix archive-nav">
    <%- paginator({
      prev_text: '<span></span>Prev',
      next_text: 'Next<span></span>'
    }) %>
  </nav>
<% } %>
-->
  </div>
</div>
阅读 4.1k
2 个回答

看这个代码像是hexo搭建的博客?

这样的话对于每一篇文章来说,都是有一些全局变量的,具体信息可以在变量(hexo)中查看。

page.type确实是没有的,page对象拥有的只是下面这些属性

clipboard.png

这个貌似和 github 无关。。而是静态博客框架里的代码。。你用的应该不是 hexo 就是Jekyll

page.type 讲道理是不需要你自己直接修改的。对于要 archive 的文章,你修改这个属性就可以了:

clipboard.png

对于不同的 tag,你如果要修改,在这里改就行:

clipboard.png

或者,在你写 md 的时候,在正文开始前用 --- 分隔,加上头信息:

clipboard.png

可以参考下我的文章原文件:https://raw.githubusercontent...

你贴出来的代码是框架根据这些文章元信息生成 HTML 页面的代码,你可能并不需要去修改那些

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进