From: Ardis Lu Date: Sun, 20 Mar 2022 22:53:37 +0000 (-0700) Subject: Add Open Graph headers X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=ba4cc469128918d1de94162636d57358b122d768;p=ardislu.dev Add Open Graph headers --- diff --git a/index.html b/index.html index 2bc8f35..fc7cb1d 100644 --- a/index.html +++ b/index.html @@ -5,6 +5,12 @@ + + + + + + diff --git a/script.js b/script.js index b2a20d2..e69efb5 100644 --- a/script.js +++ b/script.js @@ -28,7 +28,12 @@ const postMain = components.get('post-main'); /* Fetch important elements for convenience */ const head = { description: document.querySelector('meta[name="description"]'), - canonical: document.querySelector('link[rel="canonical"]') + canonical: document.querySelector('link[rel="canonical"]'), + ogTitle: document.querySelector('meta[property="og:title"]'), + ogDescription: document.querySelector('meta[property="og:description"]'), + ogUrl: document.querySelector('meta[property="og:url"]'), + ogImage: document.querySelector('meta[property="og:image"]'), + ogImageAlt: document.querySelector('meta[property="og:image:alt"]') }; /* Hydrate the loaders */ @@ -120,6 +125,11 @@ async function showPage(path) { document.title = 'ardislu.dev'; head.description.content = 'Notes on web development, crypto, self-hosting, and tech in general.'; head.canonical.href = 'https://ardislu.dev'; + head.ogTitle.content = 'ardislu.dev'; + head.ogDescription.content = 'Notes on web development, crypto, self-hosting, and tech in general.'; + head.ogUrl.content = 'https://ardislu.dev'; + head.ogImage.content = 'https://og-image.ardislu.dev/Notes%20on%20**web%20development**%2C%20**crypto**%2C%20**self-hosting**%2C%20and%20**tech**%20in%20general..png'; + head.ogImageAlt.content = "Website logo above the text 'notes on web development, crypto, self-hosting, and tech in general.'"; homeMain.innerHTML = ''; for (const [path, post] of posts) { homeMain.insertAdjacentHTML('beforeend', @@ -136,6 +146,11 @@ async function showPage(path) { document.title = post.title; head.description.content = post.description; head.canonical.href = `https://ardislu.dev${path}`; + head.ogTitle.content = post.title; + head.ogDescription.content = post.description; + head.ogUrl.content = `https://ardislu.dev${path}`; + head.ogImage.content = `https://og-image.ardislu.dev/${encodeURIComponent(post.title)}.png`; + head.ogImageAlt.content = `Website logo above the text '${post.title}'`; postHeader.querySelector('#edit').href = `https://docs.google.com/document/d/${post.id}/edit`; if (post.content === undefined) {