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 support for arbitrary post-rewriting middleware #24

Open
jamietanna opened this issue Nov 15, 2021 · 4 comments
Open

Add support for arbitrary post-rewriting middleware #24

jamietanna opened this issue Nov 15, 2021 · 4 comments

Comments

@jamietanna
Copy link
Contributor

Currently, I have two main usecases in which my Micropub endpoint modifies the incoming request before saving it, which the latter of which would be quite key for me to move over:

  • Rewrite a twitter profile URL as an h-card:

          "Have you asked https://twitter.com/jamietanna?",
          "Have you asked <span class=\"h-card\"><a class=\"u-url\" href=\"https://twitter.com/jamietanna\">@jamietanna</a></span>?"),
    
  • Mark hashtags in the post as category properties in the post itself, with some custom rules:

    • i.e. #Java becomes java (just lowercase'd)
    • i.e. #SocialMedia becomes social-media (split words on capitalisation)
    • i.e. #IndieWeb becomes indieweb (custom rule)
    • i.e. #FOSDEM becomes fosdem (all caps get treated as one word)

(There are other cases, like "if I'm replying to Twitter, add a syndication link, but those are lower priority)

@barryf
Copy link
Owner

barryf commented Nov 18, 2021

My website marks up tweet handles and hashtags in text content via regexes in the view layer1. I think this sort of transformation should be the client's responsibility, not the server's. The server stores and serves text; the client renders the post how it wishes.

Footnotes

  1. https://github.com/barryf/barryfrost/blob/master/src/http/get-catchall/helpers.js#L35

@jamietanna
Copy link
Contributor Author

Interesting, so I'd spent a while thinking about which way I wanted to go with it, and I decided that having it done Micropub-side means that I could own my hashtags (I've been meaning to blog about it for a while) so when I'm at an event tweeting about #PHPMiNDS, I can easily go back to /tags/phpminds/, because although the hashtags are technically for the final syndicated content, it's useful for my site too

@barryf
Copy link
Owner

barryf commented Nov 18, 2021

I see. I've been a bit more specific about how I use categories/tags. I'll manually enter them in Micropublish when creating a note or other post types and then index them for lists, e.g. https://barryfrost.com/categories/indieweb

@jamietanna
Copy link
Contributor Author

If the hooks are available for extension, I'd be happy maintaining the code in my fork, then its not enforced for everyone? I'd be wanting to add Micropub CRUD for the different options too, so it longer term won't just be "do the rewrite"

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

No branches or pull requests

2 participants