From 2a7654edf30a418f33d47fd5117965efa95cb6d0 Mon Sep 17 00:00:00 2001 From: Caleb Jasik Date: Tue, 20 Jul 2021 21:52:26 -0500 Subject: Docs/ Add MetaData component for Open Graph and Twitter embeds (#784) * Docs/ Add MetaData component for Open Graph and Twitter embeds * Switch twitter card type to `summary_large_image` * Add a version tag to the default-og-image url for cache busting * Update docs/src/config.ts Co-authored-by: Fred K. Schott * Incorporate changes from review * Construct `canonicalImageSrc` from `Astro.site`, which is not useful now, but could be if #788 is implemented Co-authored-by: Fred K. Schott --- docs/src/components/MetaData.astro | 38 ++++++++++++++++++++++++++++++++++++++ docs/src/config.ts | 12 ++++++++++++ docs/src/layouts/Main.astro | 6 +++++- 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 docs/src/components/MetaData.astro (limited to 'docs/src') diff --git a/docs/src/components/MetaData.astro b/docs/src/components/MetaData.astro new file mode 100644 index 000000000..ec62749b0 --- /dev/null +++ b/docs/src/components/MetaData.astro @@ -0,0 +1,38 @@ +--- +import { site } from '../config.ts'; +const { content = {}, canonicalURL } = Astro.props; +const formattedContentTitle = content.title ? `${content.title} 🚀 ${site.title}` : site.title; +const imageSrc = content?.image?.src ?? site.image.src; +const canonicalImageSrc = new URL(imageSrc, Astro.site); +const imageAlt = content?.image?.alt ?? site.image.alt; +--- + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/src/config.ts b/docs/src/config.ts index b24b5c499..a9f5258f9 100644 --- a/docs/src/config.ts +++ b/docs/src/config.ts @@ -70,4 +70,16 @@ export const sidebar = [ export const site = { title: 'Astro Documentation', + description: 'Build faster websites with less client-side Javascript', + ogLocale: 'en_US', + image: { + src: '/default-og-image.png?v=1', + alt: + 'astro logo on a starry expanse of space,' + + ' with a purple saturn-like planet floating in the right foreground', + }, + twitter: { + site: 'astrodotbuild', + creator: 'astrodotbuild', + }, }; diff --git a/docs/src/layouts/Main.astro b/docs/src/layouts/Main.astro index 25292896f..e9805dc42 100644 --- a/docs/src/layouts/Main.astro +++ b/docs/src/layouts/Main.astro @@ -4,6 +4,7 @@ import SiteSidebar from '../components/SiteSidebar.astro'; import ThemeToggle from '../components/ThemeToggle.tsx'; import DocSidebar from '../components/DocSidebar.tsx'; import MenuToggle from '../components/MenuToggle.tsx'; +import MetaData from "../components/MetaData.astro"; import { site } from "../config.ts"; const { content = {}, centered = false } = Astro.props; @@ -22,6 +23,7 @@ if (currentPage) { {content.title ? `${content.title} 🚀 ${site.title}` : site.title} +