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

自动为没有Front-matter的md按语雀知识库目录增加categories #64

Closed
allen-wong opened this issue May 19, 2020 · 2 comments
Closed

Comments

@allen-wong
Copy link

allen-wong commented May 19, 2020

hexo怎么显示知识库目录

@x-cold
Copy link
Owner

x-cold commented May 22, 2020

这个功能尚未实现,可以 MR 提供一下~

@allen-wong
Copy link
Author

allen-wong commented May 26, 2020

这是加入categories front-matter的关键代码,目前hexo本身并没有显示目录的功能。我认为这不是本插件能解决的。
第73行改成这样:const { config, client, toc, _cachedArticles } = this;

lib\Downloader.js 77行插入以下代码(写得丑,自己优化一下)

        if (config.autoFrontMatter) { // 自己在package.js添加配置项
          let categories = new Array();
          const getCategories = function (toc, item) { // 根据toc生成categories
            for (let i = 0; i < toc.length; i++) {
              if (toc[i].uuid === item.parent_uuid) {
                categories.push(toc[i].title);
                if (!!toc[i].parent_uuid) {
                  getCategories(toc, toc[i]);
                } else {
                  break;
                }
              }
            }
          }
          for (let i = 0; i < toc.length; i++) { // 取得文章对应知识库的目标项
            if (toc[i].type === 'DOC' && toc[i].id == article.id) {
              getCategories(toc, toc[i]);
            }
          }
          const str_categories = categories.length < 1 ? '' : `categories:\n- ${categories.length > 1 ? '[' + categories.join(',') + ']' : categories[0]}\n`;
          const front_matter = `---\ntitle: ${article.title}\ndate: ${article.created_at}\nupdated: ${article
            .updated_at}\n${str_categories}---\n`;
          article.body = front_matter + article.body;
        }

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

2 participants