You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何避免Jekyll中webfinger的JSON内容被HTML <p>标签包裹?

问题:Jekyll生成WebFinger JSON被HTML标签包裹的解决办法

我尝试在Jekyll中通过Markdown文件(如webfinger.md,在前置配置中设置路径)添加.well-known/webfinger目录下的WebFinger文件,配置代码如下:

---
layout: null
permalink: /.well-known/webfinger
---
{
  "subject": "acct:blah@blah.com",
  "aliases": [
    "https://blah.com/@blah",
    "https://blah.com/users/blah"
  ],
  "links": [
    {
      "rel": "http://webfinger.net/rel/profile-page",
      "type": "text/html",
      "href": "https://blah.com/@blah"
    },
    {
      "rel": "self",
      "type": "application/activity+json",
      "href": "https://blah.com/users/blah"
    },
    {
      "rel": "http://ostatus.org/schema/1.0/subscribe",
      "template": "https://mastodon.nz/authorize_interaction?uri={uri}"
    }
  ]
}

原本期望输出原生JSON,但生成的内容被HTML <p>标签包裹,请问有什么方法可以避免这种情况?


解决方案

方法1:改用.json后缀的文件

将webfinger.md重命名为webfinger.json,保留原前置配置和JSON内容:

---
layout: null
permalink: /.well-known/webfinger
---
{
  "subject": "acct:blah@blah.com",
  "aliases": [
    "https://blah.com/@blah",
    "https://blah.com/users/blah"
  ],
  "links": [
    {
      "rel": "http://webfinger.net/rel/profile-page",
      "type": "text/html",
      "href": "https://blah.com/@blah"
    },
    {
      "rel": "self",
      "type": "application/activity+json",
      "href": "https://blah.com/users/blah"
    },
    {
      "rel": "http://ostatus.org/schema/1.0/subscribe",
      "template": "https://mastodon.nz/authorize_interaction?uri={uri}"
    }
  ]
}

Jekyll会识别.json文件为非Markdown类型,跳过Markdown渲染流程,直接输出原生JSON内容。

方法2:用raw标签禁用Markdown渲染

若坚持使用.md后缀,在JSON内容前后添加Jekyll的raw标签,阻止渲染器处理这段内容:

---
layout: null
permalink: /.well-known/webfinger
---
{% raw %}
{
  "subject": "acct:blah@blah.com",
  "aliases": [
    "https://blah.com/@blah",
    "https://blah.com/users/blah"
  ],
  "links": [
    {
      "rel": "http://webfinger.net/rel/profile-page",
      "type": "text/html",
      "href": "https://blah.com/@blah"
    },
    {
      "rel": "self",
      "type": "application/activity+json",
      "href": "https://blah.com/users/blah"
    },
    {
      "rel": "http://ostatus.org/schema/1.0/subscribe",
      "template": "https://mastodon.nz/authorize_interaction?uri={uri}"
    }
  ]
}
{% endraw %}

raw标签会让Jekyll跳过这段内容的Markdown转换,避免生成<p>标签。

方法3:自定义布局并设置正确Content-Type

创建自定义空布局文件_layouts/json.raw,内容如下:

{{ content }}

然后在webfinger.md的前置配置中指定该布局,并添加content_type字段:

---
layout: json.raw
permalink: /.well-known/webfinger
content_type: application/json
---
{
  "subject": "acct:blah@blah.com",
  "aliases": [
    "https://blah.com/@blah",
    "https://blah.com/users/blah"
  ],
  "links": [
    {
      "rel": "http://webfinger.net/rel/profile-page",
      "type": "text/html",
      "href": "https://blah.com/@blah"
    },
    {
      "rel": "self",
      "type": "application/activity+json",
      "href": "https://blah.com/users/blah"
    },
    {
      "rel": "http://ostatus.org/schema/1.0/subscribe",
      "template": "https://mastodon.nz/authorize_interaction?uri={uri}"
    }
  ]
}

该方法不仅能避免<p>标签,还能将响应的Content-Type设置为application/json,完全符合WebFinger的规范要求。


内容的提问来源于stack exchange,提问作者Pablo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 12:35:17