跳到正文
Skillpedia
网站与界面(前端)8.1k · #12580

wb-preview-url-modifier

它能做什么

这项技能演示你的 AI 如何为 Webiny Website Builder 页面的预览链接添加额外参数。适合需要让预览携带令牌、租户 ID 或标志的开发者。

适用场景

  • ✓当预览链接必须包含已签名的令牌或租户标识符的时候。
  • ✓当你希望把功能开关的值传递给实时预览 URL 的时候。
  • ✓当预览链接在打开之前需要从另一项服务获取数据的时候。

技能链接

https://github.com/webiny/webiny-js/blob/next/skills/user-skills/admin/website-builder/wb-preview-url-modifier/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/webiny/webiny-js/blob/next/skills/user-skills/admin/website-builder/wb-preview-url-modifier/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请让每个 Website Builder 预览链接都包含一个从我们预览服务获取的已签名令牌。”

每周 5 个新技能,1 分钟读完。

工作原理

技能讲解如何编写一个小类,在预览地址打开之前修改它,然后在项目中注册该类。需要时,这个类可以等待远程的值。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Website Builder: Preview URL Modifier

TL;DR

PreviewUrlModifier is a DI extension point that lets project developers inject custom query parameters into all Website Builder live preview URLs. Register one implementation; it receives the full URL object and can mutate it however it needs — including async operations like fetching a signed token from a remote API.

Implement the Modifier

Import from webiny/admin/website-builder. The single required method is modify(url: URL): Promise<void> — mutate url.searchParams in place, mark the method async when you need to fetch remote values.

import { PreviewUrlModifier } from "webiny/admin/website-builder";

class MyPreviewUrlModifier implements PreviewUrlModifier.Interface {
  async modify(url: URL) {
    url.searchParams.set("my-param", "my-value");
  }
}

export default PreviewUrlModifier.createImplementation({
  implementation: MyPreviewUrlModifier,
  dependencies: []
});

Async example — fetching a signed token:

class SignedTokenModifier implements PreviewUrlModifier.Interface {
  async modify(url: URL) {
    const token = await fetch("/api/preview-token").then(r => r.text());
    url.searchParams.set("token", token);
  }
}

export default PreviewUrlModifier.createImplementation({
  implementation: SignedTokenModifier,
  dependencies: []
});

Register the Feature

// extensions/previewUrlModifier/index.tsx
import React from "react";
import { createFeature, RegisterFeature } from "webiny/admin";
import MyPreviewUrlModifier from "./MyPreviewUrlModifier.js";

const PreviewUrlModifierFeature = createFeature({
  name: "MyApp/PreviewUrlModifier",
  register(container) {
    container.register(MyPreviewUrlModifier);
  }
});

export default () => <RegisterFeature feature={PreviewUrlModifierFeature} />;
// webiny.config.tsx
<Admin.Extension src={"@/extensions/previewUrlModifier/index.tsx"} />

Where It Applies

Surface Description
Editor iframe The live-editing iframe in the page editor
Address bar link The "copy preview link" button in the editor toolbar
Pages list Preview icon links in the pages list table

Constraints

  • One modifier per project. Only the first registered implementation is used.
  • Mutate in place. Return value is ignored; mutate the URL object directly.
  • No wb.* collisions. Params prefixed wb. are reserved for internal use.

Related Skills

  • wb-custom-page-types -- registering custom page types via PageType abstraction
  • wb-page-settings -- extending page settings groups and fields
常见问题

这项改动可以依赖远程数据吗?

可以。修改器可以是异步的,例如从 API 获取已签名的令牌。

它在哪里注册?

它通过一个功能接入,并添加到项目的 webiny 配置文件中。

它会改变已发布的网站吗?

不会。技能只涉及实时预览链接,不涉及已发布的网站。

详情

作者的原始描述

Covers the PreviewUrlModifier extension point in Website Builder. Use when a user wants to inject custom query parameters into live preview URLs — e.g. signed tokens, tenant identifiers, feature flags — from their Webiny project. Handles the full registration pattern: implementing the interface, wiring via createFeature + RegisterFeature, and registering via webiny.config.tsx. Supports async modifier methods (e.g. remote token fetch).

repo: webiny/webiny-js

热度

GitHub 星标
8.1k
排名
#12580
许可证
—
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能