From 7fb5208dd21c9500165e22f0b700255d5cc612c9 Mon Sep 17 00:00:00 2001 From: fflorent Date: Fri, 4 Oct 2024 15:26:16 +0200 Subject: [PATCH] Add description and icon to preview URLs for non-document resources #1242 When pasting a URL in some app or website that allows previewing the link, for other resources than documents, you were offered an irrelevant description. This patches aims to give a generic description of what is Grist. --- app/server/lib/sendAppPage.ts | 32 ++++++++++++++------------------ static/locales/en.server.json | 3 ++- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/app/server/lib/sendAppPage.ts b/app/server/lib/sendAppPage.ts index 38f3dcb5e9c..23496dd4159 100644 --- a/app/server/lib/sendAppPage.ts +++ b/app/server/lib/sendAppPage.ts @@ -157,8 +157,8 @@ export function makeSendAppPage({ server, staticDir, tag, testLogin, baseDomain const staticTag = options.tag || tag; // If boot tag is used, serve assets locally, otherwise respect // APP_STATIC_URL. - const staticOrigin = staticTag === 'boot' ? '' : (process.env.APP_STATIC_URL || ''); - const staticBaseUrl = `${staticOrigin}/v/${staticTag}/`; + const staticOrigin = staticTag === 'boot' ? '' : (process.env.APP_STATIC_URL || config.homeUrl || ''); + const staticBaseUrl = new URL(`/v/${staticTag}/`, staticOrigin).href; const customHeadHtmlSnippet = server.create.getExtraHeadHtml?.() ?? ""; const warning = testLogin ? "
Authentication is not enforced
" : ""; // Preload all languages that will be used or are requested by client. @@ -173,7 +173,7 @@ export function makeSendAppPage({ server, staticDir, tag, testLogin, baseDomain const content = fileContent .replace("", warning) .replace("", getPageTitle(req, config)) - .replace("", getPageMetadataHtmlSnippet(config)) + .replace("", getPageMetadataHtmlSnippet(req, config, staticBaseUrl)) .replace("", getPageTitleSuffix(server.getGristConfig())) .replace("", `` + tagManagerSnippet) .replace("", preloads) @@ -284,25 +284,21 @@ function getPageTitle(req: express.Request, config: GristLoadConfig): string { * * Note: The string returned is escaped and safe to insert into HTML. */ -function getPageMetadataHtmlSnippet(config: GristLoadConfig): string { +function getPageMetadataHtmlSnippet(req: express.Request, config: GristLoadConfig, staticBaseUrl: string): string { const metadataElements: string[] = []; const maybeDoc = getDocFromConfig(config); - const description = maybeDoc?.options?.description; - if (description) { - const content = handlebars.Utils.escapeExpression(description); - metadataElements.push(``); - metadataElements.push(``); - metadataElements.push(``); - } + const description = maybeDoc?.options?.description ?? String(translate(req, 'gristMetaDescription')); + const escapedDescription = handlebars.Utils.escapeExpression(description); + metadataElements.push(``); + metadataElements.push(``); + metadataElements.push(``); - const icon = maybeDoc?.options?.icon; - if (icon) { - const content = handlebars.Utils.escapeExpression(icon); - metadataElements.push(``); - metadataElements.push(``); - metadataElements.push(``); - } + const icon = maybeDoc?.options?.icon ?? new URL('/img/logo-grist.png', staticBaseUrl).href; + const escapedIcon = handlebars.Utils.escapeExpression(icon); + metadataElements.push(``); + metadataElements.push(``); + metadataElements.push(``); return metadataElements.join('\n'); } diff --git a/static/locales/en.server.json b/static/locales/en.server.json index 3023c47ad28..dafb0a347e0 100644 --- a/static/locales/en.server.json +++ b/static/locales/en.server.json @@ -1,6 +1,7 @@ { "sendAppPage": { - "Loading": "Loading" + "Loading": "Loading", + "gristMetaDescription": "Grist is the evolution of spreadsheets." }, "oidc": { "emailNotVerifiedError": "Please verify your email with the identity provider, and log in again."