fix(learn): skip plaza share widget on learning assistant pages
Wire delivery path detection through portal static routes and strip baked share chrome from learn parent/child HTML. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
} from '../mindspace-public-page-context.mjs';
|
||||
import {
|
||||
collectInlineScriptHashes,
|
||||
shouldSkipPublicShareWidget,
|
||||
} from '../mindspace-public-delivery.mjs';
|
||||
import {
|
||||
buildViewerAnalyticsIdentity,
|
||||
@@ -336,7 +337,15 @@ export function createPortalPublishedPageDelivery({
|
||||
!raw &&
|
||||
isFullHtml &&
|
||||
result.publication?.accessMode !==
|
||||
'password';
|
||||
'password' &&
|
||||
!shouldSkipPublicShareWidget({
|
||||
pageUrl,
|
||||
requestPath: originalPath,
|
||||
relativePath:
|
||||
result.relativePath ??
|
||||
result.pageSource?.relativePath ??
|
||||
'',
|
||||
});
|
||||
if (canWrapWithShell) {
|
||||
const title =
|
||||
detectPublishedPageTitle(html);
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
injectOgTags,
|
||||
renderWechatSharePreviewHtml,
|
||||
} from '../mindspace-og-tags.mjs';
|
||||
import { stripPublicFileShareWidget } from '../mindspace-public-share-widget.mjs';
|
||||
|
||||
export function attachPortalStaticDeliveryRoutes({
|
||||
app,
|
||||
@@ -161,12 +162,32 @@ export function attachPortalStaticDeliveryRoutes({
|
||||
{ maxAge: '1d' },
|
||||
),
|
||||
);
|
||||
app.use(
|
||||
'/learn',
|
||||
staticMiddleware(pathApi.join(h5Root, 'public/learn'), {
|
||||
maxAge: '0',
|
||||
}),
|
||||
);
|
||||
const learnRoot = pathApi.join(h5Root, 'public/learn');
|
||||
const learnStatic = staticMiddleware(learnRoot, { maxAge: '0' });
|
||||
app.use('/learn', (req, res, next) => {
|
||||
const pathname = String(req.path ?? '').split('?')[0];
|
||||
if (!/\.html$/i.test(pathname)) {
|
||||
return learnStatic(req, res, next);
|
||||
}
|
||||
const filePath = pathApi.join(learnRoot, pathname);
|
||||
const resolvedRoot = pathApi.resolve(learnRoot);
|
||||
const resolvedPath = pathApi.resolve(filePath);
|
||||
if (
|
||||
!resolvedPath.startsWith(`${resolvedRoot}${pathApi.sep}`) &&
|
||||
resolvedPath !== resolvedRoot
|
||||
) {
|
||||
return res.status(403).json({ message: '禁止访问' });
|
||||
}
|
||||
if (!fsApi.existsSync(resolvedPath) || !fsApi.statSync(resolvedPath).isFile()) {
|
||||
return learnStatic(req, res, next);
|
||||
}
|
||||
const html = stripPublicFileShareWidget(
|
||||
fsApi.readFileSync(resolvedPath, 'utf8'),
|
||||
);
|
||||
res.set('Content-Type', 'text/html; charset=utf-8');
|
||||
res.set('Cache-Control', 'no-store');
|
||||
return res.send(html);
|
||||
});
|
||||
|
||||
app.get(
|
||||
'/dev/wechat-share-preview',
|
||||
|
||||
@@ -288,6 +288,9 @@ export function createPortalWorkspacePublicationDelivery({
|
||||
isOwner,
|
||||
pageDataContext,
|
||||
context,
|
||||
htmlFilePath: delivery.filePath ?? '',
|
||||
relativePath: delivery.relativePath ?? '',
|
||||
requestPath: req.originalUrl || req.url || '',
|
||||
userAgent:
|
||||
req.get('user-agent') || '',
|
||||
preparePublicationHtmlForEmbed,
|
||||
|
||||
Reference in New Issue
Block a user