如何在 docusaurus 中链接可下载文件?

发布于 2025-01-12 09:06:12 字数 594 浏览 2 评论 0原文

我想在我的文档上链接可下载内容,我尝试放入这样的链接:

<a
  href={
    require("@site/static/img/04-api/01/API-Description.png")
      .default
  } download="file-name"
>  download </a>

这会生成以下 html:

<a download="file-name" href="/assets/images/API-Description-6aeb65d8ae136a70b1b5a3d916d27ca0.png">  download </a>

<a download="file-name" href="/assets/images/API-Description-6aeb65d8ae136a70b1b5a3d916d27ca0.png">  download </a>

当我单击该链接时,我得到

“找不到页面”

我正在运行的版本:2.0.0-beta.17

I want to link downloadable content on my documentation and I tried putting in a link like this:

<a
  href={
    require("@site/static/img/04-api/01/API-Description.png")
      .default
  } download="file-name"
>  download </a>

This generates following html:

<a download="file-name" href="/assets/images/API-Description-6aeb65d8ae136a70b1b5a3d916d27ca0.png">  download </a>

<a download="file-name" href="/assets/images/API-Description-6aeb65d8ae136a70b1b5a3d916d27ca0.png">  download </a>

When I click on the link, I get

"Page Not Found"

I am running version: 2.0.0-beta.17

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酒几许 2025-01-19 09:06:12

我找到了两种方法来做到这一点。

首先,将文件放入 static 文件夹中。
示例:./static/image.png

1) 你的方式

<a href={ require("/image.png").default }>download</a>

2) 简单的方式

[download](/image.png)

** 请注意,我们没有使用 ! 来表明这是一个图像。

I have found two ways of doing this.

First, put the file inside the static folder.
Example: ./static/image.png.

1) Your way

<a href={ require("/image.png").default }>download</a>

2) Simple way

[download](/image.png)

** Note that we did not use the ! to indicate that is an image.

初熏 2025-01-19 09:06:12

您必须将 inline-html 与 download 属性和 target="_blank" 一起使用

[not working](/logo.png)

<a href={ require("/logo.png").default } download={"origName"}>not working</a>

<a target="_blank" href={ require("/logo.png").default } download>working</a>

You had to use inline-html with the download attribute and target="_blank"

[not working](/logo.png)

<a href={ require("/logo.png").default } download={"origName"}>not working</a>

<a target="_blank" href={ require("/logo.png").default } download>working</a>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文