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

add mastodon #7

Open
rdela opened this issue Jan 13, 2023 · 3 comments
Open

add mastodon #7

rdela opened this issue Jan 13, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@rdela
Copy link

rdela commented Jan 13, 2023

would love to see mastodon in here, any interest in adding it? if so, want me to ope a PR?

@rdela
Copy link
Author

rdela commented Jan 13, 2023

also fyi the link in this repo about, https://nickdiego.com/projects/social-sharing-block is a 404

@ndiego
Copy link
Owner

ndiego commented Jan 13, 2023

would love to see mastodon in here, any interest in adding it? if so, want me to open a PR?

Mastodon would be a great addition, but from my understanding, there is no uniform "share" link like there is for other social platforms. However, if you are aware of a way let me know, or feel free to open a PR.

also fyi the link in this repo about, https://nickdiego.com/projects/social-sharing-block is a 404

Thanks, I guess I never published the page 🤦‍♂️

@ndiego ndiego added the enhancement New feature or request label Jan 13, 2023
@rdela
Copy link
Author

rdela commented Jan 22, 2023

I investigated a bit and am not sure there is a JS-free way to do it cleanly yet. Perhaps something convoluted with contenteditable and CSS animations/transitions is possible but it already feels fiddly just typing that, and visitor would still have to fill in their server/instance domain. Here are two existing repos I found, they both use JS to construct the URL out of a server/instance input:

Also in the prior art world, The docs page for Jan Boddez's Share on Mastodon plugin (see also WP plugin page, janboddez/share-on-mastodon) has some filter code to append WordPress tags as hashtags in the Custom Formatting section:

add_filter( 'share_on_mastodon_status', function( $status, $post ) {
  $tags = get_the_tags( $post->ID );

  if ( $tags ) {
    $status .= "\n\n";
    
    foreach ( $tags as $tag ) {
      $status .= '#' . preg_replace( '/\s/', '', $tag->name ) . ' ';
    }

    $status = trim( $status );
  }

  return $status;
}, 11, 2 );

…Terence Eden shares a custom formatting code snippet for functions.php with an amalgamation of tags code above and some other customizations in Better sharing of WordPress posts to Mastodon:

add_filter( 'share_on_mastodon_status', function( $status, $post ) {
    //  Create a short preview of the post
    $status = "New blogging from me!\n\n";
    $status .= "\"" . get_the_title($post) . "\"\n\n";
    $status .= get_the_excerpt($post);
    //  Remove the … forced by the excerpt and replace with the Unicode symbol
    $status = html_entity_decode($status);
    //  Add a link
    $status .= "\n\nRead more: " . get_permalink( $post );
    //  Add tags
    $tags = get_the_tags( $post->ID );
    if ( $tags ) {
        $status .= "\n\n";
        foreach ( $tags as $tag ) {
            $status .= '#' . preg_replace( '/\s/', '', $tag->name ) . ' ';
        }
    }
    $status = trim( $status );
    return $status;
}, 10, 2 );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants