GithubHelp home page GithubHelp logo

Comments (14)

wuweijia1994 avatar wuweijia1994 commented on July 28, 2024 1

Wow, thank you so much! Now I got it!

from hexo-theme-phantom.

klugjo avatar klugjo commented on July 28, 2024

Sorry for the late reply, I have been busy starting a new job.

you will have to define what is the order of importance in the front matter then you can go here:

https://github.com/klugjo/hexo-theme-phantom/blob/master/layout/index.ejs#L7

And you have access to all the posts, so order them whichever way you like.

from hexo-theme-phantom.

wuweijia1994 avatar wuweijia1994 commented on July 28, 2024

Thanks for replying! But I am still a little confused about that. Is there any example of that? For example, I have articles called A and B, and then how to define the order in this "index.ejs" file?

from hexo-theme-phantom.

klugjo avatar klugjo commented on July 28, 2024

So you want to sort by name ?

from hexo-theme-phantom.

wuweijia1994 avatar wuweijia1994 commented on July 28, 2024

No, I want to sort by the importance. But I have no idea how to define the order.

from hexo-theme-phantom.

klugjo avatar klugjo commented on July 28, 2024

what is importance ? It is not a default hexo parameter

from hexo-theme-phantom.

wuweijia1994 avatar wuweijia1994 commented on July 28, 2024

For example, say I have "A" and "B". I write "A" first and normally, it will be in the second place. But I still want it to be the first one in the display. Is it possible to do that?

from hexo-theme-phantom.

klugjo avatar klugjo commented on July 28, 2024

As I said you need to defined it in front matter then modify the sort order in the file I indicated

from hexo-theme-phantom.

klugjo avatar klugjo commented on July 28, 2024

https://hexo.io/docs/front-matter.html

from hexo-theme-phantom.

klugjo avatar klugjo commented on July 28, 2024

for example

first post:

title: Hello World
date: 2013/7/13 20:46:25
importance: 1

second post:

title: Hello World 2
date: 2013/7/13 20:46:25
importance: 2
---

then you can do something like

<section class="tiles">
    <%
        // Fast array clone
        var sortedPosts = page.posts.slice(0);
        sortedPosts.sort(function(a, b){
          return a.importance < b.importance
        });
    %>
    <% sortedPosts.forEach(function(item, index){ %>
        <%- partial('_partial/article-index', {item: item, index: index}) %>
    <% }); %>
</section>

from hexo-theme-phantom.

wuweijia1994 avatar wuweijia1994 commented on July 28, 2024

Sorry to bother again. I understand what you said, and copy and paste the code. But it still keeps the same order.

/Users/weijiawu/blog/source/_posts/A.md

--- 
title: Medical Device for foot pressure 
date: 2018-04-03 19:57:46 
tags: Sensor 
cover_index: /images/Medical Device.jpg 
importance: 5 
---

/Users/weijiawu/blog/source/_posts/B.md

---
title: Self-Balance Bike with Inverted Pendulum
date: 2018-04-02 12:13:09
tags:

Control
Robotics
cover_index: /images/Inverted Pendulum Cover.jpg
importance: 7
---

/Users/weijiawu/blog/themes/phantom/layout/index.ejs

<header>
    <h1><%- theme.subtitle_main %></h1>
    <p><%- theme.susbtitle_secondary %></p>
</header>

<section class="tiles">
   <%
       // Fast array clone
       var sortedPosts = page.posts.slice(0);
       sortedPosts.sort(function(a, b){
         return a.importance < b.importance
       });
   %>
   <% sortedPosts.forEach(function(item, index){ %>
       <%- partial('_partial/article-index', {item: item, index: index}) %>
   <% }); %>
</section>

<%- partial('_partial/pagination') %>

from hexo-theme-phantom.

klugjo avatar klugjo commented on July 28, 2024

Have you tried return a.importance > b.importance

from hexo-theme-phantom.

wuweijia1994 avatar wuweijia1994 commented on July 28, 2024

Yes, I tried but still failed.

from hexo-theme-phantom.

wuweijia1994 avatar wuweijia1994 commented on July 28, 2024

I suddenly know how to solve it! Just in the "_config.yml" and change the section"order_by: -date" to "order_by: -importance". Then it is solved!

from hexo-theme-phantom.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.