litten / hexo-theme-yilia

一个简洁优雅的hexo主题 A simple and elegant theme for hexo.
http://litten.me/
8.37k stars 2.41k forks source link

hexo g的时候出现错误! #748

Open imydl opened 6 years ago

imydl commented 6 years ago
TypeError: /home/wwwroot/hexo.imydl.tech/themes/yilia/layout/page.ejs:1
 >> 1| <%- partial('_partial/article', {post: page, index: false}) %>

/home/wwwroot/hexo.imydl.tech/themes/yilia/layout/_partial/article.ejs:61
    59|         </div>
    60|       <% } %>
 >> 61|       <%- partial('post/tag') %>
    62|       <%- partial('post/category') %>
    63|       <% if (index && theme.show_all_link){ %>
    64|         <p class="article-more-link">

/home/wwwroot/hexo.imydl.tech/themes/yilia/layout/_partial/post/tag.ejs:7
    5|          <% post.tags.forEach(function(tag, i){ %> 
    6|              <li class="article-tag-list-item">
 >> 7|                  <a href="javascript:void(0)" class="js-tag article-tag-list-link color<%= tag.name.length % 5 + 1 %>"><%-tag.name%></a>
    8|              </li>
    9|              <% }) %>
    10|         </ul>

Cannot read property 'length' of undefined
namasikanam commented 5 years ago

遇到了同样的问题,请问答主解决了嘛QAQ?跪求解决方案!


Update: 已解决.

./themes/yilia/layout/_partial/post/category.ejs改为:

<% if (post.categories && post.categories.length){ %>
<div class="article-category tagcloud">
    <i class="icon-book icon"></i>
    <ul class="article-tag-list">
        <% post.categories.forEach(function(tag, i){ %>
        <% if (tag.hasOwnProperty('name')){ %>
        <li class="article-tag-list-item">
            <a href="<%= config.root %><%= tag.path %>/" class="article-tag-list-link color<%= tag.name.length % 5 + 1 %>">
                <%-tag.name%></a>
        </li>
        <% } %>
        <% }) %>
    </ul>
</div>
<% } %>

./themes/yilia/layout/_partial/post/tag.ejs改为:

<% if (post.tags && post.tags.length){ %>
<div class="article-tag tagcloud">
    <i class="icon-price-tags icon"></i>
    <ul class="article-tag-list">
        <% post.tags.forEach(function(tag, i){ %>
        <% if (tag.hasOwnProperty('name')){ %>
        <li class="article-tag-list-item">
            <a href="javascript:void(0)" class="js-tag article-tag-list-link color<%= tag.name.length % 5 + 1 %>">
                <%-tag.name%></a>
        </li>
        <% } %>
        <% }) %>
    </ul>
</div>
<% } %>

Update at Nov 13, 2021: 感谢 @white-loub 指出错误,已修复qwq

Sunxb commented 5 years ago

已解决.

好像还是不行哦

white-loub commented 2 years ago

@namasikanam 的解决方案的第二个文件修改的地方少了一个 if