-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: 新增动态页 #494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: 新增动态页 #494
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7f17cef
feat: 新增动态页
CuteLeaf f1ca596
feat: 新增动态组件及相关配置,支持最新动态展示
CuteLeaf 0300b57
feat: 更新音乐播放器配置
CuteLeaf 69c6d67
feat: 新增动态统计功能及多语言支持
CuteLeaf 92914f4
feat: 增加时区支持,优化动态内容时间戳格式
CuteLeaf 6c0c289
feat: 新增动态页面配置及相关命令
CuteLeaf 82da76d
feat: 增加动态页面的访问控制,根据配置过滤sitemap
CuteLeaf 713c05d
feat: 更新动态脚本,优化时区处理并修复图片标签,新增测试内容
CuteLeaf 8a4e6cb
feat: 新增动态内容计数显示,优化样式布局
CuteLeaf f877963
feat: 调整导入顺序,优化代码结构
CuteLeaf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* Create a timestamped dynamic markdown file from command-line text. */ | ||
|
|
||
| import fs from "node:fs"; | ||
| import path from "node:path"; | ||
|
|
||
| const content = process.argv.slice(2).join(" ").trim(); | ||
|
|
||
| if (!content) { | ||
| console.error( | ||
| "Error: No dynamic content provided\nUsage: pnpm new-dynamic <content>", | ||
| ); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const now = new Date(); | ||
| const pad = (value) => String(value).padStart(2, "0"); | ||
| const siteConfigSource = fs.readFileSync( | ||
| path.resolve("src/config/siteConfig.ts"), | ||
| "utf8", | ||
| ); | ||
| const timezone = | ||
| siteConfigSource.match(/^\s*timezone:\s*"([^"]+)"/m)?.[1] || | ||
| "Asia/Shanghai"; | ||
| const dateParts = new Intl.DateTimeFormat("en-CA", { | ||
| timeZone: timezone, | ||
| year: "numeric", | ||
| month: "2-digit", | ||
| day: "2-digit", | ||
| hour: "2-digit", | ||
| minute: "2-digit", | ||
| second: "2-digit", | ||
| hourCycle: "h23", | ||
| }) | ||
| .formatToParts(now) | ||
| .reduce((parts, part) => { | ||
| if (part.type !== "literal") parts[part.type] = part.value; | ||
| return parts; | ||
| }, {}); | ||
| const year = dateParts.year; | ||
| const month = dateParts.month; | ||
| const day = dateParts.day; | ||
| const hours = dateParts.hour; | ||
| const minutes = dateParts.minute; | ||
| const seconds = dateParts.second; | ||
| const timestamp = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; | ||
| const fileName = `${year}-${month}-${day}-${hours}${minutes}${seconds}.md`; | ||
| const targetDir = path.resolve("src/content/dynamic"); | ||
| const fullPath = path.join(targetDir, fileName); | ||
|
|
||
| fs.mkdirSync(targetDir, { recursive: true }); | ||
|
|
||
| if (fs.existsSync(fullPath)) { | ||
| console.error(`Error: File ${fullPath} already exists`); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| fs.writeFileSync(fullPath, `---\npublished: ${timestamp}\n---\n\n${content}\n`); | ||
|
|
||
| console.log(`Dynamic ${fullPath} created`); |
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): 由于
identifier和url是通过define:vars注入的常量,重新赋值会失败。因为
define:vars在浏览器中会把这些绑定生成为const,所以在存在requestedPath时重新给identifier和url赋值会抛出Assignment to constant variable,从而阻止 Disqus 初始化。可以改为引入单独的可变本地变量(例如let effectiveIdentifier = identifier; let effectiveUrl = url;),根据requestedPath更新这些变量,并在disqus_config中使用它们,而不是修改注入的常量。Original comment in English
issue (bug_risk): Reassigning
identifierandurlwill fail because they are constants injected viadefine:vars.Because
define:varsemits these bindings asconstin the browser, reassigningidentifierandurlwhenrequestedPathis present will throwAssignment to constant variableand prevent Disqus from initializing. Instead, introduce separate mutable locals (e.g.let effectiveIdentifier = identifier; let effectiveUrl = url;), update those based onrequestedPath, and use them insidedisqus_configrather than modifying the injected constants.