@sugarat/theme 0.2.13 → 0.2.14

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/node.js CHANGED
@@ -519,9 +519,14 @@ function coverImgTransform() {
519
519
  }
520
520
  try {
521
521
  const realPath = import_node_path3.default.join(vitepressConfig.root, cover);
522
+ if (!(0, import_node_fs2.existsSync)(realPath)) {
523
+ continue;
524
+ }
522
525
  const fileBuffer = (0, import_node_fs2.readFileSync)(realPath);
523
- const matchAsset = assetsMap.find((v) => import_node_buffer.Buffer.compare(fileBuffer, v.source));
524
- page.meta.cover = joinPath("/", matchAsset.fileName);
526
+ const matchAsset = assetsMap.find((v) => import_node_buffer.Buffer.compare(fileBuffer, v.source) === 0);
527
+ if (matchAsset) {
528
+ page.meta.cover = joinPath("/", matchAsset.fileName);
529
+ }
525
530
  } catch (e) {
526
531
  vitepressConfig.logger.warn(e?.message);
527
532
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sugarat/theme",
3
- "version": "0.2.13",
3
+ "version": "0.2.14",
4
4
  "description": "简约风的 Vitepress 博客主题,sugarat vitepress blog theme",
5
5
  "author": "sugar",
6
6
  "license": "MIT",
@@ -1,7 +1,7 @@
1
1
  import path from 'node:path'
2
2
  import { execSync } from 'node:child_process'
3
3
  import process from 'node:process'
4
- import { readFileSync } from 'node:fs'
4
+ import { existsSync, readFileSync } from 'node:fs'
5
5
  import { Buffer } from 'node:buffer'
6
6
  import type { SiteConfig } from 'vitepress'
7
7
 
@@ -153,9 +153,14 @@ export function coverImgTransform() {
153
153
  try {
154
154
  // 寻找构建后的
155
155
  const realPath = path.join(vitepressConfig.root, cover)
156
+ if (!existsSync(realPath)) {
157
+ continue
158
+ }
156
159
  const fileBuffer = readFileSync(realPath)
157
- const matchAsset = assetsMap.find(v => Buffer.compare(fileBuffer, v.source))
158
- page.meta.cover = joinPath('/', matchAsset.fileName)
160
+ const matchAsset = assetsMap.find(v => Buffer.compare(fileBuffer, v.source) === 0)
161
+ if (matchAsset) {
162
+ page.meta.cover = joinPath('/', matchAsset.fileName)
163
+ }
159
164
  }
160
165
  catch (e: any) {
161
166
  vitepressConfig.logger.warn(e?.message)