Repository navigation
fix: 防止清空内容目录后构建仍保留旧动态和项目 - #679
Open
josemims31 wants to merge 1 commit into
Open
josemims31 wants to merge 1 commit into
josemims31 wants to merge 1 commit into
Conversation
fix: refresh content cache during production builds
✅ Deploy Preview for demo-firefly ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
@josemims31 is attempting to deploy a commit to the xiaye's projects Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题与原因
删除全部动态或项目源文件后,再执行
pnpm build,生成的网站仍可能显示旧动态或旧项目。本项目锁定 Astro 7.3.2。该版本的 glob loader 在内容目录存在、但没有匹配文件时会提前 return,跳过后续对旧内容记录的清理。因此,在已有内容缓存的情况下,清空目录后执行普通构建,仍可能从缓存生成已经删除的内容。
相关源码:
https://github.com/withastro/astro/blob/astro%407.3.2/packages/astro/src/content/loaders/glob.ts#L272-L277
https://github.com/withastro/astro/blob/astro%407.3.2/packages/astro/src/content/loaders/glob.ts#L330-L331
修改
在 package.json 的 build 脚本中,将
astro build改为astro build --force。使用 Astro 提供的 --force 参数清除内容缓存,重新根据当前源文件生成内容,保留原有完整构建流程。
这是构建阶段的兼容处理,不涉及依赖升级或 Astro 内部代码修改。代价是每次构建都会重新同步内容,减少内容缓存带来的加速收益。
验证