@prunellejs/seo 0.7.3 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prunellejs/seo",
3
- "version": "0.7.3",
3
+ "version": "0.8.0",
4
4
  "description": "SEO meta, JSON-LD, sitemap, redirects, and self-hosted fonts plugin for Prunelle",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -21,6 +21,6 @@
21
21
  "directory": "packages/plugin-seo"
22
22
  },
23
23
  "peerDependencies": {
24
- "prunelle": "^0.7.3"
24
+ "prunelle": "^0.8.0"
25
25
  }
26
26
  }
package/src/check.ts CHANGED
@@ -4,6 +4,7 @@ import type { CheckPluginContext } from 'prunelle/config'
4
4
  import type { SeoPluginOptions } from './index'
5
5
  import { existsSync, readdirSync, readFileSync } from 'node:fs'
6
6
  import { basename, dirname, join, relative } from 'node:path'
7
+ import { isInside } from 'prunelle/config'
7
8
  import { getAppContext } from 'prunelle/internal/server'
8
9
 
9
10
  const MAX_TITLE = 60
@@ -376,9 +377,22 @@ function checkImageFile(ctx: CheckPluginContext, image: string | undefined): voi
376
377
  const path = image?.trim().split(/[?#]/)[0]
377
378
  if (path === undefined || path === '' || ctx.publicDir === undefined || REMOTE_URL_RE.test(path))
378
379
  return
379
- const file = join(ctx.publicDir, decodeURIComponent(path.replace(/^\/+/, '')))
380
+ const raw = path.replace(/^\/+/, '')
381
+ let decoded = raw
382
+ try {
383
+ decoded = decodeURIComponent(raw)
384
+ }
385
+ catch {
386
+ decoded = raw
387
+ }
388
+ const file = join(ctx.publicDir, decoded)
389
+ const pubRel = relative(ctx.root, ctx.publicDir) || '.'
390
+ if (!isInside(ctx.publicDir, file)) {
391
+ ctx.warn(formatWarn('prunelle.config.ts', undefined, 0, 'missing-image-file', `seo({ image }) is "${image}", which resolves outside ${pubRel}/, so share previews show no image`, `point \`image\` at a file inside ${pubRel}/ or at an absolute URL`))
392
+ return
393
+ }
380
394
  if (!existsSync(file))
381
- ctx.warn(formatWarn('prunelle.config.ts', undefined, 0, 'missing-image-file', `seo({ image }) is "${image}", but ${relative(ctx.root, file)} does not exist, so share previews show no image`, `add the image to ${relative(ctx.root, ctx.publicDir) || '.'}/, or point \`image\` at a file there or at an absolute URL`))
395
+ ctx.warn(formatWarn('prunelle.config.ts', undefined, 0, 'missing-image-file', `seo({ image }) is "${image}", but ${relative(ctx.root, file)} does not exist, so share previews show no image`, `add the image to ${pubRel}/, or point \`image\` at a file there or at an absolute URL`))
382
396
  }
383
397
 
384
398
  function lastOwned(entries: readonly TextEntry[], file: string, code: string, fromLayout: boolean): OwnedEntry | undefined {
package/src/index.ts CHANGED
@@ -586,11 +586,11 @@ export function seo(options: SeoPluginOptions = {}): PrunellePlugin {
586
586
  if (res.status >= 400 && seoCanonicalRequests.has(ctx.request) && !res.headers.has('content-encoding') && (res.headers.get('content-type') ?? '').includes('text/html')) {
587
587
  const html = await res.text()
588
588
  const cleaned = html.replace(CANONICAL_LINK_RE, '')
589
- if (cleaned !== html) {
590
- const headers = new Headers(res.headers)
589
+ const headers = new Headers(res.headers)
590
+ // The body is read, so the original Response is spent: hand back a fresh one even when nothing was stripped.
591
+ if (cleaned !== html)
591
592
  headers.delete('content-length')
592
- return new Response(cleaned, { status: res.status, statusText: res.statusText, headers })
593
- }
593
+ return new Response(cleaned, { status: res.status, statusText: res.statusText, headers })
594
594
  }
595
595
  return res
596
596
  }, { scope: 'dynamic' })