@tryghost/portal

中文文档
2.72.15发布于 2026/11/03MITES Module构建来源已验证

Drop-in membership interface for Ghost sites

原始使用文档
文档目录7 节
  1. Usage
  2. Custom trigger button
  3. Develop
  4. Build
  5. Test
  6. Ghost e2e tests
  7. Release

Portal

npm version

Drop-in script to make the bulk of Ghost membership features work on any theme.

Usage

Ghost automatically injects the Portal script on all sites running Ghost 4 or higher.

Alternatively, Portal can be enabled on pages outside Ghost by adding this script:

<script defer src="https://unpkg.com/@tryghost/portal@latest/umd/portal.min.js" data-ghost="https://mymemberssite.com"></script>

The data-ghost attribute expects the URL for your Ghost site, which is the only input Portal needs to work with your site's membership data via Ghost APIs.

Custom trigger button

By default, the script adds a default floating trigger button on the bottom right of your page which is used to trigger the popup on screen.

You can add a custom trigger by adding the data-portal attribute to any HTML element. Set its value to choose a specific Portal page, for example data-portal="signup".

Share modal can be opened with data-portal="share" (or #/share).

Default (zero-config) usage:

<button type="button" data-portal="share">Share</button>

On pages where {{ghost_head}} is rendered, Portal will auto-resolve metadata from DOM tags:

  • URL: canonical URL (or current URL fallback)
  • Title: Open Graph title (or document title fallback)
  • Image: Open Graph image (or Twitter image fallback)

Troubleshooting missing preview metadata:

  1. Verify the template includes {{ghost_head}}.
  2. Verify rendered HTML contains canonical + OG/Twitter tags.

The script adds gh-portal-open and gh-portal-close classes to custom triggers to reflect the popup state.

See the Portal settings documentation for ways to customize Portal for your site.

Develop

Run Portal's build watcher with the other public apps from the monorepo root:

pnpm dev:public

Portal rebuilds as you edit and is served at http://localhost:2368/ghost/assets/portal/portal.min.js, which theme pages on the development site load. pnpm dev serves the build from when it started.

Build

From this directory, create a production minified bundle in umd/portal.min.js with:

pnpm build

Test

From this directory, run unit tests once or in watch mode with:

pnpm test
pnpm test:watch

Ghost e2e tests

Portal is primarily tested through Ghost's Playwright tests in the e2e/ directory. Run them from the monorepo root:

pnpm test:e2e

Release

Patch releases are automatic. When Portal changes on main, CI publishes the next patch version to npm and clears the jsDelivr cache. Sites using that major/minor line receive the patch without a Ghost release.

If you're releasing new code that should not immediately go live always use a minor or major version when publishing.

For an intentional minor or major release:

  1. From a clean branch, run pnpm ship and select a minor or major version
  2. Merge the release commit to main
  3. Wait for a public Ghost release to ship the new default version line

pnpm ship updates both the package version and Ghost's default Portal version.

Copyright & License

Copyright (c) 2013-2026 Ghost Foundation - Released under the MIT license.

版本与发布记录

@tryghost/portal 共发布 1,162 个版本,首次发布于 2020/09/24;过去 12 个月发布了 855 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.72.15latest2026/11/03今天
2.72.142026/11/03今天
2.72.132026/11/03今天
2.72.122026/10/312 天前
2.72.112026/10/285 天前
2.72.102026/10/286 天前

其他发布通道:2.14.0 → 2.14.0,2.15.0 → 2.16.0,2.17.0 → 2.18.0,2.19.0 → 2.19.0,2.19.1 → 2.19.2,2.19.2 → 2.19.3。

关于 @tryghost/portal 的常见问题

@tryghost/portal 是什么?

幽灵网站的直接会员界面

如何安装 @tryghost/portal?

在项目目录运行 npm install @tryghost/portal,或使用 pnpm add / yarn add / bun add。

@tryghost/portal 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/tryghost__portal 是否存在。

@tryghost/portal 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@tryghost/portal 可以商用吗?

@tryghost/portal 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@tryghost/portal 还在维护吗?

最新版本 2.72.15 发布于 2026/11/03(今天);至今共发布 1162 个版本,其中过去 12 个月发布了 855 个;首次发布于 2020/09/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。