diff --git a/CMS/CMSModules/Kentico.AcceleratedMobilePages/Default.aspx.cs b/CMS/CMSModules/Kentico.AcceleratedMobilePages/Default.aspx.cs index 940e089..3f034ae 100644 --- a/CMS/CMSModules/Kentico.AcceleratedMobilePages/Default.aspx.cs +++ b/CMS/CMSModules/Kentico.AcceleratedMobilePages/Default.aspx.cs @@ -57,7 +57,7 @@ protected void Page_Load(object sender, EventArgs e) CurrentMaster.HeaderActions.Enabled = false; } - if (Node != null && !URLHelper.IsPostback()) + if (Node != null && !RequestHelper.IsPostBack()) { ReloadData(); } diff --git a/Kentico.AcceleratedMobilePages/AmpFilter.cs b/Kentico.AcceleratedMobilePages/AmpFilter.cs index 37c36c0..84b7a88 100644 --- a/Kentico.AcceleratedMobilePages/AmpFilter.cs +++ b/Kentico.AcceleratedMobilePages/AmpFilter.cs @@ -19,6 +19,12 @@ public class AmpFilter private string customElementsScripts; + /// + /// Returns URL protocol prefix depending on the current connection + /// + private string ConnectionProtocolPrefix => CMSHttpContext.Current.Request.IsSecureConnection ? Constants.P_HTTPS : Constants.P_HTTP; + + /// /// If the filter is enabled for current page, final HTML will be modified /// @@ -67,10 +73,9 @@ private string TransformToAmpHtml(string finalHtml) /// Final HTML string private string AppendAmpHtmlLink(string finalHtml) { - string ampLink = (CMSHttpContext.Current.Request.IsSecureConnection ? Constants.P_HTTPS : Constants.P_HTTP) + + string ampLink = ConnectionProtocolPrefix + Settings.AmpFilterDomainAlias + - (DocumentContext.CurrentPageInfo.DocumentUrlPath ?? DocumentContext.CurrentAliasPath) + - Settings.CmsFriendlyUrlExtension; + GetDocumentPath(); string metaTag = String.Format(Constants.AMP_AMP_HTML_LINK, ampLink) + Constants.NEW_LINE; // Insert meta tag finalHtml = Regex.Replace(finalHtml, "", metaTag + ""); @@ -234,9 +239,9 @@ private string InsertCompulsoryMarkupAndCss(string finalHtml) string styles = GetStylesheetText(); // Create a link pointing to the regular HTML version of the page - string canonicalLink = (CMSHttpContext.Current.Request.IsSecureConnection ? Constants.P_HTTPS : Constants.P_HTTP) + - SiteContext.CurrentSite.DomainName + (DocumentContext.CurrentPageInfo.DocumentUrlPath ?? DocumentContext.CurrentAliasPath) + - Settings.CmsFriendlyUrlExtension; + string canonicalLink = ConnectionProtocolPrefix + + SiteContext.CurrentSite.DomainName + + GetDocumentPath(); // Extend the tag with the compulsory markup and CSS styles headTag += Constants.NEW_LINE + @@ -360,5 +365,18 @@ private void RemoveAttribute(HtmlDocument doc, string xPath, string attrName) } } } + + + /// + /// Returns path of the currently processed document + /// + private string GetDocumentPath() + { + var documentPath = !String.IsNullOrEmpty(DocumentContext.CurrentPageInfo.DocumentUrlPath) + ? DocumentContext.CurrentPageInfo.DocumentUrlPath + : DocumentContext.CurrentAliasPath; + + return documentPath + Settings.CmsFriendlyUrlExtension; + } } } diff --git a/Kentico.AcceleratedMobilePages/Constants.cs b/Kentico.AcceleratedMobilePages/Constants.cs index ef3886f..e785ef0 100644 --- a/Kentico.AcceleratedMobilePages/Constants.cs +++ b/Kentico.AcceleratedMobilePages/Constants.cs @@ -56,7 +56,7 @@ public class Constants "//meta[translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=\"viewport\"]", "//script[not(translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=\"application/ld+json\") and not(@async and @custom-element)]", "//input[translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=\"image\" or translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=\"button\" or translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=\"password\" or translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=\"file\"]", - "//link[translate(@rel,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=\"preconnect\" or translate(@rel,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=\"prerender\" or translate(@rel,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=\"prefetch\"]", + "//link[translate(@rel,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=\"preconnect\" or translate(@rel,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=\"prerender\" or translate(@rel,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=\"prefetch\" or (translate(@rel,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=\"preload\" and translate(@as,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')=\"style\") ]", "//meta[@http-equiv]", "//a[starts-with(@href,\"javascript:\")][not(contains(@target,\"_blank\"))]", "//style", diff --git a/Kentico.AcceleratedMobilePages/Settings.cs b/Kentico.AcceleratedMobilePages/Settings.cs index c300022..2d8362b 100644 --- a/Kentico.AcceleratedMobilePages/Settings.cs +++ b/Kentico.AcceleratedMobilePages/Settings.cs @@ -9,7 +9,7 @@ public static class Settings /// /// Gets extensions that the system adds to page URLs on current site. /// - public static string CmsFriendlyUrlExtension => SettingsKeyInfoProvider.GetValue(SiteContext.CurrentSiteName + ".CMSFriendlyURLExtension"); + public static string CmsFriendlyUrlExtension => SettingsKeyInfoProvider.GetValue(SiteContext.CurrentSiteName + ".CMSFriendlyURLExtension").Split(';')[0]; /// diff --git a/README.md b/README.md index bd36837..17df419 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Accelerated Mobile Pages Module (AMP Filter) is a custom module for Kentico CMS and EMS. It consists of an [Output Filter](https://docs.kentico.com/k11/configuring-kentico/using-output-filters) for transforming regular HTML to AMP HTML format and a macro method that makes it easy to adjust and fine-tune the rendered output. The project is based on a [master thesis (EN)](https://is.muni.cz/th/409956/fi_m/?lang=en) of Daniel Minarik ([full text](https://is.muni.cz/th/409956/fi_m/thesis.pdf)). -:bulb: Read [how we implemented AMP](https://devnet.kentico.com/articles/google-amping-the-kentico-advantage-site) on [Kentico Advantage website](http://amp.advantage.kentico.com/). +:bulb: Read [how we implemented AMP](https://devnet.kentico.com/articles/google-amping-the-kentico-advantage-site) on Kentico Advantage website. ## Usage @@ -39,7 +39,7 @@ There are several ways of including cascading style sheets into an AMP page: * If none of the previous options is set, the AMP Filter will use the regular CSS stylesheet assigned to the page (either the site's default stylesheet or the page-specifc one). This option is not recommended, as the stylesheet could be bigger than 50kB (e.g., if it contains styles for the whole website). ### Further customization of AMP pages -The AMP standard offers a lot of components or tags which do not have an ordinary HTML equivalent, and therefore, they can't be automatically injected or replaced in the page's source code. +The AMP standard offers a lot of components or tags which do not have an ordinary HTML equivalent, and therefore, they can't be automatically injected or replaced in the page's source code. You can use the `{% AmpFilter.IsAmpPage() %}` macro to find out whether the AMP Filter is enabled and active on the current page. This is useful for showing and hiding different parts of a web page. To do that, use the macro as a visibility condition of a web part. @@ -66,7 +66,7 @@ Some advanced replacements (which were not possible to implement using the HtmlA ### Cascading style sheets The AMP Filter does not transform cascading stylesheets in any way. The developer must ensure that the stylesheet complies with [AMP HTML specification - stylesheet restrictions](https://www.ampproject.org/docs/reference/spec#stylesheets). - + ### Global settings AMP Filter has two types of global settings: @@ -91,7 +91,7 @@ Even when using the AMP Filter there are still some things that need to be handl * For simple sites with CSS totalling no more than 50kB in size (and adhering to the official [AMP rules](https://www.ampproject.org/docs/reference/spec#stylesheets)), there's no need to create AMP-specific stylesheets - the sites will work correctly with the regular stylesheets. * The AMP filter is mainly intened for simple, static pages, i.e. pages containing regular HTML. Only the ``, `