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

Convert hashtags to categories/tags when posting #50

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

toolstack
Copy link
Contributor

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.

Scan the body for anything that matches a category or tag name that starts with a hashtag.
Copy link
Owner

@akirk akirk left a comment

Choose a reason for hiding this comment

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

Thank you! I'd be cautious about looping over the categories and terms (what if there are many). 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().

@toolstack
Copy link
Contributor Author

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
Copy link
Owner

akirk commented Jan 10, 2024

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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 😁

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

Successfully merging this pull request may close these issues.

2 participants