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

文档复用中的多链接场景需求。 #4386

Open
4 tasks done
AgentRich opened this issue Nov 26, 2024 · 4 comments
Open
4 tasks done

文档复用中的多链接场景需求。 #4386

AgentRich opened this issue Nov 26, 2024 · 4 comments

Comments

@AgentRich
Copy link

AgentRich commented Nov 26, 2024

Is your feature request related to a problem? Please describe.

困惑

在多文档写作中经常会有重复的内容出现,我们希望做到一处改动,处处更新。这是技术文档写作中的文档复用。
在使用VitePress建设个人网站的时候关注到,文档复用的需求可以使用包含markdown文件功能实现。
但有一个场景目前大部分静态文档网站均无法实现:就是当复用源中包含了连接跳转,而这些链接在不同的文档中又指向了不同的地址。为了描述方便,我们把这种场景称作多链接复用场景,被复用的文档称作复用源,引用内容的文档称作引用文档。

现状

我尝试使用VitePress提供的包含markdown文件外部链接访问frontmatter数据三个功能组合进行需求实现。但效果并不理想。在Markdown语法中,连接的写法是[title](link)。当我尝试在link中使用Mustache语法时,VitePress并没有对其进行解析。如下图所示:
image
image
image

Describe the solution you'd like

包含markdown文件功能确实能非常好的实现复用功能,但希望能在此功能上有所突破。我试想了一种解决方案,形式跟Vue.js中的插槽很像。

想象方案

  1. 首先在复用源文档引入占位符,占位符为Html标签形式,属性中name代表外部插入变量的名称。
  2. 在引用文档的 include语法中加入[] ,用于对应占位符名字给变量赋值。
    代码形式如下:
    image

如此让文档间的关系多了类似继承的特性,真正实现了docs like code。

Describe alternatives you've considered

目前的代替方案只能是将复用源文档进行分块复用,采用块1 + link + 块2 的方式完成需求。
但当文档中类似的情况多起来后,维护连接就变得异常困难。
而且有些为了提升阅读体验采用整篇复用的文档,也会因为这个小小的需求从整篇复用拆成分块复用,致使工作量飙升。

Additional context

No response

Validations

@chgeo
Copy link
Contributor

chgeo commented Nov 27, 2024

Very hard to follow here. Consider writing in English.

@AgentRich
Copy link
Author

Very hard to follow here. Consider writing in English.

Confusion

In multi-document writing, duplicate content often appears, and we hope to achieve a change in one place with updates everywhere else. This is known as document reuse in technical documentation.
When building a personal website using VitePress, I noticed that the need for document reuse can be achieved using the Markdown File Inclusion feature.
However, there is one scenario that most static documentation websites currently cannot handle: when the reuse source contains links that point to different addresses in different documents. For ease of description, we refer to this scenario as the multi-link reuse scenario, where the reused document is called the reuse source, and the document that references the content is called the reference document.

Status quo

I attempted to use a combination of three features provided by VitePress—Markdown File Inclusion, External Links, and Accessing Frontmatter Data—to meet my requirements. However, the results were not ideal. In Markdown syntax, links are written as [title](link). When I tried to use Mustache syntax in the link part, VitePress did not parse it. As shown in the following image:
image
image

Describe the solution you'd like
The Markdown File Inclusion feature indeed works very well for achieving reuse, but I hope to see some advancements in this functionality. I have envisioned a solution that is similar to slots in Vue.js.

Imagined Solution

Introduce Placeholders in the Reuse Source Document
First, introduce placeholders in the reuse source document. These placeholders should be in the form of HTML tags, with the name attribute representing the name of the external inserted variable.
Assign Values to Placeholders in the Reference Document
In the include syntax of the reference document, add [] to correspond to the placeholder names and assign values to the variables.
The code format would look like this:
image
Proposed Solution
By implementing this approach, the relationship between documents gains characteristics similar to inheritance, truly achieving "docs like code."

Describe Alternatives You've Considered
Currently, the only alternative is to break down the reuse source document into smaller sections and use a combination of block1 + link + block2 to meet the requirement.
However, as the number of similar cases increases in the document, maintaining these links becomes extremely difficult.
Moreover, some documents that use full-text reuse to enhance the reading experience would need to be split into smaller blocks due to this small requirement, significantly increasing the workload.

@VoVAllen
Copy link
Contributor

VoVAllen commented Dec 7, 2024

You should use Vue Component here.

@AgentRich
Copy link
Author

You should use Vue Component here.
Just looked at the usage of Vue Components, but it still feels quite complex.

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