Backend of public sharing at root (#6103)

This commit is contained in:
Tom Moor
2023-11-01 22:10:00 -04:00
committed by GitHub
parent 1d6ef2e1b3
commit 2838503273
11 changed files with 153 additions and 29 deletions

View File

@@ -54,6 +54,7 @@ export const renderApp = async (
description?: string;
canonical?: string;
shortcutIcon?: string;
rootShareId?: string;
analytics?: Integration | null;
} = {}
) => {
@@ -72,7 +73,7 @@ export const renderApp = async (
const page = await readIndexFile();
const environment = `
<script nonce="${ctx.state.cspNonce}">
window.env = ${JSON.stringify(presentEnv(env, options.analytics))};
window.env = ${JSON.stringify(presentEnv(env, options))};
</script>
`;
@@ -106,7 +107,10 @@ export const renderApp = async (
};
export const renderShare = async (ctx: Context, next: Next) => {
const { shareId, documentSlug } = ctx.params;
const rootShareId = ctx.state.rootShare?.id;
const shareId = rootShareId ?? ctx.params.shareId;
const documentSlug = ctx.params.documentSlug;
// Find the share record if publicly published so that the document title
// can be be returned in the server-rendered HTML. This allows it to appear in
// unfurls with more reliablity
@@ -159,6 +163,7 @@ export const renderShare = async (ctx: Context, next: Next) => {
? team.avatarUrl
: undefined,
analytics,
rootShareId,
canonical: share
? `${share.canonicalUrl}${documentSlug && document ? document.url : ""}`
: undefined,