From 8c8258d9c52c6566a0b3d9c740ba81af2431bed5 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Sat, 5 Mar 2022 23:01:12 -0800 Subject: [PATCH] Update meta tags on page change --- script.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/script.js b/script.js index 81801e2..e3247b3 100644 --- a/script.js +++ b/script.js @@ -25,6 +25,12 @@ const postHeader = components.get('post-header'); const postLoader = components.get('post-loader'); 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"]') +}; + /* Hydrate the loaders */ homeLoader.insertAdjacentHTML('beforeend', `
@@ -126,6 +132,8 @@ async function showPage(path) { const post = posts.get(path); document.title = post.title; + head.description.content = post.description; + head.canonical.href = `https://ardislu.dev${path}`; postHeader.querySelector('#edit').href = `https://docs.google.com/document/d/${post.id}/edit`; if (post.content === undefined) { -- 2.47.3