All Projects → verkstedt → react-amp-components

verkstedt / react-amp-components

Licence: MIT License
A (hopefully) simple way to render AMP components via React on the server.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-amp-components

amp-mui
⚡ AMP MUI CSS Framework
Stars: ✭ 18 (-40%)
Mutual labels:  amp, amp-html
amp-surface
⚡ AMP Surface CSS Framework
Stars: ✭ 26 (-13.33%)
Mutual labels:  amp, amp-html
amp-converter
A PHP library to convert HTML articles, blog posts or similar content to AMP (Accelerated Mobile Pages).
Stars: ✭ 59 (+96.67%)
Mutual labels:  amp, amp-html
ampjucks
Boilerplate and base project to create static websites with AMP, Nunjucks and Gulp
Stars: ✭ 18 (-40%)
Mutual labels:  amp, amp-html
amp-browser
AMP Browser
Stars: ✭ 39 (+30%)
Mutual labels:  amp, amp-html
wordpress-amp-theme
A free WordPress theme for blogging built entirely on Google AMP
Stars: ✭ 22 (-26.67%)
Mutual labels:  amp, amp-html
amp-react-renderer-plugin
⚡Plugin makes it painless to create React component based AMP page⚡
Stars: ✭ 29 (-3.33%)
Mutual labels:  amp, amp-html
amp-renderer
Server-side rendering for AMP in Python
Stars: ✭ 14 (-53.33%)
Mutual labels:  amp, amp-html
AMP-dockerized
CubeCoders AMP in a Docker Image. Easily create game servers for games like Minecraft, GMod, TF2, Factorio, and StarBound!
Stars: ✭ 54 (+80%)
Mutual labels:  amp
MadelineProtoPluginSystem
A fully async plugin-friendly MadelineProto source base
Stars: ✭ 14 (-53.33%)
Mutual labels:  amp
amp-bootstrap-example
Example workflow for using Bootstrap with AMP
Stars: ✭ 75 (+150%)
Mutual labels:  amp-html
alfresco-mvc
Glue between SpringMVC @controllers and Alfresco
Stars: ✭ 22 (-26.67%)
Mutual labels:  amp
prestashopamp
Prestashop module to support AMP
Stars: ✭ 32 (+6.67%)
Mutual labels:  amp
hugo-lamp
A light Hugo AMP responsive theme for blogger ⚡.
Stars: ✭ 51 (+70%)
Mutual labels:  amp
gridd
Flexible grid-based WordPress theme
Stars: ✭ 38 (+26.67%)
Mutual labels:  amp
deepvac
PyTorch Project Specification.
Stars: ✭ 507 (+1590%)
Mutual labels:  amp
ficus
Scala-friendly companion to Typesafe config
Stars: ✭ 321 (+970%)
Mutual labels:  amp
Magento-AMP
Accelerated Mobile Pages (Google AMPs) for Magento1
Stars: ✭ 43 (+43.33%)
Mutual labels:  amp-html
web-stories-wp
Web Stories for WordPress
Stars: ✭ 695 (+2216.67%)
Mutual labels:  amp
awesome-milligram
A curated list of Milligram resources.
Stars: ✭ 76 (+153.33%)
Mutual labels:  amp

react-amp-components

npm version Greenkeeper badge

A (hopefully) simple way to render AMP components via React on the server.

It uses react-helmet for managing all the required meta and script tags.

That means that you can just import and use the AMP component you need, without having to care about adding the additional required script tags.

Warning

This project is still in its early infancy. Only a few components exist, but we will add more. Feel free to contribute 🚀

Installation

Install it from npm:

yarn add react-amp-components

or:

npm install --save react-amp-components

Usage

Import and use the AMP component you would like to use:

// MyComponent.js
import {
  Layout, // Renders the boilerplate & delegates the passed children to Helmet
  Sidebar
} from "react-amp-components";

class MyComponent extends React.Component {
  render() {
    <div>
      <Layout>
        <title>{title}</title>
        <link rel="canonical" href="http://canonical.url" />
        <script type="application/ld+json">{`
          {
            "@context": "http://schema.org",
            "@type": "Product"
          }
        `}</script>
      </Layout>
      <Sidebar id="my-sidebar" layout="hidden">
        <p>Here is some sidebar content</p>
      </Sidebar>
    </div>;
  }
}

Then on the server you generate the final HTML output, and the content for the head:

// Server.js
const React = require("react");
const ReactDOMServer = require("react-dom/server");
const { Helmet } = require("react-amp-components");

const MyComponent = require("./MyComponent.js");

const content = ReactDOMServer.renderToStaticMarkup(
  React.createElement(MyComponent)
);
const meta = Helmet.renderStaticClean();

Which you can then interpolate:

const finalHTML = `
  <!doctype html>
  <html ${meta.htmlAttributes}>
    <head>
      ${meta.title}
      ${meta.meta}
      ${meta.link}
      ${meta.script}
      ${meta.noscript}
      ${meta.style}
    </head>
    <body ${meta.bodyAttributes}>
      ${content}
    </body>
  </html>
`;

AMP Components implemented

amp-sidebar

amp-img

amp-carousel

amp-analytics

amp-accordion

amp-bind

amp-install-serviceworker

amp-ad

Example usage:

<InstallServiceworker
  src="https://www.your-domain.com/serviceworker.js"
  dataIframeSrc="https://www.your-domain.com/install-serviceworker.html"
/>

Props:

  • src (required)
  • dataIframeSrc (optional)
  • dataNoServiceWorkerFallbackUrlMatch (optional)
  • dataNoServiceWorkerFallbackShellUrl (optional)

Todo

  • Define all the AMP components with their properties and scripts in a JSON file and use that to generate them.
  • Rename Layout to Helmet
  • Provide helper finalHTML renderer
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].