如何将非涂鸦文件添加到基于涂鸦的网站
How to add non scribble file to a scribble based website
我可以使用 image
在我的涂鸦文档中嵌入图像,渲染函数会将其复制到目标位置。现在,我还想在我的文档中包含非图像文件,例如可以下载的 MP3 或 PDF 文件。
此外,我不能只将文件包含在源文件夹中,然后 link 添加到其中,因为如果我将文档呈现到不同的目标文件夹中,它不会被复制。
最后,我知道我可以手动创建目标目录,然后将文件粘贴到那里。或者我可以修改我用来构建文档的任何文件以复制该文件。这并不令人满意,因为现在我必须在两个地方跟踪图像。 .scrbl
源文件,以及目标目录或构建文件。
那么,有没有一种方法可以在 scribble 中包含一个非 scribble(或图像)文件,例如 MP3 或 PDF,以便渲染函数知道抓取它并将其包含在文档中?
虽然有点乱,但您可以将 image
与 hyperlink
结合使用以获得您想要的结果。您使用 image
函数获取 render
函数来复制文件,并使用 hyperlink
向其添加一个 link。您的文档将类似于:
Here is a @image{file.mp3}@hyperlink["file.mp3"]{file}.
这是有效的,因为 image
函数还需要一个扩展列表来尝试嵌入,但是这个列表默认为空列表,因此它不会嵌入文件,而只会将其复制到目的地。然后,您可以使用 hyperlink
到 link 到现在复制的 file.mp3
文件。
您可以使用以下函数将其合并为一个操作:
(define (embed-file file . content)
(list
(image file)
(apply hyperlink file content)))
现在您可以在自己的文档中使用 embed-file
:
Here is a @embed-file["file.mp3"]{file}.
(我应该注意到这个想法来自Ben Lerner。)
我接管了某人的代码库,他们使用 Leif Andersen 提供的 解决了这个问题。但是,这在链接到源目录中子文件夹中的文件时会导致问题。有问题的文件被移动到输出目录的根目录,而超链接没有正确更新。相反,我发现了以下不那么 hack-y 的解决方案。
您可以使用 link-resource
structure of the scribble/html-properties
module. This expects the path of the original file. You place this link-resource
into a style
struct of the scribble/core
模块。最后,此样式作为参数传递给 hyperlink
.
将它们放在一起,embed-file
函数变成了
(define (embed-file file . content)
(apply hyperlink
file
content
#:style (style "place-resources-in-output-folder" ; name
(list (link-resource file)))))
"place-resources-in-output-folder"
只是我给样式起的名字。
这可确保文件都移动到根输出文件夹并正确链接。
我可以使用 image
在我的涂鸦文档中嵌入图像,渲染函数会将其复制到目标位置。现在,我还想在我的文档中包含非图像文件,例如可以下载的 MP3 或 PDF 文件。
此外,我不能只将文件包含在源文件夹中,然后 link 添加到其中,因为如果我将文档呈现到不同的目标文件夹中,它不会被复制。
最后,我知道我可以手动创建目标目录,然后将文件粘贴到那里。或者我可以修改我用来构建文档的任何文件以复制该文件。这并不令人满意,因为现在我必须在两个地方跟踪图像。 .scrbl
源文件,以及目标目录或构建文件。
那么,有没有一种方法可以在 scribble 中包含一个非 scribble(或图像)文件,例如 MP3 或 PDF,以便渲染函数知道抓取它并将其包含在文档中?
虽然有点乱,但您可以将 image
与 hyperlink
结合使用以获得您想要的结果。您使用 image
函数获取 render
函数来复制文件,并使用 hyperlink
向其添加一个 link。您的文档将类似于:
Here is a @image{file.mp3}@hyperlink["file.mp3"]{file}.
这是有效的,因为 image
函数还需要一个扩展列表来尝试嵌入,但是这个列表默认为空列表,因此它不会嵌入文件,而只会将其复制到目的地。然后,您可以使用 hyperlink
到 link 到现在复制的 file.mp3
文件。
您可以使用以下函数将其合并为一个操作:
(define (embed-file file . content)
(list
(image file)
(apply hyperlink file content)))
现在您可以在自己的文档中使用 embed-file
:
Here is a @embed-file["file.mp3"]{file}.
(我应该注意到这个想法来自Ben Lerner。)
我接管了某人的代码库,他们使用 Leif Andersen 提供的
您可以使用 link-resource
structure of the scribble/html-properties
module. This expects the path of the original file. You place this link-resource
into a style
struct of the scribble/core
模块。最后,此样式作为参数传递给 hyperlink
.
将它们放在一起,embed-file
函数变成了
(define (embed-file file . content)
(apply hyperlink
file
content
#:style (style "place-resources-in-output-folder" ; name
(list (link-resource file)))))
"place-resources-in-output-folder"
只是我给样式起的名字。
这可确保文件都移动到根输出文件夹并正确链接。