hexojs / hexo

A fast, simple & powerful blog framework, powered by Node.js.
https://hexo.io
MIT License
39.48k stars 4.86k forks source link

About rendering ejs page #1453

Closed xinyuwang closed 9 years ago

xinyuwang commented 9 years ago

I want to add some static page to show my personal information in my blog. To keep the style consistent, I want to use the layout.ejs just like the index.ejs in my theme. So, I write some ejs file in theme/layout/ but it doesn't work. If I write some ejs in /theme/layout, should this file be rendered? is that only the special name(e.g. index.ejs, post.ejs) will be rendered? Can I rendering my own ejs file (combined with layout.ejs) by setting some configuration? I try to use script and Hexo API to render my ejs file, however, it can not combine the layout.ejs. I am a freshman with Hexo. Thanks for replying. Wish you a nice day.

morris821028 commented 9 years ago

I not sure what you need.

For example, on default theme landscape without tags.ejs. You can't visited https://hexo.io/hexo-theme-landscape/tags/, but https://hexo.io/hexo-theme-landscape/tags/Bar/ can.

modify theme/landscape/layout/layout.ejs and add page.layout == 'tags'

        <% if (page.layout == '404') { %>
          <%- partial('404') %>
        <% } else if(page.layout == 'page' || page.layout == 'tags') { %>
          <section id="main" style="width: 95%"><%- body %></section>
        <% } else { %>
          <section id="main"><%- body %></section>
          <% if (theme.sidebar && theme.sidebar !== 'bottom'){ %>
            <%- partial('_partial/sidebar', null, {cache: !config.relative_link}) %>
          <% } %>
        <% } %>

also build new file theme/landscape/layout/tags.ejs, maybe like this

<article class="article article-type-post" itemscope="" itemprop="blogPost">
    <div class="article-inner">     
    <header class="article-header">
    <h1 itemprop="name">
      <a class="article-title" href="">Tag Cloud</a>
    </h1>
    </header>   
    <footer class="article-footer"></footer>
        <div class="widget tagcloud">
          <%- tagcloud({'amount': '1024', 'orderby': 'name', 'order': '1', min_font: 14, max_font: 48}) %>
        </div>
    </div>
</article>

then, make new dictionary blog/source/tags/index.md

title: Tags
layout: tags
---

good luck.

xinyuwang commented 9 years ago

@morris821028 Thanks a lot .