hexojs / hexo

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

Filter posts by custom post.variables #3354

Closed ghost closed 5 years ago

ghost commented 5 years ago

Tags plugin works good, but I need other more variables that filter out my blogposts. For example, "color" variable. My .md:

layout: post
title: hello
color: black

And another post has .md:

layout: post
title: bye
color: green

My plan is to create a widget (same look and feel as a tagcloud) that grabs all my custom post variables ("color" cloud"), and then when user clicks "green" for example, the blogpost with title: bye filters out.

Anybody tried this before? Any clues how to go about this? I am a bit worried as I feel I have to go into the core of hexo and write a new plugin for this. Or can I just copy/rename the whole "tagcloud plugin" from tag to color for example and do this for multiple custom variables?

JOduMonT commented 5 years ago

@7pedroruizzz sadly I don't have the solution but a question pretty similar here

However, I change my approach after reading this one, and applied the solution with success.

I hope, these will gave you some hint

tcrowe commented 5 years ago

@7pedroruizzz Hi! Any variables you add are available in the templates 👍🏻

e.g. <%=page.color%>

Some themes rename page to post and etc.

ghost commented 5 years ago

@tcrowe

@jodumont

Hello!

I know, but I need these custom variables in a tagcloud widget.

Currently I have the tag-plugin installed and working:

<% if (site.tags.length){ %>
<div class="m_widget tagcloud">
    <h5>Tags</h5>
    <div class='content'>
        <%- tagcloud(site.tags, {
            min_font: 14,
            max_font: 14,
        }) %>
    </div>
</div>
<% } %>

This is a tagcloud tags.

What I need is "in addition" another tagcloud with only my custom post.variable namely color (= as defined as a post.variable in my .md files).

So the color tagcloud shows green, blue,yellow, etc. and works the same way as the "original" tagcloud with tags.

Makes sense and possible to accomplish (without going into the Hexo core to make tweaks?)?

tcrowe commented 5 years ago

Sounds interesting

We can accomplish with front matter Yaml list:

color:
- green
- blue
- yellow

Can you try it then msg back?

tcrowe commented 5 years ago

I hope that worked, @7pedroruizzz.

If not please re-open this and we can find another solution. 👍🏻