hexojs / hexo

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

Where are "tags" generated in post-overview? #3198

Closed ghost closed 6 years ago

ghost commented 6 years ago

There are tags under each individual blogpost in the post-overview page / article page.

See image here...

image

I need to make some javascript changes to those tags, but I cannot find the corresponding file.

(I tried ... node_modules > hexo > lib > plugins > helper > tagcloud).

But that is the wrong one... that one is for the sidebar tagcloud.

I need the tags per individual blogpost in post-page / article-page. Thanks.

tcrowe commented 6 years ago

Hi @rabas007

Which theme is it? In ./themes/_____/layout you should be able to find how those tags render and customize it.

If you check can you let me know if that is the spot?

ghost commented 6 years ago

@tcrowe - Hi Tony,

I am trying to highlight specific tags within all tags for each individual blogpost. I use REGEX code for that. It does work in tagcloud.js, see here... (https://github.com/hexojs/hexo/blob/master/lib/plugins/helper/tagcloud.js)

I added following lines right before line-224:

if(tag.name.match(/[a-zA-Z0-9]+\s*\([a-zA-Z0-9]+\)/)) {
      result.push(
        '<a class="unique-color-for-specific-tag" href="' + self.url_for(tag.path) + '" style="' + style + '">' +
        (transform ? transform(tag.name) : tag.name) +" ("+tag.length+")"+
        '</a>'
      );

This does what I need in tagcloud, but I want to apply the same code to the tags under each blogpost in the posts-overview and blogpost-page pages. I just cannot find where they are rendered in which plugin?

tcrowe commented 6 years ago

Oh that's why I was asking the theme name so we can look for the tag code.

tagcloud usage is here https://hexo.io/docs/helpers.html#tagcloud

ghost commented 6 years ago

OK, thanks. But how to fit in my REGEX code in there so it renders only the specific tags I want? My REGEX code... (/[a-zA-Z0-9]+\s*\([a-zA-Z0-9]+\)/)). So I do NOT want ALL tags to show in tagcloud, just the ones that match the REGEX rule above.

tcrowe commented 6 years ago

You never answered my question which theme so I guessed this one:

https://github.com/stkevintan/hexo/blob/master/themes/material-flow/layout/_partial/post.ejs#L24

ghost commented 6 years ago

@tcrowe - yes, this theme. Sorry, I thought it did not matter because my issue is with node_modules and the hexo folder > lib > plugins > helper > ???

tcrowe commented 6 years ago

The code you're looking for is in your theme, not inside node_modules

ghost commented 6 years ago

@tcrowe - I tested it in tagcloud.js for tagcloudand it works (so it is 100% in node_modules). I just cannot find where the tags are rendered for the posts, because I need to do the same for posts what I did for tagcloud.

tcrowe commented 6 years ago

Whenever helpers are not what I need I goto the theme code. I would still argue that's the best place to go. If not maybe someone else can chime in who better understands.

tcrowe commented 6 years ago

I also create custom helpers sometimes: https://hexo.io/docs/helpers.html

They go in the project root then ➡️./source

tcrowe commented 6 years ago

Here's an example of one we recently discussed https://github.com/hexojs/hexo/issues/3173#issuecomment-395931673