mirror of
https://github.com/docmost/docmost.git
synced 2026-09-11 07:56:54 +08:00
fix: meta title for shared subpages (#2478)
This commit is contained in:
@@ -60,16 +60,21 @@ export class ShareSeoController {
|
|||||||
|
|
||||||
const pageId = this.extractPageSlugId(pageSlug);
|
const pageId = this.extractPageSlugId(pageSlug);
|
||||||
|
|
||||||
const share = await this.shareService.getShareForPage(
|
let title: string;
|
||||||
pageId,
|
let searchIndexing = false;
|
||||||
workspace.id,
|
try {
|
||||||
);
|
const shared = await this.shareService.getSharedPage(
|
||||||
|
{ pageId },
|
||||||
if (!share) {
|
workspace.id,
|
||||||
|
{ includeContent: false },
|
||||||
|
);
|
||||||
|
title = shared.page.title;
|
||||||
|
searchIndexing = shared.share.searchIndexing;
|
||||||
|
} catch (err) {
|
||||||
return this.sendIndex(indexFilePath, res);
|
return this.sendIndex(indexFilePath, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
const rawTitle = htmlEscape(share?.sharedPage.title ?? 'untitled');
|
const rawTitle = htmlEscape(title ?? 'untitled');
|
||||||
const metaTitle =
|
const metaTitle =
|
||||||
rawTitle.length > 80 ? `${rawTitle.slice(0, 77)}…` : rawTitle;
|
rawTitle.length > 80 ? `${rawTitle.slice(0, 77)}…` : rawTitle;
|
||||||
|
|
||||||
@@ -78,7 +83,7 @@ export class ShareSeoController {
|
|||||||
const metaTags = [
|
const metaTags = [
|
||||||
`<meta property="og:title" content="${metaTitle}" />`,
|
`<meta property="og:title" content="${metaTitle}" />`,
|
||||||
`<meta property="twitter:title" content="${metaTitle}" />`,
|
`<meta property="twitter:title" content="${metaTitle}" />`,
|
||||||
!share.searchIndexing ? `<meta name="robots" content="noindex" />` : '',
|
!searchIndexing ? `<meta name="robots" content="noindex" />` : '',
|
||||||
]
|
]
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.join('\n ');
|
.join('\n ');
|
||||||
|
|||||||
@@ -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
|
//TODO: we should resolve the page from the share id
|
||||||
if (!dto.pageId) throw new NotFoundException('Shared page not found');
|
if (!dto.pageId) throw new NotFoundException('Shared page not found');
|
||||||
|
|
||||||
@@ -120,10 +124,13 @@ export class ShareService {
|
|||||||
throw new NotFoundException('Shared page not found');
|
throw new NotFoundException('Shared page not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
const page = await this.pageRepo.findById(dto.pageId, {
|
const includeContent = opts?.includeContent !== false;
|
||||||
includeContent: true,
|
const page = includeContent
|
||||||
includeCreator: true,
|
? await this.pageRepo.findById(dto.pageId, {
|
||||||
});
|
includeContent: true,
|
||||||
|
includeCreator: true,
|
||||||
|
})
|
||||||
|
: await this.pageRepo.findById(dto.pageId);
|
||||||
|
|
||||||
if (!page || page.deletedAt) {
|
if (!page || page.deletedAt) {
|
||||||
throw new NotFoundException('Shared page not found');
|
throw new NotFoundException('Shared page not found');
|
||||||
@@ -137,7 +144,9 @@ export class ShareService {
|
|||||||
throw new NotFoundException('Shared page not found');
|
throw new NotFoundException('Shared page not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
page.content = await this.updatePublicAttachments(page);
|
if (includeContent) {
|
||||||
|
page.content = await this.updatePublicAttachments(page);
|
||||||
|
}
|
||||||
|
|
||||||
return { page, share };
|
return { page, share };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user