mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-04 23:16:53 +00:00
Merge pull request #2943 from dongzhenye/feat/version-management
refactor: improve version number management
This commit is contained in:
@@ -1,12 +1,11 @@
|
|||||||
# 环境变量 @see https://www.nextjs.cn/docs/basic-features/environment-variables
|
# 环境变量 @see https://www.nextjs.cn/docs/basic-features/environment-variables
|
||||||
NEXT_PUBLIC_VERSION=4.7.7
|
|
||||||
|
|
||||||
|
|
||||||
# 可在此添加环境变量,去掉最左边的(# )注释即可
|
# 可在此添加环境变量,去掉最左边的(# )注释即可
|
||||||
# Notion页面ID,必须
|
# Notion页面ID,必须
|
||||||
# NOTION_PAGE_ID=097e5f674880459d8e1b4407758dc4fb
|
# NOTION_PAGE_ID=097e5f674880459d8e1b4407758dc4fb
|
||||||
|
|
||||||
# 非必须
|
# 非必须
|
||||||
|
# NEXT_PUBLIC_VERSION=
|
||||||
# NEXT_PUBLIC_PSEUDO_STATIC=
|
# NEXT_PUBLIC_PSEUDO_STATIC=
|
||||||
# NEXT_PUBLIC_REVALIDATE_SECOND=
|
# NEXT_PUBLIC_REVALIDATE_SECOND=
|
||||||
# NEXT_PUBLIC_THEME=matery
|
# NEXT_PUBLIC_THEME=matery
|
||||||
34
.github/pull_request_template.md
vendored
Normal file
34
.github/pull_request_template.md
vendored
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
## 已知问题
|
||||||
|
|
||||||
|
1. (示例)版本号管理不规范
|
||||||
|
- 版本号直接写在环境变量中,容易出错
|
||||||
|
- 多处维护版本号,可能不一致
|
||||||
|
|
||||||
|
## 解决方案
|
||||||
|
|
||||||
|
1. (示例)将版本号管理从 `.env.local` 迁移到 `package.json`
|
||||||
|
- 统一从 `package.json` 读取版本号
|
||||||
|
- 使用 IIFE 优雅处理版本号获取逻辑
|
||||||
|
- 保持向后兼容,支持环境变量覆盖
|
||||||
|
|
||||||
|
## 改动收益
|
||||||
|
|
||||||
|
1. (示例)更规范的版本管理
|
||||||
|
- 统一从 `package.json` 读取
|
||||||
|
- 保持与 npm 生态一致
|
||||||
|
- 减少人为错误
|
||||||
|
|
||||||
|
## 具体改动
|
||||||
|
|
||||||
|
1. (示例)`blog.config.js`
|
||||||
|
- 移除原有的静态版本号配置
|
||||||
|
- 在文件末尾添加动态版本号获取逻辑
|
||||||
|
- 保持向后兼容,优先使用环境变量
|
||||||
|
- 添加错误处理和默认值
|
||||||
|
|
||||||
|
## 测试确认
|
||||||
|
|
||||||
|
- [x] 本地开发环境测试通过
|
||||||
|
- [x] 生产环境构建测试通过
|
||||||
|
- [x] 版本号正确显示
|
||||||
|
- [x] 环境变量配置正常工作
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -25,7 +25,7 @@ yarn-debug.log*
|
|||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
|
|
||||||
# local env files
|
# local env files
|
||||||
# .env.local # 版本号放在此环境变量中
|
.env.local
|
||||||
.env.development.local
|
.env.development.local
|
||||||
.env.test.local
|
.env.test.local
|
||||||
.env.production.local
|
.env.production.local
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
- [Setup](#setup)
|
- [Setup](#setup)
|
||||||
- [Creating new themes](#creating-new-themes)
|
- [Creating new themes](#creating-new-themes)
|
||||||
- [Adding localizations](#adding-localizations)
|
- [Adding localizations](#adding-localizations)
|
||||||
|
- [Environment Variables](#environment-variables)
|
||||||
|
|
||||||
Thanks for considering to contribute!
|
Thanks for considering to contribute!
|
||||||
|
|
||||||
@@ -42,6 +43,19 @@ localization! Follow these steps to add a new localization:
|
|||||||
3. Add your language config to [lang.js][lang.js].
|
3. Add your language config to [lang.js][lang.js].
|
||||||
4. [Create a PR][pr] with your localization updates.
|
4. [Create a PR][pr] with your localization updates.
|
||||||
|
|
||||||
|
## Environment Variables
|
||||||
|
|
||||||
|
NotionNext uses environment variables for configuration. To set up your development environment:
|
||||||
|
|
||||||
|
1. Copy `.env.example` to `.env.local`
|
||||||
|
2. Fill in the required values in `.env.local`
|
||||||
|
3. Never commit `.env.local` to version control
|
||||||
|
|
||||||
|
The configuration priority is:
|
||||||
|
1. Notion Config Table (highest)
|
||||||
|
2. Environment Variables
|
||||||
|
3. blog.config.js (lowest)
|
||||||
|
|
||||||
[fork]: https://github.com/tangly1024/NotionNext/fork
|
[fork]: https://github.com/tangly1024/NotionNext/fork
|
||||||
[pr]: https://github.com/tangly1024/NotionNext/compare
|
[pr]: https://github.com/tangly1024/NotionNext/compare
|
||||||
[next.js]: https://github.com/vercel/next.js
|
[next.js]: https://github.com/vercel/next.js
|
||||||
|
|||||||
@@ -548,7 +548,15 @@ const BLOG = {
|
|||||||
process.env.npm_lifecycle_event === 'export', // 在打包过程中默认开启缓存,开发或运行时开启此功能意义不大。
|
process.env.npm_lifecycle_event === 'export', // 在打包过程中默认开启缓存,开发或运行时开启此功能意义不大。
|
||||||
isProd: process.env.VERCEL_ENV === 'production' || process.env.EXPORT, // distinguish between development and production environment (ref: https://vercel.com/docs/environment-variables#system-environment-variables)
|
isProd: process.env.VERCEL_ENV === 'production' || process.env.EXPORT, // distinguish between development and production environment (ref: https://vercel.com/docs/environment-variables#system-environment-variables)
|
||||||
BUNDLE_ANALYZER: process.env.ANALYZE === 'true' || false, // 是否展示编译依赖内容与大小
|
BUNDLE_ANALYZER: process.env.ANALYZE === 'true' || false, // 是否展示编译依赖内容与大小
|
||||||
VERSION: process.env.NEXT_PUBLIC_VERSION // 版本号
|
VERSION: (() => {
|
||||||
|
try {
|
||||||
|
// 优先使用环境变量,否则从package.json中获取版本号
|
||||||
|
return process.env.NEXT_PUBLIC_VERSION || require('./package.json').version
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Failed to load package.json version:', error)
|
||||||
|
return '1.0.0' // 缺省版本号
|
||||||
|
}
|
||||||
|
})()
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = BLOG
|
module.exports = BLOG
|
||||||
|
|||||||
@@ -19,7 +19,8 @@
|
|||||||
"post-build": "next-sitemap --config next-sitemap.config.js",
|
"post-build": "next-sitemap --config next-sitemap.config.js",
|
||||||
"export": "cross-env EXPORT=true next build && next-sitemap --config next-sitemap.config.js",
|
"export": "cross-env EXPORT=true next build && next-sitemap --config next-sitemap.config.js",
|
||||||
"bundle-report": "cross-env ANALYZE=true next build",
|
"bundle-report": "cross-env ANALYZE=true next build",
|
||||||
"build-all-in-dev": "cross-env VERCEL_ENV=production next build"
|
"build-all-in-dev": "cross-env VERCEL_ENV=production next build",
|
||||||
|
"version": "echo $npm_package_version"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@clerk/localizations": "^3.0.4",
|
"@clerk/localizations": "^3.0.4",
|
||||||
|
|||||||
Reference in New Issue
Block a user