@prunellejs/seo 0.7.3 → 0.7.5

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/check.ts +16 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prunellejs/seo",
3
- "version": "0.7.3",
3
+ "version": "0.7.5",
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.7.5"
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 {