dewfall123 / vitepress-for-component

📖 针对组件开发的VitePress。 重构版本https://github.com/dewfall123/ruabick
https://dewfall123.github.io/vitepress-for-component/
MIT License
194 stars 38 forks source link

将组件放入src的子级文件夹后无法正确渲染 #65

Closed linzowo closed 2 years ago

linzowo commented 2 years ago

Describe the bug 通过调整配置使工具能够编译src子目录下的组件文档,并在temp中生成了相关文档,但是在页面中访问时,无法展示正确内容。

To Reproduce

  1. 更改 docs\.vitepress\config.js配置更改后配置如下
    
    const base = process.env.NODE_ENV === 'production' ? '/@/' : '';
    const { resolve } = require('path');

module.exports = { title: 'UAAS平台', description: '项目文档', // 扫描srcIncludes里面的 *.md文件 srcIncludes: ['src/components'], alias: { // 为了能在demo中正确的使用 import { X } from 'test'

}, base, themeConfig: { // logo: '../logo.svg', nav: [{ text: 'demo', link: '/math' }], lang: 'zh-CN', locales: { '/': { lang: 'zh-CN', title: 'UAAS平台', description: '项目文档', label: '中文', selectText: '语言', nav: [{ text: '指南', link: '/' }], sidebar: [ { text: '介绍', link: '/' }, { text: 'Button', link: '/components/button/' }, { text: 'OrganizationSelect', link: '/OrganizationSelect/' }, ], }, }, search: { searchMaxSuggestions: 10, }, lastUpdated: true, prevLink: true, nextLink: true, }, };


2. 在`src\components`下创建组件
组件包含以下文件 

demo.vue index.vue index.zh-CN.md

```md
// src\components\OrganizationSelect\index.zh-CN.md
---
map:
  # 映射到docs的路径
  path: /OrganizationSelect
---

# OrganizationSelect 组织选择组件

用于筛选组织的多级树级组件

## 组织选择组件

### 基本用法

<demo src="./demo.vue"
  language="vue"
  title="基本用法"
  desc="点击切换。"> </demo>

## API

// ```ts
import OrganizationSelect from '/@/components/OrganizationSelect.vue';
// ```
  1. 编译后结果
    
    // docs\.temp\OrganizationSelect\index.md
    ---
    map:
    path: /OrganizationSelect
    realPath: src\components\OrganizationSelect\index.zh-CN.md // 自动生成路径页面显示404
    realPath: src\OrganizationSelect\index.zh-CN.md // 手动删除 \components 后页面能正常显示,但是demo.vue does not exist!
    ---

OrganizationSelect 组织选择组件

用于筛选组织的多级树级组件

组织选择组件

基本用法

<demo src="./demo.vue" language="vue" title="基本用法" desc="点击切换。">

API

import OrganizationSelect from '/@/components/OrganizationSelect.vue';



**Expected behavior**
希望能支持在已有项目内进行文档开发,或支持在src例如`src\components`子级目录下的文档编译显示

**System Info**
- vitepress version: "vitepress-for-component": "^0.17.1"
- vite version: "vite": "^2.6.13"
- Node version: v16.15.0
- OS version: win11

**Additional context**
Add any other context about the problem here.
dewfall123 commented 2 years ago

realPath: src\OrganizationSelect\index.zh-CN.md // 手动删除 \components 后页面能正常显示,但是demo.vue does not exist!

问题关键是realPath错误:

原理是访问/OrganizationSelect路由时,会去读取realPath的文件,但是读取src\components\OrganizationSelect\index.zh-CN.md文件404,这个不知道在你的代码中是什么情况。

我按照你的描述操作没能复现,最好能提供最小可复现仓库。

linzowo commented 2 years ago

我检查了我的文档中所写的路径发现存在错误修正后就可以了。最开始不行应该是配置不正确导致的。