3

我有一个用于 Web 应用程序的 Open Search XML,它看起来像这样:

<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
    <ShortName>AppName</ShortName>
    <Description>Search App</Description>
    <InputEncoding>UTF-8</InputEncoding>
    <Image width="32" height="32" type="image/png">https://not.my.app.url/public/favicon.png</Image>
    <Url type="text/html" method="get" template="https://not.my.app.url/$/search?q={searchTerms}"/>
</OpenSearchDescription>

这样做的一个问题是,如果我想在不同的 URL 上托管应用程序,https://not.my.app.url我将不得不手动编辑清单以匹配新的主机名,或者使用某种预处理器将正确的主机名放在那里。有什么办法可以代替相对路径吗?我尝试简单地省略主机名和协议说明符,但随后 Firefox 拒绝将其安装为搜索提供程序(我没有测试任何其他浏览器)。

4

1 回答 1

2

OpenSearch 规范将URL 模板语法定义为:

ttemplate      = tscheme ":" thier-part [ "?" tquery ] [ "#" fragment ]
tscheme        = *( scheme / tparameter )
thier-part     = "//" tauthority ( tpath-abempty / tpath-absolute / tpath-rootless / path-empty )
tauthority     = [ tuserinfo "@" ] thost [ ":" tport ]
tuserinfo      = *( userinfo / tparameter )
thost          = *( host / tparameter )
tport          = *( port / tparameter )
tpath-abempty  = *( "/" tsegment )
tsegment       = *( segment / tparameter )
tpath-absolute = "/" [ tsegment-nz *( "/" tsegment ) ]
tsegment-nz    = *( segment-nz / tparameter )
tpath-rootless = tsegment-nz *( "/" tsegment )
tparameter     = "{" tqname [ tmodifier ] "}"
tqname         = [ tprefix ":" ] tlname
tprefix        = *pchar
tlname         = *pchar
tmodifier      = "?"
tquery         = *( query / tparameter )
tfragement     = *( fragement / tparameter )

如您所见,该方案和主机是必需的。

换句话说,不允许使用相对 URL。
您必须使用绝对 URL,例如http://example.com/search?q={searchTerms}.

于 2021-05-08T15:03:22.570 回答