Skip to content

Commit

Permalink
Merge pull request tangly1024#2703 from tangly1024/release/4.7.0
Browse files Browse the repository at this point in the history
打包修复
  • Loading branch information
tangly1024 authored Sep 5, 2024
2 parents 9561567 + 66166f7 commit f1757c7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion components/OpenWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function existedWhiteList(path, whiteListStr) {
// 移除查询参数(从 '?' 开始的部分)和 `.html` 后缀
const processedPath = path
.replace(/\?.*$/, '') // 移除查询参数
.replace(/.*\/([^\/]+)(?:\.html)?$/, '$1') // 去掉前面的路径和 .html
.replace(/.*\/([^/]+)(?:\.html)?$/, '$1') // 去掉前面的路径和 .html

// 严格检查白名单字符串中是否包含处理后的 path
// const whiteListArray = whiteListStr.split(',')
Expand Down
28 changes: 20 additions & 8 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,26 @@ const locales = (function () {
})()

// 编译前执行
// const preBuild = (function () {
// // 删除 public/sitemap.xml 文件 ; 否则会和/pages/sitemap.xml.js 冲突。
// const sitemapPath = path.resolve(__dirname, 'public', 'sitemap.xml')
// if (fs.existsSync(sitemapPath)) {
// fs.unlinkSync(sitemapPath)
// console.log('Deleted existing sitemap.xml from public directory')
// }
// })()
const preBuild = (function () {
if (
!process.env.npm_lifecycle_event === 'export' &&
!process.env.npm_lifecycle_event === 'build'
) {
return
}
// 删除 public/sitemap.xml 文件 ; 否则会和/pages/sitemap.xml.js 冲突。
const sitemapPath = path.resolve(__dirname, 'public', 'sitemap.xml')
if (fs.existsSync(sitemapPath)) {
fs.unlinkSync(sitemapPath)
console.log('Deleted existing sitemap.xml from public directory')
}

const sitemap2Path = path.resolve(__dirname, 'sitemap.xml')
if (fs.existsSync(sitemap2Path)) {
fs.unlinkSync(sitemap2Path)
console.log('Deleted existing sitemap.xml from root directory')
}
})()

/**
* 扫描指定目录下的文件夹名,用于获取所有主题
Expand Down

0 comments on commit f1757c7

Please sign in to comment.