skinofthesoul / grav-plugin-antispam

Automatic email address obfuscation for Grav pages.
MIT License
9 stars 3 forks source link

onPageContentRaw/onPageContentProcessed vs. onOutputGenerated #18

Closed pamtbaau closed 3 years ago

pamtbaau commented 3 years ago

What is the rationale for running the obfusculation during onOutputGenerated? This event runs on every page request, which seems unnecessary to me.

Events onPageContentRaw (before processing Markdown) and onPageContentProcessed (after Markdown) only runs once when page has not yet been cached, or cache has been invalidated. Any reason why the obfusculation shouldn't run during one of these events?

skinofthesoul commented 3 years ago

Excellent input yet again, thank you! To be honest, this was my very first Grav plugin, and I may have found this hook in some other plugin, tried it and found that it worked. In any case I didn't really know what I was doing (I still don't in many cases, but I'm getting there). The way you put it, using onPageContentProcessed seems the best idea to me. I shall try that. :-)

skinofthesoul commented 3 years ago

Aaaaand done :-)

pamtbaau commented 3 years ago

And tested for cached and non-cached circumstances?

skinofthesoul commented 3 years ago

Heh, ah, you got me there! Of course this needs a recaching for all the pages with email addresses. Hmmmmm… how could I trigger a cache rebuild on plugin update? This is tricky?!

pamtbaau commented 3 years ago

Doesn't upgrading a plugin/theme using GPM automatically delete cache? Not, sure, you might want to test that.

skinofthesoul commented 3 years ago

Hmmmm I don't think it does, I did a quick check. :-\

I could keep the code for onOutputGenerated, it shouldn't do anything if the addresses have been munged already… and then delete it in a later update… pppphhhhhh I think I'll do that.

pamtbaau commented 3 years ago

I tried the following:

But please only trust your own situation.

skinofthesoul commented 3 years ago

Hmmm, like I said I only did a quick check, and at least the image cache does not get rebuilt apparently. How do you check for a cache clear? I'd really like this solution, mine is messy!

pamtbaau commented 3 years ago

How do you check for a cache clear?

When running $ bin/gpm update the command will tell you so:

$ bin/gpm update

GPM Releases Configuration: Stable
Found 13 packages installed of which 1 need updating
01. Antispam        [v1.4 -> v1.5]

 Continue with the update process? [Y|n]  (yes/no) [yes]:
 >
GPM Releases Configuration: Stable

Preparing to install Antispam [v1.5]
  |- Downloading package...   100%
  |- Checking destination...  ok
  |- Installing package...    ok
  '- Success!

Clearing cache
Cleared:  /www/grav/site-dev/cache/twig/*
Cleared:  /www/grav/site-dev/cache/doctrine/*
Cleared:  /www/grav/site-dev/cache/compiled/*
Touched: /www/grav/site-dev/user/config/system.yaml
$
skinofthesoul commented 3 years ago

Oh, that's sweet! Thanks for telling me. You seem to be right as well, I uninstalled and reinstalled the plugin on several projects and all went very smoothly, I'm just having the oddest issue with one email address that gets eaten, somehow. But this is likely a different bug, which I will look into after going outside and clearing my head for a bit. The plugin update seems fine, so thanks again!