XML

Parcel 支持使用 @parcel/transformer-xml 插件转换在 XML 文件中定义的 RSSAtom 源。当检测到 .xml.rss.atom 文件时,它将自动安装到您的项目中。

依赖

#

Parcel 转换 RSS 和 Atom 源中的 URL 引用,以匹配最终名称和公共 URL,并在适当的情况下包含内容哈希

在 RSS 中,这包括:

在 Atom 中,这包括:

嵌入式 HTML

#

RSS 和 Atom 源中嵌入的 HTML 和 XHTML 内容也按照 HTML 中描述的方式进行转换。嵌入式 HTML 中的所有 URL 引用也将被转换,并且引用的文件将通过相关的 Parcel 管道进行处理。

HTML 引用

#

可以使用 <link> 元素从 HTML 文件中引用 RSS 和 Atom 源。使用 application/rss+xmlapplication/atom+xml MIME 类型。Parcel 将确保以这种方式引用的 XML 文件不会收到内容哈希,并且具有随时间保持一致的 URL。

<link
href="feed.xml"
rel="alternate"
type="application/rss+xml"
title="博客 RSS 源"
/>

示例

#

此示例展示了一个包含单个条目的 Atom 源。两个 <link> 元素中的 URL 引用将被重写以包含公共 URL,并且文章内容中引用的图像将被处理并添加内容哈希。

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>示例源</title>
<subtitle>一个副标题。</subtitle>
<link href="/" />
<id>urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6</id>
<updated>2021-12-13T18:30:02Z</updated>
<entry>
<title>精彩文章</title>
<link href="post.html" />
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
<updated>2021-12-13T18:30:02Z</updated>
<summary>一些文字。</summary>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>这是文章内容。</p>
<img src="image.png" />
</div>
</content>
<author>
<n>约翰·多伊</n>
<email>johndoe@example.com</email>
</author>
</entry>
</feed>