cara-tm / pat_if_amp

⚡ A Textpattern Conditional Plugin for Google's Accelerated Mobile Pages Project (AMP)
https://ampstart.com/
GNU General Public License v2.0
4 stars 1 forks source link
accelerated-mobile-pages amp google-amp textpattern textpattern-plugin

h1. pat_if_amp

"Download":https://github.com/cara-tm/pat_if_amp/releases | "Packagist":https://packagist.org/packages/cara-tm/pat_if_amp

AMP pages for "Textpattern CMS":http://textpattern.io/.

This conditional tag examines the URL of the current page and determines if the URL ends in 'amp.' This allows for a custom page to be rendered using the standards for Google's Accelerated Mobile Pages (AMP) project.

h2. Links

Don't forget to check out my other plugin that's also Google AMP compatible: "pat_article_social":https://github.com/cara-tm/pat_article_social

h2. Note

Since TXP 4.7+ and its new features, you can choose to use build-in tags solution instead of this plugin. Read more about from "this forum post by Oleg":https://forum.textpattern.com/viewtopic.php?pid=320549#p320549 (don't forget to add a TXP variable on the fly for further usages within you website):

bc.. AMP page

regular page

</txp:evaluate>

h2. Installing

Using "Composer":https://getcomposer.org:

bc. $ composer require cara-tm/pat_if_amp:*

Or download the latest version of the plugin from "the GitHub project page":https://github.com/cara-tm/pat_if_amp/releases, paste the code into the Textpattern Plugins administration panel, install and enable the plugin.

h2. pat_if_amp

h3. Attributes

  • @url@ string (optional): The location (URL) of the website. Default: @hu@ (website URL as set in the Textpattern preferences panel).
  • @subdomain@ string (optional): Sets the subdomain name of where to redirect to. Default: @amp@.
  • @permlink@ boolean (optional): if set to @0@ (false) the redirection for the same article's URL mode within the subdomain will be not made. Default: @1@ (true).

h3. Example

Place code similar to below within your individual article template header, so that the AMP page can be properly detected:

bc.

<link rel="amphtml" href="https://github.com/cara-tm/pat_if_amp/blob/master/<txp:permlink />/amp/">

</txp:if_individual_article>

Place something similar to below within your individual article template to display the alternative formatting:

bc.

<txp:output_form form="standard_page" />

</txp:mkp_if_amp>

h2. Textpattern variable usage

A @@ with a true/false value (@1@ or @0@) is automatically generated, for testing when this is an AMP context or not.

h3. Usage

bc. AMP context

Normal context

</txp:if_variable>

h3. Example

bc. ...Do some AMP things... AMP Category 1 Link

...Do some normal (non-AMP) things...

</txp:if_variable>

This example concerns categories, use kind of the same model for @pages@ and/or @archives@.

h2. pat_amp_sanitize

A tag to render article text content without any inline styles. To use as a drop-in replacement of the standard Textpattern @@ tag and/or @@ tag.

h3. Attributes

  • @content@ string (optional): choose either @body@ or @excerpt@ article content to sanitize. Default: @body@.

h3. Usage

In an article Form context:

bc.

h2. pat_amp_redirect

A simple tag for web redirection to a subdomain name. Same behaviour as used in The Guardian website. Must be used with a mobiles detection script (i.e. adi_mobile plugin). Some web designers could choose to use a subdomain for their mobiles websites (may be not recommended, but the official AMP Blog is located in a subdomain, see: "https://amphtml.wordpress.com":https://amphtml.wordpress.com). In this case, the Textpattern multi-sites capacities makes things easier.

Note: Doesn't work on local server installations, only on live servers.

h3. Usage

bc.

Good advice: Copy the @config.php@ file of the main site into the subdomain configuration folder in order to share the same database. So, all articles written by the Copy Editors will be sent automatically to the 'AMP powered website' from only one Textpattern administration interface attached to the 'normal' website. But designers have a separate and cleaner space to build their AMP pages.

h3. Attributes

  • @url@ string (optional): The location (URL) of the website. Default: @hu@ (website URL as set in the Textpattern preferences panel).
  • @subdomain@ string (optional): Sets the subdomain name of where to redirect to. Default: @amp@.
  • @permlink@ boolean (optional): Choose to redirect the same individual article's title URL within the subdomain. Default: @0@ (false).

h3. Example

bc.

In this case, if your main domain is @example.com@, it redirects to the @amp.example.com@ subdomain and uses the same individual article's URL from the main domain.

h3. Acknowledgments

Many thanks to "Phil Wareham":http://www.designhive.com/contact/phil-wareham who tidied up this plugin code and its help file. Thank you to "Michael K. Pate":https://github.com/michaelkpate, for its original idea, who accepted to distribute my entire rewriting code as a 'pat' prefixed plugin.

!https://raw.githubusercontent.com/cara-tm/pat_if_amp/master/amp-project-textpattern-cms-mention.png!