Skip to content

Commit

Permalink
Apply suggestions from @manuhabitela
Browse files Browse the repository at this point in the history
  • Loading branch information
fflorent committed Oct 17, 2024
1 parent 3206c22 commit c20b198
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
17 changes: 8 additions & 9 deletions app/server/lib/sendAppPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export function makeSendAppPage({ server, staticDir, tag, testLogin, baseDomain
).join('\n');
const content = fileContent
.replace("<!-- INSERT WARNING -->", warning)
.replace("<!-- INSERT TITLE -->", getPageTitle(config) ?? translate(req, 'Loading...'))
.replace("<!-- INSERT TITLE -->", getDocName(config) ?? translate(req, 'Loading...'))
.replace("<!-- INSERT META -->", getPageMetadataHtmlSnippet(req, config, staticBaseUrl))
.replace("<!-- INSERT TITLE SUFFIX -->", getPageTitleSuffix(server.getGristConfig()))
.replace("<!-- INSERT BASE -->", `<base href="${staticBaseUrl}">` + tagManagerSnippet)
Expand Down Expand Up @@ -264,14 +264,12 @@ function configuredPageTitleSuffix() {
}

/**
* Returns a page title suitable for inserting into an HTML title element.
*
* Currently returns the document name if the page being requested is for a document, or
* a placeholder, "Loading...", that's updated in the client once the page has loaded.
* Returns the doc name.
*
* Note: The string returned is escaped and safe to insert into HTML.
*
*/
function getPageTitle(config: GristLoadConfig): string|null {
function getDocName(config: GristLoadConfig): string|null {
const maybeDoc = getDocFromConfig(config);

return maybeDoc && handlebars.Utils.escapeExpression(maybeDoc.name);
Expand All @@ -291,13 +289,13 @@ function getPageMetadataHtmlSnippet(req: express.Request, config: GristLoadConfi

metadataElements.push('<meta property="og:type" content="website">');
metadataElements.push('<meta name="twitter:card" name="summary_large_image">');
const description = maybeDoc?.options?.description ?? translate(req, 'gristMetaDescription');
const description = maybeDoc?.options?.description ?? translate(req, 'og-description');
const escapedDescription = handlebars.Utils.escapeExpression(description);
metadataElements.push(`<meta name="description" content="${escapedDescription}">`);
metadataElements.push(`<meta property="og:description" content="${escapedDescription}">`);
metadataElements.push(`<meta name="twitter:description" content="${escapedDescription}">`);

const icon = maybeDoc?.options?.icon ?? new URL('icons/grist.png', staticBaseUrl).href;
const icon = maybeDoc?.options?.icon ?? new URL('img/opengraph-preview-image.png', staticBaseUrl).href;
const escapedIcon = handlebars.Utils.escapeExpression(icon);
const iconSize = '100';
metadataElements.push(`<meta name="thumbnail" content="${escapedIcon}">`);
Expand All @@ -306,7 +304,8 @@ function getPageMetadataHtmlSnippet(req: express.Request, config: GristLoadConfi
metadataElements.push(`<meta property="og:image:height" content="${iconSize}">`);
metadataElements.push(`<meta name="twitter:image" content="${escapedIcon}">`);

const title = (getPageTitle(config) ?? translate(req, 'Welcome')) + getPageTitleSuffix(config);
const maybeDocTitle = getDocName(config);
const title = (maybeDocTitle ? maybeDocTitle + getPageTitleSuffix(config) : translate(req, 'og-title'));
// NB: We don't generate the content of the <title> tag here.
metadataElements.push(`<meta property="og:title" content="${title}">`);
metadataElements.push(`<meta name="twitter:title" content="${title}">`);
Expand Down
Binary file added static/img/opengraph-preview-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions static/locales/en.server.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"sendAppPage": {
"Loading...": "Loading...",
"gristMetaDescription": "Grist is the evolution of spreadsheets.",
"Welcome": "Welcome"
"og-description": "A modern, open source spreadsheet that goes beyond the grid",
"og-title": "Grist, the evolution of spreadsheet"
},
"oidc": {
"emailNotVerifiedError": "Please verify your email with the identity provider, and log in again."
Expand Down

0 comments on commit c20b198

Please sign in to comment.