akirk / enable-mastodon-apps

Allow accessing your WordPress blog with Mastodon clients
https://wordpress.org/plugins/enable-mastodon-apps
GNU General Public License v2.0
34 stars 5 forks source link

Convert hashtags to categories/tags when posting #50

Open toolstack opened 8 months ago

toolstack commented 8 months ago

During a post submission, scan the body for anything that matches a category or tag name (case insensitively) that starts with a hashtag and add that to the new post_data array.

toolstack commented 8 months ago

Thank you! I'd be cautious about looping over the categories and terms (what if there are many).

As this is only done when submitting a post, the overhead hit seems like a reasonable compromise (see below for why). Even if there are a few hundred or thousand terms, that's not a lot of overhead.

What about using regex to extract the tags and then searching for them using the name parameter of get_terms() which is used in the background for get_categories() and get_tags().

Could, but a regex is more challenging as WP allows for terms that have spaces in them, so searching for terms as defined by WP is probably more desirable. Looping through the terms makes catching the tags with spaces easy as we know what we're looking for.

akirk commented 8 months ago

Could, but a regex is more challenging as WP allows for terms that have spaces in them, so searching for terms as defined by WP is probably more desirable. Looping through the terms makes catching the tags with spaces easy as we know what we're looking for.

Interesting, so in your opinion there should be support for specifying a category or tag like this #category with space in it vs. the slug notation like #category-with-space-in-it?

toolstack commented 8 months ago

Yes

Interesting, so in your opinion there should be support for specifying a category or tag like this #category with space in it vs. the slug notation like #category-with-space-in-it?

Yes, most users don't know what a slug is, so letting them simply type in "#category name I always see" makes more sense here I think.

toolstack commented 8 months ago

Yes, most users don't know what a slug is, so letting them simply type in "#category name I always see" makes more sense here I think.

In fact I think there might be an argument to check for three different kinds of tagging; "#this is a tag", "#this-is-a-tag", and "#thisisatag".

Aka, replacing spaces with dashes and removing spaces completely and searching for all three in the content.

I also think it might make sense to check the last line of the content and see if after tags, there's nothing left and if so, remove it.

Both are for future thought though 😁