Code Monkey home page Code Monkey logo

react-amp-components's Introduction

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

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

react-amp-components's People

Contributors

carelulu-gabriel avatar danigrandeletgo avatar fedegheverkstedt avatar greenkeeper[bot] avatar mattlub avatar nuc avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-amp-components's Issues

Is this still supported?

I see some old issues and PRs, and lots of unimplemented amp components. Just curious whether this is still being improved (or at least dependencies are being updated) before we implement it.

An in-range update of webpack is breaking the build 🚨

The devDependency webpack was updated from 4.25.1 to 4.26.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

webpack is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ ci/circleci: build: Your tests failed on CircleCI (Details).

Commits

The new version differs by 7 commits.

  • 04f90c5 4.26.0
  • e1df721 Merge pull request #8392 from vkrol/cherry-pick-terser-to-webpack-4
  • a818def fix for changed API in terser plugin warningsFilter
  • b39abf4 Rename test directories too
  • 311a728 Switch from uglifyjs-webpack-plugin to terser-webpack-plugin
  • a230148 Merge pull request #8351 from DeTeam/chunk-jsdoc-typo
  • 7a0af76 Fix a typo in Chunk#split jsdoc comment

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

update readme

tasks:

  • add instructions on how to contribute (e.g. raise issue, create PR with description etc.)
  • add example usages for different components
  • add info on deployment/commit styles (e.g. some commits are just version numbers, are these automated?)
  • update todos

An in-range update of semantic-release is breaking the build 🚨

The devDependency semantic-release was updated from 15.13.18 to 15.13.19.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

semantic-release is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ ci/circleci: build: Your tests failed on CircleCI (Details).

Release Notes for v15.13.19

15.13.19 (2019-07-06)

Bug Fixes

  • package: update marked to version 0.7.0 (75f0830)
Commits

The new version differs by 3 commits.

  • 75f0830 fix(package): update marked to version 0.7.0
  • 4b2b2fb chore(package): update clear-module to version 4.0.0
  • 3b8cae9 docs: fix typo

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


The push permission to the Git repository is required.

semantic-release cannot push the version tag to the branch master on remote Git repository with URL https://github.com/verkstedt/react-amp-components.

Please refer to the authentication configuration documentation to configure the Git credentials on your CI environment and make sure the repositoryUrl is configured with a valid Git URL.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

An in-range update of react is breaking the build 🚨

There have been updates to the react monorepo:

    • The devDependency react was updated from 16.6.1 to 16.6.2.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

This monorepo update includes releases of one or more dependencies which all belong to the react group definition.

react is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ ci/circleci: build: Your tests failed on CircleCI (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.