Umbraco extension create Google AMP pages for content.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
Umbraco.Amp Updated the nuget spec infromation. May 17, 2017
.gitattributes Add .gitignore and .gitattributes. May 5, 2017
.gitignore Add .gitignore and .gitattributes. May 5, 2017 Updated Readme Aug 16, 2017
Umbraco Amp.sln Added the img converter May 9, 2017

Umbraco AMP

Umbraco extension create Google AMP pages for content.

Provides an AMP layout boilerplate (/Views/Shared/_LayoutAmp.cshtml) to base AMP pages off of.

Creates an Amp template in Umbraco so that you can start creating amp pages off of the alternate template url in order to have Amp and traditional pages side by side. (Ex:

Use the custom controller RenderAmpMvcController to unlock multiple templates off of the alternate template route. Put AMP views in /Views/Amp and name them off of the document type alias which you want to create an AMP view for.

To make it the default controller, add this to the OnApplicationStarting method on a class implementing IApplicationEventHandler: DefaultRenderMvcControllerResolver.Current.SetDefaultControllerType(typeof(RenderAmpMvcController));

See the Umbraco AMP exmaple here

Converting HTML into AMP HTML

In some cases you will not have control over the HTML being displayed to the page like an RTE from the back office. For these cases this package provides a converter which will try to convert the invalid HTML elements into valid AMP HTML elements. Currently, the items that are converted are:

  • img to amp-img
  • iframe to amp-iframe

In order to use the converter, call the static method Convert(...) on the class AmpConversionProvider. This will return a AmpConversionResult which contains the names of the tags that were converted (so that you can add the nessesary AMP components to the page) and the converted AMP HTML.

var originalHtml = new HtmlString(Model.Content.GetPropertyValue<string>("body"));
var result = AmpConversionProvider.Convert(originalHtml);
var ampHtml = result.AmpHtml;

Using a section in your AMP Layout file, you can add the required AMP components based on the conversion that occured in your view.

@section TagImports {
    @if (result.RequiredAmpComponents.Contains("amp-iframe")) {
        <script async custom-element="amp-iframe" src=""></script>