Skip to content

Instantly share code, notes, and snippets.

@leemartin
Last active February 11, 2021 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leemartin/b10534aa61e070629e78cae4b47657f8 to your computer and use it in GitHub Desktop.
Save leemartin/b10534aa61e070629e78cae4b47657f8 to your computer and use it in GitHub Desktop.
Dynamic Meta Share Function
const handler = async (event) => {
const subject = event.queryStringParameters.name || 'Tony'
const html = `
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<title>The Sharing</title>
<meta name="description" content="A Masterpiece of the Modern Web">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="The Sharing">
<meta name="twitter:description" content="A Masterpiece of the Modern Web">
<meta name="twitter:image" content="https://1jlm985suc.execute-api.us-east-1.amazonaws.com/dev/share/${subject}">
<meta property="og:type" content="article">
<meta property="og:url" content="https://thesharing.netlify.app/share/${subject}">
<meta property="og:site_name" content="The Sharing">
<meta property="og:title" content="The Sharing">
<meta property="og:description" content="A Masterpiece of the Modern Web">
<meta property="og:image" content="https://1jlm985suc.execute-api.us-east-1.amazonaws.com/dev/share/${subject}">
<meta property="og:image:type" content="image/png">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
</head>
<body>
<script>window.location = '/' + window.location.search;</script>
</body>
</html>`
return {
statusCode: 200,
headers: {
'Content-Type': 'text/html'
},
body: html
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment