Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to get raw scripts urls in script manager #42

Merged
merged 3 commits into from
Aug 8, 2019
Merged

Add method to get raw scripts urls in script manager #42

merged 3 commits into from
Aug 8, 2019

Conversation

lucasecdb
Copy link
Contributor

I've added a new method to the AmpScripts class to support getting the raw scripts urls instead of the React elements, so I don't need to render twice in my server. This also adds the capability of sending the urls in a serializable way, if you have a separate microservice to handle the server-rendering task.

Usage would be as follow:

import { AmpScripts, AmpScriptsManager } from 'react-amphtml/setup';
import App from './App';

const ampScripts = new AmpScripts();

const bodyContent = renderToStaticMarkup(
  <AmpScriptsManager ampScripts={ampScripts}>
    <App />
  </AmpScriptsManager>,
);

const scriptSources = ampScripts.getScripts()

const html = `
<!doctype html>
<html amp="">
  <head>
    <!-- should manually add the header boilerplate here -->
    ${scriptSources.map(({ src, extension }) =>
      `<script async custom-element="${extension}" src="${src}"></script>`
    )}
  </head>
  <body>${bodyContent}</body>
</html>
`

@lucasecdb
Copy link
Contributor Author

@dfrankland can you take a look at this? I don't know what to add in the tests to increase the coverage

@dfrankland dfrankland merged commit 278302f into dfrankland:master Aug 8, 2019
@dfrankland
Copy link
Owner

@lucasecdb thanks for this improvement! I am going to make a couple of changes, and probably add another test to bump the coverage, then I will publish.

@lucasecdb lucasecdb deleted the feat/raw-scripts branch August 8, 2019 18:35
@lucasecdb
Copy link
Contributor Author

thanks!

@dfrankland
Copy link
Owner

Everything should be published under v4.0.2. Thanks again 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants