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

Feat: google-amp #118

Closed
wants to merge 8 commits into from
Prev Previous commit
Next Next commit
feat(globals): google-amp to jsx wrappers
kirill-ivanovvv committed Nov 15, 2024
commit 2bbf401ca154fa24ee09b7d37e325a6f7638c39a
24 changes: 24 additions & 0 deletions globals/data/src/getters/google-amp-page.getter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
type GetGoogleAmpPageProps = {
bodyContent: string
// TODO title, canonical link
}

type GetGoogleAmpPageReturnType = string

type GetGoogleAmpPageType = (props: GetGoogleAmpPageProps) => GetGoogleAmpPageReturnType

export const getGoogleAmpPage: GetGoogleAmpPageType = ({ bodyContent }) =>
`<!doctype html>
<html amp lang="en">
<head>
<meta charset="utf-8">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<title>Hello, AMPs</title>
<link rel="canonical" href="https://amp.dev/documentation/guides-and-tutorials/start/create/basic_markup/">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
</head>
<body>
${bodyContent}
</body>
</html>`
5 changes: 5 additions & 0 deletions globals/data/src/getters/jsx-html-string.getter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const getJsxHtmlString = async (component: JSX.Element): Promise<string> => {
const ReactDOMServer = (await import('react-dom/server')).default
const staticMarkup = ReactDOMServer.renderToStaticMarkup(component)
return staticMarkup
}