reuixiy / hugo-theme-meme

😝 You can’t spell awesome without MemE!
https://io-oi.me/hugo-theme-meme
MIT License
1.01k stars 279 forks source link

feat: add new shareOnMastodon and shareOnFediverse option #445

Closed palant closed 11 months ago

palant commented 11 months ago

It has been a while since I touched the theme, so I might have missed something @reuixiy.

This adds a “Share on Mastodon” button. That’s somewhat less trivial than usual because a Mastodon instance needs to be selected, requiring an intermediate page. The page I created is heavily inspired by Share₂Fedi but doesn’t require server-side support. Also, parameters are passed via location.hash rather than the query string, meaning that they won’t be visible in server logs (privacy).

There is a request to api.fediverse.observer to populate the list of suggested instances. This request is happening at build time which a) might slow down the build process and b) might get outdated if the site is rarely updated. Nevertheless, I consider this solution better than a client-side request. Fediverse Observer doesn’t allow filtering the list other than by status, meaning that users would have to download 8 MB of data. With the filtering done by Hugo, it’s only 600 instances left (around 30 kB). Hugo can also be configured to cache this request so that it won’t be repeated unnecessarily.

Passing a parameter to head.html partial via .Scratch is very ugly but this was the only solution I could see in the short term.

Metadata of the share page seems mostly fine, thanks to the index page being passed as context. If anything, a better page title would be an option.

palant commented 11 months ago

I now added shareOnMastodonFetchInstances option to explicitly enable that request to download instances. By default, no request will happen and the list will simply stay empty. I added it to the English example configuration, you will need to add to Chinese configurations yourself.

reuixiy commented 11 months ago

I love fediverse! Can you provide an additional screencast of this feature to help me review?

palant commented 11 months ago

This is the icon:

Share on Mastodon icon

And this is the page that opens when it is clicked:

Share on Mastodon form

Here I clicked “Remember instance” before and it saved my Mastodon instance. Otherwise it wouldn’t be checked by default.

I just realized that I don’t remember where I got this Mastodon icon from (it has been used on my site for years). I’ll check that.

palant commented 11 months ago

Oh, and here is what it looks like after clicking “Continue to Mastodon”:

Mastodon publish form with text pre-filled

palant commented 11 months ago

Added one one commit. I didn’t realize that the other share icons have a hover effect, added it for the Mastodon icon as well.

palant commented 11 months ago

I just realized that I don’t remember where I got this Mastodon icon from (it has been used on my site for years). I’ll check that.

It’s Font Awesome, just like all the other icons. So it’s all fine here.

palant commented 11 months ago

I am somewhat undecided as to where to go from here. My original intent was adding more share icons for other Fediverse apps like KBin or Lemmy in subsequent pull requests. However, there are simply too many if you look at the projects supported by Share₂Fedi.

Now it is possible to have a universal share form. It would determine the kind of software running on the instance and create the appropriate link. It would make sense. Except: what should be the icon then?

There are icons for Fediverse and ActivityPub. These aren’t exactly well-known however.

I think that the best course of action would be adding both Mastodon and Fediverse icons, doing exactly the same thing. If you agree, I’ll change this pull request accordingly.

palant commented 11 months ago

Ok, I’ve implemented this as a generic “Share on Fediverse” now. Notes:

What it looks like. Share icons:

Share icons including Mastodon and Fediverse icons, the latter being active

The share form, this time without a saved instance:

Form titled Share on Mastodon, Fediverse instance field active

Next step on Mastodon:

A pre-filled Mastodon post form

Next step on KBin:

A pre-filled KBin post form

Next step on Hubzilla:

A pre-filled Hubzilla post form

Next step on Friendica:

A pre-filled Friendica post form

palant commented 11 months ago

All fixed: