From ebded2fc40c3ff2faead343b9f68d768e6db2c32 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 15 May 2022 23:50:42 -0300 Subject: social embeds (discord, maybe twitter) Tracks only for now, but more will come Soon(TM)! --- src/upd8.js | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 80 insertions(+), 9 deletions(-) (limited to 'src/upd8.js') diff --git a/src/upd8.js b/src/upd8.js index 12f1af3..b999ef7 100755 --- a/src/upd8.js +++ b/src/upd8.js @@ -194,6 +194,9 @@ const UTILITY_DIRECTORY = 'util'; // (This gets symlinked into the --data-path directory.) const STATIC_DIRECTORY = 'static'; +// This exists adjacent to index.html for any page with oEmbed metadata. +const OEMBED_JSON_FILE = 'oembed.json'; + function inspect(value) { return nodeInspect(value, {colors: ENABLE_COLOR}); } @@ -822,12 +825,13 @@ writePage.to = ({ return path; }; -writePage.html = (pageFn, { +writePage.html = (pageInfo, { defaultLanguage, language, languages, localizedPaths, paths, + oEmbedJSONHref, to, transformMultiline, wikiData @@ -847,8 +851,9 @@ writePage.html = (pageFn, { sidebarLeft = {}, sidebarRight = {}, nav = {}, - footer = {} - } = pageFn({to}); + footer = {}, + socialEmbed = {}, + } = pageInfo; body.style ??= ''; @@ -1059,6 +1064,14 @@ writePage.html = (pageFn, { `; + const socialEmbedHTML = [ + socialEmbed.title && html.tag('meta', {property: 'og:title', content: socialEmbed.title}), + socialEmbed.description && html.tag('meta', {property: 'og:description', content: socialEmbed.description}), + socialEmbed.image && html.tag('meta', {property: 'og:image', content: socialEmbed.image}), + socialEmbed.color && html.tag('meta', {name: 'theme-color', content: socialEmbed.color}), + oEmbedJSONHref && html.tag('link', {type: 'application/json+oembed', href: oEmbedJSONHref}), + ].filter(Boolean).join('\n'); + return filterEmptyLines(fixWS` value).map(([ key, value ]) => ``).join('\n')} ${canonical && ``} ${localizedCanonical.map(({ lang, href }) => ``).join('\n')} + ${socialEmbedHTML} ${(theme || stylesheet) && fixWS`