Skip to content

Commit

Permalink
fix: utc -number invalid date
Browse files Browse the repository at this point in the history
  • Loading branch information
ATQQ committed Sep 13, 2024
1 parent 83f24f1 commit 45a4bdc
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 16 deletions.
6 changes: 6 additions & 0 deletions packages/blogpress/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
pagefind-indexed: false
publish: false
---
## 2.0.59
### Patch Changes

- Updated dependencies
- @sugarat/theme@0.4.12

## 2.0.58

### Patch Changes

- Updated dependencies
Expand Down
2 changes: 1 addition & 1 deletion packages/blogpress/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "blogpress",
"type": "module",
"version": "2.0.58",
"version": "2.0.59",
"private": true,
"license": "MIT",
"scripts": {
Expand Down
10 changes: 9 additions & 1 deletion packages/create-theme/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
# @sugarat/create-theme

## 0.0.77

### Patch Changes

- fix: utc error date

## 0.0.76

### Patch Changes

- chore: use theme@0.4.11
- chore: use vitepress@1.3.4

## 0.0.75

### Patch Changes

- chore: use theme@0.4.10

## 0.0.74

### Patch Changes
- chore: use theme@0.4.9

- chore: use theme@0.4.9

## 0.0.73

Expand Down
2 changes: 1 addition & 1 deletion packages/create-theme/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sugarat/create-theme",
"version": "0.0.76",
"version": "0.0.77",
"description": "简约风的 Vitepress 博客主题,sugarat vitepress blog theme",
"author": "粥里有勺糖",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-theme/public/template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"dependencies": {
"@element-plus/icons-vue": "^2.3.1",
"@sugarat/theme": "^0.4.11",
"@sugarat/theme": "^0.4.12",
"element-plus": "^2.7.2",
"vue": "3.4.26"
},
Expand Down
6 changes: 6 additions & 0 deletions packages/theme/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @sugarat/theme

## 0.4.12

### Patch Changes

- fix: utc -number invalid date

## 0.4.11

### Patch Changes
Expand Down
6 changes: 6 additions & 0 deletions packages/theme/docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ bun install vitepress@latest
```
:::

## 0.4.12 (2024/09/13)

### Patch Changes

- fix: utc -number invalid date

## 0.4.11 (2024/09/08)

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/theme/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sugarat/theme",
"version": "0.4.11",
"version": "0.4.12",
"description": "简约风的 Vitepress 博客主题,sugarat vitepress blog theme",
"author": "sugar",
"license": "MIT",
Expand Down
23 changes: 12 additions & 11 deletions packages/theme/src/utils/node/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,18 @@ export async function getArticleMeta(filepath: string, route: string, timeZone =
if (!meta.title) {
meta.title = getDefaultTitle(content)
}
const utcValue = timeZone >= 0 ? `+${timeZone}` : `${timeZone}`
const date = await (
(meta.date
&& new Date(`${new Date(meta.date).toUTCString()}+${timeZone}`))
|| getFileLastModifyTime(filepath)
&& new Date(`${new Date(meta.date).toUTCString()}${utcValue}`))
|| getFileLastModifyTime(filepath)
)
// 无法获取时兜底当前时间
meta.date = formatDate(date || new Date())

// 处理tags和categories,兼容历史文章
meta.categories
= typeof meta.categories === 'string'
= typeof meta.categories === 'string'
? [meta.categories]
: meta.categories
meta.tags = typeof meta.tags === 'string' ? [meta.tags] : meta.tags
Expand All @@ -66,12 +67,12 @@ export async function getArticleMeta(filepath: string, route: string, timeZone =
// 获取摘要信息
// TODO:摘要生成优化
meta.description
= meta.description || getTextSummary(content, 100) || excerpt
= meta.description || getTextSummary(content, 100) || excerpt

// 获取封面图
meta.cover
= meta.cover
?? (getFirstImagURLFromMD(fileContent, route))
= meta.cover
?? (getFirstImagURLFromMD(fileContent, route))

// 是否发布 默认发布
if (meta.publish === false) {
Expand All @@ -82,9 +83,9 @@ export async function getArticleMeta(filepath: string, route: string, timeZone =
}
export async function getArticles(cfg: Partial<Theme.BlogConfig>, vpConfig: SiteConfig) {
const srcDir
= cfg?.srcDir || vpConfig.srcDir.replace(vpConfig.root, '').replace(/^\//, '')
|| process.argv.slice(2)?.[1]
|| '.'
= cfg?.srcDir || vpConfig.srcDir.replace(vpConfig.root, '').replace(/^\//, '')
|| process.argv.slice(2)?.[1]
|| '.'
const files = glob.sync(`${srcDir}/**/*.md`, { ignore: ['node_modules'], absolute: true })

const metaResults = files.reduce((prev, curr) => {
Expand Down Expand Up @@ -124,8 +125,8 @@ export function patchVPConfig(vpConfig: any, cfg?: Partial<Theme.BlogConfig>) {
if (cfg?.comment && 'type' in cfg.comment && cfg?.comment?.type === 'artalk') {
const server = cfg.comment?.options?.server
if (server) {
vpConfig.head.push(['link', { href: `${server}/dist/Artalk.css`, rel: 'stylesheet' }])
vpConfig.head.push(['script', { src: `${server}/dist/Artalk.js`, id: 'artalk-script' }])
vpConfig.head.push(['link', { href: `${server} /dist/Artalk.css`, rel: 'stylesheet' }])
vpConfig.head.push(['script', { src: `${server} /dist/Artalk.js`, id: 'artalk-script' }])
}
}
}
Expand Down

0 comments on commit 45a4bdc

Please sign in to comment.