Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Topic started by: Antes on July 27, 2020, 04:43:04 PM

Title: AMP4SMF
Post by: Antes on July 27, 2020, 04:43:04 PM
Link to the mod (https://custom.simplemachines.org/index.php?mod=4265)

Adds very basic AMP support for your SMF forum... Only supported structure is topics.

SMF2: v0.0.1 (same code as SMF 2.1 version just less hooks due to core-software limitations)
SMF2.1: v0.0.3

You can support me via Twitch Prime (https://www.twitch.tv/xinyenfon)* or Patreon (https://www.patreon.com/XinYenFon).

Changelog
v0.0.3 (SMF 2.1 version only)
- Img bbcode and Code bbcode disabled.
- Poll related code removed.
v0.0.2 (SMF 2.1 version only)
! Small code adapts & more hooks
v0.0.1
! First release
Title: Re: AMP4SMF
Post by: -Rock Lee- on July 27, 2020, 07:06:45 PM
I will test it to see how it works, even if it is basic it can fulfill its function well. I saw some advertising agencies implement it in some highly modified SMF but the performance worsened (I don't know why).


Regards!
Title: Re: AMP4SMF
Post by: diegolyanky on July 27, 2020, 07:55:17 PM

Didn't worked on 2 of my sites. SMF 2.0.17

Title: Re: AMP4SMF
Post by: Arantor on July 28, 2020, 08:29:23 AM
Quote from: diegolyanky on July 27, 2020, 07:55:17 PM

Didn't worked on 2 of my sites. SMF 2.0.17



How did it not work? Do you go to the doctor when you are unwell and just say "I'm ill", no, you provide details. Please do so here.
Title: Re: AMP4SMF
Post by: diegolyanky on July 28, 2020, 08:56:12 AM

haha... Sorry, you're right.

I installed without problem, all fine and no errors. When I tested the AMP under search console, said: NO AMP DETECTED.

That's all...

Maybe I am doing something wrong (IDK)

Thanks a lot for your quick reply
Title: Re: AMP4SMF
Post by: Antes on July 28, 2020, 10:53:11 AM
Quote from: diegolyanky on July 28, 2020, 08:56:12 AM

haha... Sorry, you're right.

I installed without problem, all fine and no errors. When I tested the AMP under search console, said: NO AMP DETECTED.

That's all...

Maybe I am doing something wrong (IDK)

Thanks a lot for your quick reply

There are few things;

The mod does not make your entire site AMP Valid. Its only for topics. When I try to validate a page in AMPValidator it fails but tells me that this page redirects to AMP version (weird that validator itself is not self-redirecting).

Once I tell the page that show me the redirected (AMP) results: https://search.google.com/test/amp?skip_amp_follow=true&id=APQM6j9Ket1IaCc4aCaiEA

To validate your page if it has valid AMP version... Navigate to the topic, check source file and you should see something like...

<link rel="amphtml" href="https://www.yoursite.tld/index.php?action=amp;topic=id">

if the code is there your page (SHOULD) be fine... as again we don't know how well the system works but according to their Docs, this is the way to redirect search engine (Google) to AMP page... If the following code does not exist in your page, either you didn't install the mod's edits to your custom theme or something else -which I don't know-.
Title: Re: AMP4SMF
Post by: -Rock Lee- on July 28, 2020, 02:47:03 PM
It works as it should although I thought it causes problems with the nice url, so far it works fine. But when there are citations or the code bbcode fails in the validation, not everywhere but in some specific points related to php (I have to do more tests). Left where that error marks me:

Quote<a href="" onclick="return smfSelectText(this);" class="codeoperation">[Select]</a></div><code class="bbc_code">SET xdate = %date: ~ -10,2%% date: ~ -7,2%% date: ~ -4,4%</code><br /><div class="codeheader">Código: (Windows) <a href="" onclick="return smfSelectText(this);" class="codeoperation">[Seleccionar]</a></div><code class="bbc_code">@echo on<br />

Try one 2.0.15 and two 2.0.17... In all of them something similar happens to me when I put [code][/code] with lines in php/bach/bash (I have to try more).


Regards!

ADD: Apparently the error occurs because the "onclick" attribute cannot appear in the "a" tag (it's an AMP rule from what I read). It's time to do a little more research! :P
Title: Re: AMP4SMF
Post by: marcosbr on July 28, 2020, 10:25:35 PM

I only have this error on topics with image from the RSS Feed Poster. (I use this mod)
AMP validator: "The tag 'img' may only appear as a descendant of tag 'noscript'. Did you mean 'amp-img'? Debug. Learn more..."


Remaining OK!
Title: Re: AMP4SMF
Post by: Antes on July 29, 2020, 02:37:26 AM
Quote from: Rock Lee on July 28, 2020, 02:47:03 PM
It works as it should although I thought it causes problems with the nice url, so far it works fine. But when there are citations or the code bbcode fails in the validation, not everywhere but in some specific points related to php (I have to do more tests). Left where that error marks me:

Quote<a href="" onclick="return smfSelectText(this);" class="codeoperation">[Select]</a></div><code class="bbc_code">SET xdate = %date: ~ -10,2%% date: ~ -7,2%% date: ~ -4,4%</code><br /><div class="codeheader">Código: (Windows) <a href="" onclick="return smfSelectText(this);" class="codeoperation">[Seleccionar]</a></div><code class="bbc_code">@echo on<br />

Try one 2.0.15 and two 2.0.17... In all of them something similar happens to me when I put [code][/code] with lines in php/bach/bash (I have to try more).


Regards!

ADD: Apparently the error occurs because the "onclick" attribute cannot appear in the "a" tag (it's an AMP rule from what I read). It's time to do a little more research! :P

Quote from: marcosbr on July 28, 2020, 10:25:35 PM

I only have this error on topics with image from the RSS Feed Poster. (I use this mod)
AMP validator: "The tag 'img' may only appear as a descendant of tag 'noscript'. Did you mean 'amp-img'? Debug. Learn more..."


Remaining OK!

That's expected... BBCodes are using different type of goodies to become alive and AMP by design is very limited system... The solution is not editing your post, please do not do that.
Title: Re: AMP4SMF
Post by: -Rock Lee- on July 29, 2020, 02:06:21 PM
I did not even think about editing topics for this error, I will look for another solution if it exists, although the impression that smf already brings cannot be used? Isn't it similar in the sense it has to be as simple as possible?

https://www.simplemachines.org/community/index.php?action=printpage;topic=574227.0 < It is even more direct than AMP or so it seems to me.


Regards!
Title: Re: AMP4SMF
Post by: Arantor on July 29, 2020, 02:19:14 PM
Yes but it doesn't use the magical markup that Google tells you to use, so it can better make money out of your content.
Title: Re: AMP4SMF
Post by: Antes on July 29, 2020, 02:26:02 PM
Quote from: Rock Lee on July 29, 2020, 02:06:21 PM
I did not even think about editing topics for this error, I will look for another solution if it exists, although the impression that smf already brings cannot be used? Isn't it similar in the sense it has to be as simple as possible?

https://www.simplemachines.org/community/index.php?action=printpage;topic=574227.0 < It is even more direct than AMP or so it seems to me.


Regards!

The system is built based on printpage to keep the simplicity, the reality is AMP is a horrid spawn of Google... The only reason I wrote this mod because a) it was relatively easy to do b) I had time. Solution to BBCode may not be simple, I need to make some research because I honestly think, someone shouldn't just hook-into parseBBC and replace BBCodes with other ones...

Another reality is... ResponsiveCurve is 100000000000000 (0 to infinity) better than AMP can ever be, because Responsive design does not limit your functionality UNLIKE this horrid spawn of Google... The mod will become obsolete, once Google says, "okay I' f'd up... this system is not working" -which is relatively soon- because we know that they are removing limitation of promoting sites (to upper story parts) to AMP.

Quote from: Arantor on July 29, 2020, 02:19:14 PM
Yes but it doesn't use the magical markup that Google tells you to use, so it can better make money out of your content.

also +1
Title: Re: AMP4SMF
Post by: -Rock Lee- on July 29, 2020, 03:54:42 PM
Quote from: Arantor on July 29, 2020, 02:19:14 PM
Yes but it doesn't use the magical markup that Google tells you to use, so it can better make money out of your content.

If it is something I notice and more in these times, I never thought to make a site profitable because I think it loses the sense of fun when editing something and becomes an obligation. Added you need 100000000 visits to win 1USD... There are better and easier ways to get money (that's what I think).

Quote from: Antes on July 29, 2020, 02:26:02 PM
The system is built based on printpage to keep the simplicity, the reality is AMP is a horrid spawn of Google... The only reason I wrote this mod because a) it was relatively easy to do b) I had time. Solution to BBCode may not be simple, I need to make some research because I honestly think, someone shouldn't just hook-into parseBBC and replace BBCodes with other ones...

Another reality is... ResponsiveCurve is 100000000000000 (0 to infinity) better than AMP can ever be, because Responsive design does not limit your functionality UNLIKE this horrid spawn of Google... The mod will become obsolete, once Google says, "okay I' f'd up... this system is not working" -which is relatively soon- because we know that they are removing limitation of promoting sites (to upper story parts) to AMP.

It is the truth that for a while they will use AMP and then change everything, after all they must generate their profit. To see how it works it is not badly, it does not add or subtract having it installed (in forum normal operation).


Regards!
Title: Re: AMP4SMF
Post by: Arantor on July 29, 2020, 03:58:43 PM
No, it's not about making *your* site profitable. It's about Google making money from you.
Title: Re: AMP4SMF
Post by: -Rock Lee- on July 29, 2020, 04:53:22 PM
Now that you mention it you are right and many want google to look at their websites, a perfect cycle.
Title: Re: AMP4SMF
Post by: AllMassive on August 10, 2020, 07:48:11 PM
Sorry, but:
What is AMP ?
Title: Re: AMP4SMF
Post by: efk on August 10, 2020, 08:53:13 PM
Quote from: AllMassive on August 10, 2020, 07:48:11 PM
Sorry, but:
What is AMP ?
Probably 99%+ members and guests will have exactly the same question. Even google fails to answer  :D
Edit: Got an idea what it could be since I saw many Amplifiers in google store in past, so it has to be Amplifier but still no clue for what since there is no info about mod.
Title: Re: AMP4SMF
Post by: -Rock Lee- on August 10, 2020, 08:55:06 PM
Quote from: AllMassive on August 10, 2020, 07:48:11 PM
Sorry, but:
What is AMP ?

This https://amp.dev/ :D or https://developers.google.com/amp


Regards!
Title: Re: AMP4SMF
Post by: Arantor on August 11, 2020, 05:32:16 AM
A way of making your site easier for Google to scrape and display content from without having to send users to you / a way of displaying ads better without all the other stuff on your site.
Title: Re: AMP4SMF
Post by: pocttopus on August 21, 2020, 01:18:47 PM
Does AMP stands for Accelerated Mobile Pages?
Title: Re: AMP4SMF
Post by: Antes on August 21, 2020, 02:52:32 PM
Yes
Title: Re: AMP4SMF
Post by: Xpresskonami on August 26, 2020, 11:41:27 PM
Quote from: Antes on August 21, 2020, 02:52:32 PM
Yes

Thanks for the mod. Is this working with pretty url and how can i get the link for it
Title: Re: AMP4SMF
Post by: Xpresskonami on August 26, 2020, 11:45:17 PM
Quote from: Antes on August 21, 2020, 02:52:32 PM


BBCODE image not working with the mod See demo here (http://spyloadedforum.cf/index.php?action=amp;topic=107)
Title: Re: AMP4SMF
Post by: Antes on August 27, 2020, 06:32:36 AM
https://www.simplemachines.org/community/index.php?topic=574227.msg4064199#msg4064199
Title: Re: AMP4SMF
Post by: -Rock Lee- on August 27, 2020, 08:03:07 PM
Quote from: Xpresskonami on August 26, 2020, 11:41:27 PM
Thanks for the mod. Is this working with pretty url and how can i get the link for it

I use it with the pretty urls without problems, just add at the end "?action=amp"


Regards!
Title: Re: AMP4SMF
Post by: Antes on August 28, 2020, 03:51:00 AM
You don't need any URLs, by default Google will detect the page without needing your support. Also if you are going to use that page for your users, don't... just get a Responsive Theme.
Title: Re: AMP4SMF
Post by: njtweb on September 02, 2020, 07:14:02 AM
I'eve read through and have a couple questions.

First, I see this is helpful for Google speed which is very helpful for adsense. That would be the only reason I'd want to leverage this mod. However I also read it strips image tags in mobile devices. Is this accurate? I need my users mobile experience to be the same as on a computer.

Thank you I look forward to your response.
Title: Re: AMP4SMF
Post by: Antes on September 02, 2020, 08:11:33 AM
Quote from: njtweb on September 02, 2020, 07:14:02 AM
I'eve read through and have a couple questions.

First, I see this is helpful for Google speed which is very helpful for adsense. That would be the only reason I'd want to leverage this mod. However I also read it strips image tags in mobile devices. Is this accurate? I need my users mobile experience to be the same as on a computer.

Thank you I look forward to your response.

That's not even remotely possible with AMP. AMP is just yet another pumped project from Google, the only reason this mod exist because people should leverage off of these cherries on the top. To have proper mobile experience you should get a properly designed Responsive Theme (or RCurve if you are on default theme).

To address the BBCode issue, Unfortunately I don't have much time to spend on SMF for now. I'd love to fix at least image issue in the mod and possibly disable rest of the BBCodes in that specific mod.
Title: Re: AMP4SMF
Post by: njtweb on September 02, 2020, 09:13:50 AM
Thank you, I do use default theme and responsive curve 1.1.0. I didn't update to 1.0.1 because you didn't think it was necessary, (I commented in your dcurve thread).
Title: Re: AMP4SMF
Post by: Antes on September 05, 2020, 11:26:45 AM
SMF 2.1 ONLY - v0.0.3 released, added a nice neat hook to disable some BBCodes. Backporting this may not happen due to lack of hooks... I'll try to work-around the hooks to ensure same code backported but no promises.
Title: Re: AMP4SMF
Post by: spiros on November 09, 2020, 01:50:27 PM
Amazing work, Antes, I see you did it for SMF 2 and I installed it. A strange thing, pages validate via https://validator.ampproject.org but when I access them with my Android phone (Chrome browser), I get "sorry this page is not valid amp html" and get redirected to the forum home page. When I try with any other browser, I see the amp page.

Example pages:
https://www.translatum.gr/forum/index.php?action=amp;topic=987010
https://www.translatum.gr/forum/index.php?action=amp;topic=985701.0
Title: Re: AMP4SMF
Post by: spiros on November 11, 2020, 03:31:36 PM
I got this reply:

QuoteLooking at the URL in the search result, it has a URL with parts of the query string escaped.

Original URL:
https://www.translatum.gr/forum/index.php?action=amp;topic=987010

URL in Search:
https://www.translatum.gr/forum/index.php?action=amp%3Btopic%3D985701

Using that escaped URL with both validator.amp.dev and the Chrome Extension it shows that the returned HTML is not valid AMP and is not declared as AMP.

There are two potential solutions for you, though this is outside of the scope of AMP itself.

Use & instead of ; for different query params.
Update the server for this domain to handle escaped query params for %3B (which is ;).
https://github.com/ampproject/amphtml/issues/31063

Not clear on either of these suggestions really...

This is what I can see in the way the page is linked in google search results:

<a class="C8nzq BmP5tf amp_r" data-amp="https://www.translatum.gr/forum/index.php?action=amp;topic%3D985701" data-amp-cur="https://www.translatum.gr/forum/index.php?action=amp;topic=985701" data-amp-title="translatum.gr" data-amp-vgi="8458557019360116853" href="https://www.translatum.gr/forum/index.php?action=amp;topic=985701" data-ved="2ahUKEwim8cXvrvvsAhXCMewKHYUJDfEQFjAAegQIARAB" ping="/url?sa=i&amp;source=web&amp;rct=j&amp;url=https://www.translatum.gr/forum/index.php%3Faction%3Damp%3Btopic%3D985701&amp;ved=2ahUKEwim8cXvrvvsAhXCMewKHYUJDfEQFjAAegQIARAB&amp;psig=AOvVaw3Zumwox_YowxhDDwIehV-e&amp;ust=1605214160452451&amp;ampcf=1"><div class="abuKkc IhfN8d MUxGbd lyLwlc aLF0Z"><img class="eqA2re" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAABnRSTlMAAAAAAABupgeRAAAAMklEQVR4AWMY5OD/TIb/aZgIl+o0XAinanSdBAGFGmbS0gZMLxGrgSirCAQrYT2DHwAAv0tHhsJpXPsAAAAASUVORK5CYII=" alt="Image" aria-hidden="true" data-atf="1" width="16" height="16"><span class="Zu0yb UGIkD qzEoUe">www.translatum.gr<span class="kbNtnf Jzkcjd"> › forum</span></span><span jsname="zYLzN" class="ZseVEf QzoJOb" aria-label="AMP logo"></span></div><h2 class="Uo8X3b">Web results</h2><div class="PpBGzd YcUVQe MUxGbd v0nnCb" aria-level="3" role="heading"><div class="V7Sr0 p5AXld PpBGzd YcUVQe">pre-owned -&gt; μεταχειρισμένος, δεύτερο χέρι, που είχε προηγούμενο ιδιοκτήτη, προϊδιόκτητος - Translatum</div></div></a>
Title: Re: AMP4SMF
Post by: Antes on November 12, 2020, 06:50:26 AM
I can't be sure what is causing this... Google redirects with "%3Btopic%3D985701" and either mod or server fails to redirect...
Title: Re: AMP4SMF
Post by: spiros on November 12, 2020, 07:07:02 AM
Well, apparently this does not occur on canonical URLs which have similar parameter separators. It could be a clue. For what it's worth, I tested it on 2 different sites (same server).

This is what I see when searching from Chrome desktop (https://www.google.com/search?q=pre-owned+translatum&oq=pre&aqs=chrome.1.69i57j35i39j46i457j0j46i199i291j69i61l3.2723j0j3&sourceid=chrome&ie=UTF-8), which, for some strange reason, only lists the AMP page, and happily directs to it when clicked.

<a href="https://www.translatum.gr/forum/index.php?action=amp;topic=985701" ping="/url?sa=t&amp;source=web&amp;rct=j&amp;url=https://www.translatum.gr/forum/index.php%3Faction%3Damp%3Btopic%3D985701&amp;ved=2ahUKEwji8ujg-vzsAhVBsKQKHY6VDrsQFjAAegQIAxAC"><br><h3 class="LC20lb DKV0Md"><span>pre-owned -&gt; %u03BC%u03B5%u03C4%u03B1%u03C7%u03B5%u03B9%u03C1%u03B9%u03C3%u03BC%u03AD%u03BD%u03BF%u03C2, %u03B4%u03B5%u03CD%u03C4%u03B5%u03C1%u03BF %u03C7%u03AD%u03C1%u03B9, %u03C0%u03BF%u03C5 ... - Translatum</span></h3><div class="TbwUpd NJjxre"><cite class="iUh30 Zu0yb qLRx3b tjvcx">www.translatum.gr<span class="dyjrff qzEoUe"><span> %u203A forum</span></span></cite></div></a>

When I spoof the user agent to mobile from Chrome desktop, I get this (which presents the issue, apparently, it is just the = sign which is mangled there? "topic%3D985701"):

<a class="C8nzq BmP5tf amp_r" data-amp="https://www.translatum.gr/forum/index.php?action=amp;topic%3D985701" data-amp-cur="https://www.translatum.gr/forum/index.php?action=amp;topic=985701" data-amp-title="translatum.gr" data-amp-vgi="8458557019360116853" href="/url?sa=t&amp;source=web&amp;rct=j&amp;url=https://www.translatum.gr/forum/index.php%3Faction%3Damp%3Btopic%3D985701&amp;ved=2ahUKEwibmLWs-_zsAhUDKuwKHUYaB2EQFjAAegQIBBAC&amp;usg=AOvVaw1svqtelcNJFRHy1kuYwYAy&amp;ampcf=1" data-ved="2ahUKEwibmLWs-_zsAhUDKuwKHUYaB2EQFjAAegQIBBAC" oncontextmenu="google.ctpacw.cm(this)"><div class="abuKkc IhfN8d MUxGbd lyLwlc aLF0Z"><img class="eqA2re" height="16" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAABnRSTlMAAAAAAABupgeRAAAAMklEQVR4AWMY5OD/TIb/aZgIl+o0XAinanSdBAGFGmbS0gZMLxGrgSirCAQrYT2DHwAAv0tHhsJpXPsAAAAASUVORK5CYII=" width="16" alt="Image" aria-hidden="true" data-atf="1"><span class="Zu0yb UGIkD qzEoUe">www.translatum.gr<span class="kbNtnf Jzkcjd"> %u203A forum</span></span><span jsname="zYLzN" class="ZseVEf QzoJOb" aria-label="AMP logo"></span></div><h2 class="Uo8X3b">Web results</h2><div class="PpBGzd YcUVQe MUxGbd v0nnCb" aria-level="3" role="heading"><div class="V7Sr0 p5AXld PpBGzd YcUVQe">pre-owned -&gt; %u03BC%u03B5%u03C4%u03B1%u03C7%u03B5%u03B9%u03C1%u03B9%u03C3%u03BC%u03AD%u03BD%u03BF%u03C2, %u03B4%u03B5%u03CD%u03C4%u03B5%u03C1%u03BF %u03C7%u03AD%u03C1%u03B9, %u03C0%u03BF%u03C5 %u03B5%u03AF%u03C7%u03B5 %u03C0%u03C1%u03BF%u03B7%u03B3%u03BF%u03CD%u03BC%u03B5%u03BD%u03BF %u03B9%u03B4%u03B9%u03BF%u03BA%u03C4%u03AE%u03C4%u03B7, %u03C0%u03C1%u03BF%u03CA%u03B4%u03B9%u03CC%u03BA%u03C4%u03B7%u03C4%u03BF%u03C2 - Translatum</div></div></a>

I am guessing here that it is the data-amp value which matters when it comes to linking to the result.

Would be interesting to see if anybody else is using the mod and has amp results listed in Google, to double check.
Title: Re: AMP4SMF
Post by: Antes on November 12, 2020, 07:17:02 AM
Interesting part is;

/index.php?action=amp%3Btopic%3D985701

this is how I send to header

<link rel="amphtml" href="'. $scripturl . '?action=amp;topic=' . $topic .'">


the first "=" sign does not change, but after that ";" and "=" both changes... I'll research this further, unless Arantor comes around and gives the answer :P
Title: Re: AMP4SMF
Post by: spiros on November 12, 2020, 07:27:58 AM
I can see <link rel="amphtml" href="'. $scripturl . '?action=amp;topic=' . $topic .'"> in modification.xml. But if one wanted to change URL parameters for the AMP URL formation, this could not be done here, correct?

This part /index.php?action=amp%3Btopic%3D985701 is in the ping tag. It exists in Desktop search results too which are not affected by this issue.
Title: Re: AMP4SMF
Post by: gorbi on February 06, 2023, 06:24:30 AM
Great work!
Title: Re: AMP4SMF
Post by: SusanTN on January 09, 2024, 01:24:46 PM
Google Notified me of an error with amp generated by this plugin.

The attribute 'type' may not appear in tag 'li'.

Here is google's amp specification

https://amp.dev/documentation/guides-and-tutorials/websites/learn/spec/amphtml?redirected