Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

存在以下问题:INFO Generated: categories [null] for post #24

Open
zyu0 opened this issue Jun 13, 2021 · 13 comments
Open

存在以下问题:INFO Generated: categories [null] for post #24

zyu0 opened this issue Jun 13, 2021 · 13 comments

Comments

@zyu0
Copy link

zyu0 commented Jun 13, 2021

详细描述:hexo 5.4.0中使用这个插件出现了不会自动生成分类文件夹的问题,不知是我步骤不对还是哪里错了。我尝试后用执行两次hexo g解决了这个问题,结合github action不需要手动执行。但具体原因还未知。详细过程如我博客文章:https://tazyu.xyz/post/986feafd/

@zyu0
Copy link
Author

zyu0 commented Jun 13, 2021

我想到可能是因为front-matter是空的原因,所以第一次执行hexo g会先给文件写入分类信息,但文件夹这时没有生成,所以要再次写一遍才行。

@xu-song
Copy link
Owner

xu-song commented Jun 14, 2021

  1. public/categories目录内容的生成,应该是hexo-generator-category 这个插件负责的
    https://github.com/hexojs/hexo-generator-category

  2. 为什么会出现 Generated: categories [null] 有些奇怪,你是用的最新版的 hexo-auto-category吗?

@varm
Copy link

varm commented Aug 13, 2021

确实有这个问题,不过我这里显示的是 “categories [undefined] for post...
环境

{
  "hexo": {
    "version": "5.4.0"
  },
  "dependencies": {
    "hexo": "^5.4.0",
    "hexo-abbrlink": "^2.2.1",
    "hexo-auto-category": "^0.2.1"
  }
}

输出

--第1次 hexo g
INFO  Start processing
INFO  Generate link [213dff4d] for post [source/_posts/database/join在MapReduce中的用法.md][ join在MapReduce中的用法 ]
INFO  Generated: categories [undefined] for post [source/_posts/database/join在MapReduce中的用法.md][ join在MapReduce中的用法 ]
INFO  Generated: categories [[ 'database' ]] for post [join在MapReduce中的用法.md]
INFO  Files loaded in 1.25 s
INFO  Generated: sitemap.xml
INFO  Generated: sitemap.xsl
(node:15400) Warning: Accessing non-existent property 'lineno' of module exports inside circular dependency
(node:15400) Warning: Accessing non-existent property 'column' of module exports inside circular dependency
(node:15400) Warning: Accessing non-existent property 'filename' of module exports inside circular dependency
(node:15400) Warning: Accessing non-existent property 'lineno' of module exports inside circular dependency
(node:15400) Warning: Accessing non-existent property 'column' of module exports inside circular dependency
(node:15400) Warning: Accessing non-existent property 'filename' of module exports inside circular dependency
INFO  Generated: atom.xml
INFO  Generated: Staticfile
INFO  Generated: about/index.html
INFO  Generated: categories/index.html
INFO  Generated: feedback/index.html
INFO  Generated: tags/index.html
INFO  Generated: uncategorized/681abb5a.html
INFO  Generated: develop/16885286.html


--第2次 hexo g
INFO  Start processing
INFO  Generate link [681abb5a] for post [source/_posts/database/join在MapReduce中的用法.md][ join在MapReduce中的用法 ]
INFO  Generated: categories [[ 'database' ]] for post [source/_posts/database/join在MapReduce中的用法.md][ join在MapReduce中的用法 ]
INFO  Files loaded in 1.06 s
INFO  Deleted: uncategorized/681abb5a.html
INFO  Generated: atom.xml
INFO  Generated: categories/index.html
INFO  Generated: database/681abb5a.html
INFO  Generated: categories/life/index.html

@xu-song
Copy link
Owner

xu-song commented Aug 16, 2021

@varm 当前的日志看不出什么原因。
您多打印日志看看呢,多打几个变量 log.i(*) ,
主要代码在 node_modules\hexo-auto-category\lib\logic.js

// 4. process post
postStr = front.stringify(tmpPost);
postStr = '---\n' + postStr;
fs.writeFile(data.full_source, postStr, 'utf-8');
log.i("Generated: categories [%s] for post [%s]", tmpPost.categories, categories[categories.length-1]);

@varm
Copy link

varm commented Sep 2, 2021

@varm 当前的日志看不出什么原因。
您多打印日志看看呢,多打几个变量 log.i(*) ,
主要代码在 node_modules\hexo-auto-category\lib\logic.js

// 4. process post
postStr = front.stringify(tmpPost);
postStr = '---\n' + postStr;
fs.writeFile(data.full_source, postStr, 'utf-8');
log.i("Generated: categories [%s] for post [%s]", tmpPost.categories, categories[categories.length-1]);

调试了一下,我安装了一个 URL 插件:hexo-abbrlink,它内置了 hexo-auto-category,之前显示 “undefined” 是没有开启它的内置配置。
第一次执行 hexo g 后 markdown 文件 Front-matter 明明已经改好, 但是生成后的 html 文件还是在 public 目录的 “uncategorized” 里面,难道是 Generate 这一步有问题?

INFO  Start processing
INFO  Generate link [25f15880] for post [source/_posts/life/TestArticle.md][ TestArticle ]
INFO  Generated: categories [[ 'life' ]] for post [source/_posts/life/TestArticle.md][ TestArticle ]
INFO  Files loaded in 4.35 s
INFO  Generated: sitemap.xml     
INFO  Generated: atom.xml
INFO  Generated: categories/index.html      
INFO  Generated: about/index.html
INFO  Generated: uncategorized/25f15880.html
INFO  Generated: guestbook/index.html 

@xu-song
Copy link
Owner

xu-song commented Sep 2, 2021

那是不是跟 hexo-abbrlink 有关

@varm
Copy link

varm commented Sep 2, 2021

hexo-abbrlink 生成的 Front-matter:categories 和 自身的 abbrlink 都是对的,大概看着好像也没问题,你可以看下这里:https://github.com/rozbo/hexo-abbrlink/blob/master/lib/logic.js#L75

@xu-song
Copy link
Owner

xu-song commented Sep 2, 2021

你是不是没配

permalink: posts/:abbrlink/

https://github.com/rozbo/hexo-abbrlink#how-to-install

@varm
Copy link

varm commented Sep 2, 2021

配置了,生成的 markdown 是好的,文件名都有

---
title: TestArticle
abbrlink: 25f15880
categories:
  - life
date: 2021-08-16 14:24:51
tags:
---

到了 html 就变了,获取不到分类,链接都是 /uncategorized/25f15880.html,所以我就是有点怀疑 hexo-generator-category,但这是个官方插件,都两年没更新了。

@xu-song
Copy link
Owner

xu-song commented Sep 2, 2021

log.i(post.permalink) 看看

@varm
Copy link

varm commented Sep 2, 2021

在哪里加

@xu-song
Copy link
Owner

xu-song commented Sep 2, 2021

随便哪里加加看吧,能访问到post变量的地方

@varm
Copy link

varm commented Sep 2, 2021

在 hexo-generator-archive 里面加了,显示的 https://www.domain.com/uncategorized/25f15880.html,我看到此时 markdown 文件已经修改了,加了 abbrlink 和 categories,但是 post 变量的 raw 值显示的内容里面没有 abbrlink 和 categories。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants