{"id":14990154,"url":"https://github.com/daviddarnes/mastodon-post","last_synced_at":"2025-07-04T21:35:23.978Z","repository":{"id":223285521,"uuid":"759207711","full_name":"daviddarnes/mastodon-post","owner":"daviddarnes","description":"A Web Component to display Mastodon posts and their metadata","archived":false,"fork":false,"pushed_at":"2024-04-22T09:30:57.000Z","size":43,"stargazers_count":37,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-13T07:06:03.055Z","etag":null,"topics":["component","components","customelement","customelements","webcomponent","webcomponents"],"latest_commit_sha":null,"homepage":"https://daviddarnes.github.io/mastodon-post/demo.html","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/daviddarnes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"buy_me_a_coffee":"daviddarnes"}},"created_at":"2024-02-18T00:01:44.000Z","updated_at":"2025-05-21T16:56:20.000Z","dependencies_parsed_at":"2024-04-12T15:46:55.577Z","dependency_job_id":"ea325ce8-a6d4-40eb-b772-f74d2607815b","html_url":"https://github.com/daviddarnes/mastodon-post","commit_stats":null,"previous_names":["daviddarnes/mastodon-post"],"tags_count":6,"template":false,"template_full_name":"daviddarnes/component-template","purl":"pkg:github/daviddarnes/mastodon-post","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daviddarnes%2Fmastodon-post","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daviddarnes%2Fmastodon-post/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daviddarnes%2Fmastodon-post/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daviddarnes%2Fmastodon-post/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daviddarnes","download_url":"https://codeload.github.com/daviddarnes/mastodon-post/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daviddarnes%2Fmastodon-post/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263624644,"owners_count":23490525,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["component","components","customelement","customelements","webcomponent","webcomponents"],"created_at":"2024-09-24T14:19:35.430Z","updated_at":"2025-07-04T21:35:23.932Z","avatar_url":"https://github.com/daviddarnes.png","language":"HTML","readme":"# `mastodon-post`\n\nA Web Component to display Mastodon posts and their metadata.\n\n**[Demo](https://daviddarnes.github.io/mastodon-post/demo.html)** | **[Custom template demo](https://daviddarnes.github.io/mastodon-post/demo-custom-template.html)** | **[Further reading](https://darn.es/mastodon-post-web-component/)**\n\n## Examples\n\nGeneral usage example:\n\n```html\n\u003cscript type=\"module\" src=\"mastodon-post.js\"\u003e\u003c/script\u003e\n\n\u003cmastodon-post\u003e\n  \u003ca href=\"https://mastodon.design/@DavidDarnes/109824258017750161\"\u003e\n    Discuss on Mastodon\n  \u003c/a\u003e\n\u003c/mastodon-post\u003e\n```\n\nExample using a custom template:\n\n```html\n\u003cscript type=\"module\" src=\"mastodon-post.js\"\u003e\u003c/script\u003e\n\n\u003ctemplate id=\"mastodon-post-template\"\u003e\n  \u003cblockquote data-key=\"content\"\u003e\u003c/blockquote\u003e\n\u003c/template\u003e\n\n\u003cmastodon-post\u003e\n  \u003ca href=\"https://mastodon.design/@DavidDarnes/109824258017750161\"\u003e\n    Discuss on Mastodon\n  \u003c/a\u003e\n\u003c/mastodon-post\u003e\n```\n\nExample using a more complex custom template:\n\n```html\n\u003cscript type=\"module\" src=\"mastodon-post.js\"\u003e\u003c/script\u003e\n\n\u003ctemplate id=\"mastodon-post-template\"\u003e\n  \u003cdl\u003e\n    \u003cdt\u003eReposts\u003c/dt\u003e\n    \u003cdd data-key=\"reblogs_count\"\u003e\u003c/dd\u003e\n    \u003cdt\u003eReplies\u003c/dt\u003e\n    \u003cdd data-key=\"replies_count\"\u003e\u003c/dd\u003e\n    \u003cdt\u003eFavourites\u003c/dt\u003e\n    \u003cdd data-key=\"favourites_count\"\u003e\u003c/dd\u003e\n  \u003c/dl\u003e\n  \u003ca data-key=\"url\"\u003e\n    View original post from \u003cimg alt=\"avatar\" data-key=\"account.avatar\" /\u003e\n    \u003cstrong data-key=\"account.display_name\"\u003e\u003c/strong\u003e on\n    \u003cstrong data-key=\"hostname\"\u003e\u003c/strong\u003e\n  \u003c/a\u003e\n\u003c/template\u003e\n\n\u003cmastodon-post\u003e\n  \u003ca href=\"https://mastodon.design/@DavidDarnes/109824258017750161\"\u003e\n    Discuss on Mastodon\n  \u003c/a\u003e\n\u003c/mastodon-post\u003e\n```\n\n## Features\n\nThis Web Component allows you to:\n\n- Turn a regular Mastodon post link into a quoted Mastodon post\n- Surface the post metadata alongside the post, e.g. reply count, reblog count, favourite count\n- Use a custom template for all instances of the component on the page using a `data-key=\"name\"` data attributes\n- Use a custom template for specific instances using the `template` attribute\n- Retrieve nested data using the `data-key` attribute and typical JavaScript key referencing, e.g. `data-key=\"account.display_name\"` or `data-key=\"media_attachments[0]preview_url\"`\n\n## Installation\n\nYou have a few options (choose one of these):\n\n1. Install via [npm](https://www.npmjs.com/package/@daviddarnes/mastodon-post): `npm install @daviddarnes/mastodon-post`\n1. [Download the source manually from GitHub](https://github.com/daviddarnes/mastodon-post/releases) into your project.\n1. Skip this step and use the script directly via a 3rd party CDN (not recommended for production use)\n\n### Usage\n\nMake sure you include the `\u003cscript\u003e` in your project (choose one of these):\n\n```html\n\u003c!-- Host yourself --\u003e\n\u003cscript type=\"module\" src=\"mastodon-post.js\"\u003e\u003c/script\u003e\n```\n\n```html\n\u003c!-- 3rd party CDN, not recommended for production use --\u003e\n\u003cscript\n  type=\"module\"\n  src=\"https://www.unpkg.com/@daviddarnes/mastodon-post@1.3.0/mastodon-post.js\"\n\u003e\u003c/script\u003e\n```\n\n```html\n\u003c!-- 3rd party CDN, not recommended for production use --\u003e\n\u003cscript\n  type=\"module\"\n  src=\"https://esm.sh/@daviddarnes/mastodon-post@1.3.0\"\n\u003e\u003c/script\u003e\n```\n\n### Using a custom template\n\nThe default template for the component looks like this:\n\n```html\n\u003cfigure\u003e\n  \u003cblockquote data-key=\"content\"\u003e\u003c/blockquote\u003e\n  \u003cfigcaption\u003e\n    \u003ccite\u003e\n      \u003ca data-key=\"url\"\u003e\n        \u003cspan data-key=\"username\"\u003e\u003c/span\u003e\n        @\n        \u003cspan data-key=\"hostname\"\u003e\u003c/span\u003e\n      \u003c/a\u003e\n    \u003c/cite\u003e\n    \u003cdl\u003e\n      \u003cdt\u003eReposts\u003c/dt\u003e\n      \u003cdd data-key=\"reblogs_count\"\u003e\u003c/dd\u003e\n      \u003cdt\u003eReplies\u003c/dt\u003e\n      \u003cdd data-key=\"replies_count\"\u003e\u003c/dd\u003e\n      \u003cdt\u003eFavourites\u003c/dt\u003e\n      \u003cdd data-key=\"favourites_count\"\u003e\u003c/dd\u003e\n    \u003c/dl\u003e\n  \u003c/figcaption\u003e\n\u003c/figure\u003e\n```\n\nHowever you can customise the template by using a `\u003ctemplate\u003e` element with an `id` of `mastodon-post-template`, which will be used for every instance of the component on the page. Here's an example which just exposes the vanity metrics of the Mastodon post as a `\u003cdl\u003e`:\n\n```html\n\u003ctemplate id=\"mastodon-post-template\"\u003e\n  \u003cdl\u003e\n    \u003cdt\u003eReposts\u003c/dt\u003e\n    \u003cdd data-key=\"reblogs_count\"\u003e\u003c/dd\u003e\n    \u003cdt\u003eReplies\u003c/dt\u003e\n    \u003cdd data-key=\"replies_count\"\u003e\u003c/dd\u003e\n    \u003cdt\u003eFavourites\u003c/dt\u003e\n    \u003cdd data-key=\"favourites_count\"\u003e\u003c/dd\u003e\n  \u003c/dl\u003e\n\u003c/template\u003e\n```\n\nYou can also use different templates on the same page by using the `template` attribute to target `\u003ctemplate\u003e` elements with a specific `id`:\n\n```html\n\u003ctemplate id=\"custom-template\"\u003e\n  \u003ca data-key=\"content, url\"\u003e\u003c/a\u003e\n\u003c/template\u003e\n\n\u003cmastodon-post template=\"custom-template\"\u003e\n  \u003ca href=\"https://mastodon.design/@DavidDarnes/109824258017750161\"\u003e\n    Discuss on Mastodon\n  \u003c/a\u003e\n\u003c/mastodon-post\u003e\n```\n\nData is applied using a `data-key` data attribute. The value of this attribute should correspond to a data point within a [Mastodon public status API response](https://docs.joinmastodon.org/methods/statuses/). The official Mastodon documentation has [an example of a status response here](https://docs.joinmastodon.org/methods/statuses/#200-ok-1). The `data-key` attribute also allows you to target nested data using typical JavaScript dot notation:\n\n```html\n\u003ctemplate id=\"mastodon-post-template\"\u003e\n  \u003cfigure\u003e\n    \u003cblockquote data-key=\"content\"\u003e\u003c/blockquote\u003e\n    \u003cfigcaption\u003e\n      \u003ccite\u003e\n        \u003ca data-key=\"url\"\u003e\n          View original post from\n          \u003cimg alt=\"avatar\" data-key=\"account.avatar\" /\u003e\n          \u003cstrong data-key=\"account.display_name\"\u003e\u003c/strong\u003e on\n          \u003cstrong data-key=\"hostname\"\u003e\u003c/strong\u003e\n        \u003c/a\u003e\n      \u003c/cite\u003e\n    \u003c/figcaption\u003e\n  \u003c/figure\u003e\n\u003c/template\u003e\n```\n\n_Note that for `\u003ca\u003e` and `\u003cimg\u003e` elements the value won't be applied to it's content if the string being returned starts with `http` and instead will be applied to the `href` and `src` attributes respectively._\n\nCheck out the [custom template demo](https://daviddarnes.github.io/mastodon-post/demo-custom-template.html) as well as [the source code](https://github.com/daviddarnes/mastodon-post/blob/main/demo-custom-template.html) for reference.\n\n## Credit\n\nWith thanks to the following people:\n\n- [Zach Leatherman](https://zachleat.com) for inspiring this [Web Component repo template](https://github.com/daviddarnes/component-template)\n","funding_links":["https://buymeacoffee.com/daviddarnes"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaviddarnes%2Fmastodon-post","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaviddarnes%2Fmastodon-post","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaviddarnes%2Fmastodon-post/lists"}