A custom element (a.k.a. web component) to display the latest notes from a Ghost blog's ActivityPub feed.
- Zero dependencies - pure vanilla JavaScript web component
- Displays profile header with name, username, image, and summary
- Shows the latest 10 notes from the ActivityPub feed; like the Posts tab in Ghost's social web, replies and reposts are left out
- Renders note content and attached images: one, or up to four in a grid, with their alt text
- Full screen image viewer: shows the alt text, moves between a post's images with the arrow keys, the on-screen arrows or a swipe
- Formats and displays post dates
- Handles errors gracefully
- Customizable with CSS
More details: https://muratcorlu.com/adding-ghost-social-web-notes-to-your-website-2/
Import the component to your Ghost page (by Ghost's code injection or your template):
<script src="https://cdn.jsdelivr.net/npm/@synapsmedia/ghost-activitypub-embed@latest/ghap-embed.min.js"></script>
And use it by adding component to wherever you want to show the feed:
<ghost-activitypub-embed></ghost-activitypub-embed>
You can use a Ghost HTNL Card to embed the component or edit your theme directly.
url- The base URL of your Ghost blog with ActivityPub enabled. By default it's the domain of your current page.include-posts- Include posts in the feed (defaultfalse)proxy- Proxy URL to fetch the feed data through (optional)site-links- Show a link to the profile's website, and a Subscribe button when the Ghost site takes sign-ups (opens its Portal sign-up) (defaultfalse)handle- The profile's handle, like@john@onolan.org, when it's on another domain than the site (Ghost's custom social web domains). By default the handle is shown on the site's domainprofile-url- Where the post author's avatar, name and handle link to, like the profile's page. By default they aren't links (optional)post- Show a single post under the profile header, not the feed. An ActivityPub object path likenote/<id>orarticle/<id>, or the object's full URL (optional)
parent- Withpost, the post it replies to, shown above it with a thread line:{ object, author, handle, link }.objectis the parent's ActivityPub object (nullwhen it couldn't be loaded),authorits actor (ornull),handlethe author's handle when known (e.g.john@onolan.org), andlinkwhere the parent opens. The component doesn't fetch it: parents are often on other servers (e.g. Mastodon) that need a server to fetch them. Set it before adding the element to the page.
Post and profile HTML from the fetched objects is sanitized: only text formatting and http(s) links are kept.
after-header- Content placed under the profile header, above the posts. For example tabs; hide the posts withghost-activitypub-embed::part(feed-item) { display: none; }while another tab is open.
This component is isolated from theme styles. That means it will work in any theme. You can customize the component using CSS variables and using CSS part() selector.
--ghap-background-color- The background color of the feed container (default#fff)--ghap-text-color- The text color of the feed container (default#000)--ghap-padding- The padding of the feed container (default1rem)--ghap-border-color- The border color of the feed container (defaultrgb(229, 233, 235))--ghap-feed-item-icon-size- The size of the feed item icon (default40px)--ghap-feed-vertical-gap- The vertical gap between feed items (default1rem)--ghap-font-family- The font family of the feed container (default, Ghost's body font)--ghap-font-size- The font size of the feed container (default10px)--ghap-border-radius- The border radius of the feed container (default10px)--ghap-border-width- The border width of the feed container (default1px)--ghap-highlight-color- The background of a single post shown under the post it replies to (defaultrgb(239, 246, 255))--ghap-thread-parent-icon-size- The avatar size of the post replied to (default32px)--ghap-thread-main-icon-size- The avatar size of a single post shown under the post it replies to (default48px)
You can set CSS variables with code injection or in your theme's CSS file.
<style>
ghost-activitypub-embed {
--ghap-background-color: #f0f0f0;
--ghap-text-color: #333;
--ghap-padding: 1rem;
--ghap-border-color: #ccc;
--ghap-feed-item-icon-size: 40px;
--ghap-feed-vertical-gap: 1rem;
--ghap-font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'avenir next', avenir, 'helvetica neue', helvetica, ubuntu, roboto, noto, 'segoe ui', arial, sans-serif;
--ghap-font-size: 10px;
--ghap-border-radius: 10px;
--ghap-border-width: 1px;
}
</style>
You can use a proxy to fetch the feed data. This is useful if you want to run this component on a different domain.
<ghost-activitypub-embed url="https://your-ghost-blog.com" proxy="https://your-proxy.com"></ghost-activitypub-embed>
Proxy server should accept requests starting with /.ghost/activitypub/ and read x-proxy header to get the original URL. Then should make the same request to the original URL and return the response.
container- The feed containerheader- The profile headerfeed-item- The feed itemfeed-item-content- The feed item contentfeed-author- The feed authorfeed-author-avatar- The feed author avatarfeed-item-images- A post's attached images
Examples of using CSS parts:
Remove border from feed container:
<style>
ghost-activitypub-embed::part(container) {
border: none;
}
</style>
Hide profile header:
<style>
ghost-activitypub-embed::part(header) {
display: none;
}
</style>
Hide avatar column:
<style>
ghost-activitypub-embed::part(feed-author-avatar) {
display: none;
}
ghost-activitypub-embed::part(feed-item-content) {
padding-left: 0;
}
</style>
- The Ghost blog must have ActivityPub integration enabled and configured
Clone the repository and install dependencies:
git clone https://github.com/YOUR_USERNAME/ghost-activitypub-embed.git
cd ghost-activitypub-embed
npm install
Start the development server:
npm run dev
You can check your changes on http://localhost:8000
Contributions are welcome! Please feel free to submit a Pull Request.
MIT