diff --git a/apps/server/src/core/share/share-seo.controller.ts b/apps/server/src/core/share/share-seo.controller.ts index d2cfdd975..63de09bdb 100644 --- a/apps/server/src/core/share/share-seo.controller.ts +++ b/apps/server/src/core/share/share-seo.controller.ts @@ -60,16 +60,21 @@ export class ShareSeoController { const pageId = this.extractPageSlugId(pageSlug); - const share = await this.shareService.getShareForPage( - pageId, - workspace.id, - ); - - if (!share) { + let title: string; + let searchIndexing = false; + try { + const shared = await this.shareService.getSharedPage( + { pageId }, + workspace.id, + { includeContent: false }, + ); + title = shared.page.title; + searchIndexing = shared.share.searchIndexing; + } catch (err) { return this.sendIndex(indexFilePath, res); } - const rawTitle = htmlEscape(share?.sharedPage.title ?? 'untitled'); + const rawTitle = htmlEscape(title ?? 'untitled'); const metaTitle = rawTitle.length > 80 ? `${rawTitle.slice(0, 77)}…` : rawTitle; @@ -78,7 +83,7 @@ export class ShareSeoController { const metaTags = [ ``, ``, - !share.searchIndexing ? `` : '', + !searchIndexing ? `` : '', ] .filter(Boolean) .join('\n '); diff --git a/apps/server/src/core/share/share.service.ts b/apps/server/src/core/share/share.service.ts index 68acf48e8..00dbd0caa 100644 --- a/apps/server/src/core/share/share.service.ts +++ b/apps/server/src/core/share/share.service.ts @@ -110,7 +110,11 @@ export class ShareService { } } - async getSharedPage(dto: ShareInfoDto, workspaceId: string) { + async getSharedPage( + dto: ShareInfoDto, + workspaceId: string, + opts?: { includeContent?: boolean }, + ) { //TODO: we should resolve the page from the share id if (!dto.pageId) throw new NotFoundException('Shared page not found'); @@ -120,10 +124,13 @@ export class ShareService { throw new NotFoundException('Shared page not found'); } - const page = await this.pageRepo.findById(dto.pageId, { - includeContent: true, - includeCreator: true, - }); + const includeContent = opts?.includeContent !== false; + const page = includeContent + ? await this.pageRepo.findById(dto.pageId, { + includeContent: true, + includeCreator: true, + }) + : await this.pageRepo.findById(dto.pageId); if (!page || page.deletedAt) { throw new NotFoundException('Shared page not found'); @@ -137,7 +144,9 @@ export class ShareService { throw new NotFoundException('Shared page not found'); } - page.content = await this.updatePublicAttachments(page); + if (includeContent) { + page.content = await this.updatePublicAttachments(page); + } return { page, share }; }