Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mastodon support #307

Merged
merged 17 commits into from
Feb 18, 2025
Merged

Mastodon support #307

merged 17 commits into from
Feb 18, 2025

Conversation

gfscott
Copy link
Owner

@gfscott gfscott commented Feb 5, 2025

Closes #210

This PR adds support for embedding Mastodon posts. Some things to know:

  • Since there are many Mastodon servers out there, you'll need to configure which Mastodon instance you use in order to recognize and embed its URLs. Choose the server that you log into to view your timeline. See the README for details.
  • The plugin needs to make up to two API calls per embedded post in order to fetch all the necessary data. This is unavoidable due to Mastodon's decentralized architecture. For large Eleventy sites, it's likely these network queries will add noticeably to build times.
  • Due to these performance limitations, the Mastodon plugin is not active by default when using it as part of eleventy-plugin-embed-everything. Here's how to activate it. (If you install eleventy-plugin-embed-mastodon on its own, however, it will be active by default.)

@gfscott gfscott self-assigned this Feb 5, 2025
Copy link

changeset-bot bot commented Feb 5, 2025

🦋 Changeset detected

Latest commit: 232ab37

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
eleventy-plugin-embed-mastodon Major
eleventy-plugin-embed-everything Minor
eleventy-plugin-embed-everything-demo Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@gfscott gfscott marked this pull request as ready for review February 16, 2025 17:57
Copy link

codecov bot commented Feb 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (d8d57bd) to head (232ab37).
Report is 18 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #307   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            7        10    +3     
  Lines          190       230   +40     
  Branches         0         7    +7     
=========================================
+ Hits           190       230   +40     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@gfscott gfscott changed the title [WIP] Mastodon support Mastodon support Feb 18, 2025
@gfscott gfscott requested a review from Copilot February 18, 2025 18:13
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 7 out of 22 changed files in this pull request and generated 1 comment.

Files not reviewed (15)
  • demo/package.json: Language not supported
  • package.json: Language not supported
  • packages/mastodon/package.json: Language not supported
  • packages/everything/.eleventy.js: Evaluated as low risk
  • demo/src/index.md: Evaluated as low risk
  • packages/everything/lib/pluginDefaults.js: Evaluated as low risk
  • demo/eleventy.config.js: Evaluated as low risk
  • packages/everything/test/test-validatePlugins.js: Evaluated as low risk
  • demo/src/mastodon.md: Evaluated as low risk
  • .changeset/lemon-bugs-cross.md: Evaluated as low risk
  • packages/mastodon/test/replace.test.mjs: Evaluated as low risk
  • packages/mastodon/test/_validStrings.mjs: Evaluated as low risk
  • packages/mastodon/test/_validUrls.mjs: Evaluated as low risk
  • packages/mastodon/lib/defaults.js: Evaluated as low risk
  • packages/mastodon/lib/pattern.js: Evaluated as low risk
Comments suppressed due to low confidence (3)

packages/mastodon/index.js:11

  • The error message should be more descriptive. Suggested change: '[eleventy-plugin-embed-mastodon] You need to configure a Mastodon server URL. Please set the 'server' option in the plugin configuration to the hostname of your Mastodon instance.'
throw new Error("[eleventy-plugin-embed-mastodon] You need to configure a Mastodon server URL");

packages/mastodon/lib/replace.js:47

  • [nitpick] The error message could be more descriptive by specifying which parameter is missing.
console.error("Missing Mastodon instance or status ID.");

packages/mastodon/lib/replace.js:74

  • [nitpick] The error message could be more descriptive by specifying which parameter is missing.
console.error("Missing hostname or URL.");

const federatedStatusQuery = `https://${hostname}/api/v1/statuses/${id}`;
try {
const {url} = await Fetch(federatedStatusQuery, {
duration: cacheDuration,
Copy link
Preview

Copilot AI Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no validation to ensure that cacheDuration is in the correct format, which could lead to runtime errors.

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Add TODOs to pattern file

Delete dead comment

Start scaffolding out replace functions

Basically works
Just some commentary

Fix broken test
Try/Catch, plus some error testing

Configure Vitest coverage

Config, throw better errors

Fix mocking, I think
Testing, console.error mocking, more reliable return values

Tests, more resilient to failure cases

More test coverage
Coverage: failing oembed case

Remove redundant return values
@gfscott gfscott merged commit 3481e22 into main Feb 18, 2025
14 checks passed
@gfscott gfscott deleted the mastodon branch February 18, 2025 19:13
@github-actions github-actions bot mentioned this pull request Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Embed Mastodon
1 participant