-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
2,561 additions
and
39 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -36,4 +36,5 @@ vendor | |
zhi.js | ||
dist-cjs | ||
*.d.ts | ||
*.map | ||
*.map | ||
styles/**/**.css |
This file contains 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 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 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 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 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,129 @@ | ||
/* | ||
* Copyright (c) 2023, Terwer . All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Terwer designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Terwer in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com | ||
* or visit www.terwer.space if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
/** | ||
* 时间处理工具类 | ||
* | ||
* @author terwer | ||
* @since 1.0.0 | ||
*/ | ||
class DateUtil { | ||
private readonly TIME_SPLIT = " " | ||
|
||
/** | ||
* 给日期添加小时 | ||
* @param date | ||
* @param numOfHours | ||
* @returns {*} | ||
* | ||
* @author terwer | ||
* @since 1.0.0 | ||
*/ | ||
private addHoursToDate(date: Date, numOfHours: number): Date { | ||
date.setTime(date.getTime() + numOfHours * 60 * 60 * 1000) | ||
return date | ||
} | ||
|
||
/** | ||
* 转换ISO日期为中文日期 | ||
* | ||
* @param str '2022-07-18T06:25:48.000Z | ||
* @param isAddTimeZone 是否增加时区(默认不增加) | ||
* @param isShort 是否只返回日期 | ||
* @returns {string|*} | ||
* @author terwer | ||
* @since 1.0.0 | ||
*/ | ||
public formatIsoToZhDate = ( | ||
str: string, | ||
isAddTimeZone?: boolean, | ||
isShort?: boolean | ||
): string => { | ||
if (!str) { | ||
return "" | ||
} | ||
let newstr = str | ||
|
||
// https://www.regextester.com/112232 | ||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match | ||
const isoDateRegex = | ||
/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(.\d{3})Z$/gm | ||
const matches = newstr.match(isoDateRegex) | ||
if (matches == null) { | ||
return str | ||
} | ||
for (let i = 0; i < matches.length; i++) { | ||
const match = matches[i] | ||
|
||
let newmatch = match | ||
if (isAddTimeZone) { | ||
// ISO日期默认晚8小时 | ||
// logUtil.logInfo(addHoursToDate(new Date(match), 8)) | ||
newmatch = this.addHoursToDate(new Date(match), 8).toISOString() | ||
} | ||
|
||
const dts = newmatch.split("T") | ||
const d = dts[0] | ||
const t = dts[1].split(".")[0] | ||
|
||
let result = d + this.TIME_SPLIT + t | ||
if (isShort) { | ||
result = d | ||
} | ||
|
||
newstr = newstr.replace(match, result) | ||
// logUtil.logInfo("formatZhDate match=>", match) | ||
// logUtil.logInfo("formatZhDate result=>", result) | ||
} | ||
|
||
// logUtil.logInfo("formatZhDate=>", newstr) | ||
return newstr | ||
} | ||
|
||
/** | ||
* 当前日期时间完整格式,格式:2023-03-10 02:03:43 | ||
*/ | ||
public nowZh() { | ||
return this.formatIsoToZhDate(new Date().toISOString()) | ||
} | ||
|
||
/** | ||
* 当前日期,格式:2023-03-10 | ||
*/ | ||
public nowDateZh() { | ||
return this.formatIsoToZhDate(new Date().toISOString(), true, true) | ||
} | ||
|
||
/** | ||
* 当前时间,格式:02:03:43 | ||
*/ | ||
public nowTimeZh() { | ||
const now = this.formatIsoToZhDate(new Date().toISOString(), true) | ||
return now.split(this.TIME_SPLIT)[1] | ||
} | ||
} | ||
|
||
const dateUtil = new DateUtil() | ||
export default dateUtil |
This file contains 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,3 @@ | ||
/* 博客主题首页入口 */ | ||
@require "../common/vars/vars-blog" | ||
@require "./default/main.styl" |
This file contains 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,2 @@ | ||
body | ||
margin: 0 auto |
This file contains 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,14 @@ | ||
/* -------------------------------------------------颜色定义-暗黑模式--------------------------------------------------- */ | ||
html[data-theme-mode="dark"] | ||
--zhi-body-bg: _body-bg-dark | ||
--zhi-main-bg: _main-bg-dark | ||
--zhi-sidebar-bg: _sidebar-bg-dark | ||
//--zhi-blur-bg: _blur-bg-dark | ||
//--zhi-custom-block-bg: _custom-block-bg-dark | ||
--zhi-primary-color: _primary-color-dark | ||
--zhi-text-color: _text-color-dark | ||
//--zhi-text-lighten-color: _text-lighten-color-dark | ||
--zhi-border-color: _border-color-dark | ||
//--zhi-code-bg: _code-bg-dark | ||
//--zhi-code-color: _code-color-dark | ||
--zhi-list-hover: _list-hover-dark |
This file contains 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,14 @@ | ||
/* -------------------------------------------------颜色定义-阅读模式--------------------------------------------------- */ | ||
html[data-theme-mode="green"] | ||
--zhi-body-bg: _body-bg-green | ||
--zhi-main-bg: _main-bg-green | ||
--zhi-sidebar-bg: _sidebar-bg-green | ||
//--zhi-blur-bg: _blur-bg-green | ||
//--zhi-custom-block-bg: _custom-block-bg-green | ||
--zhi-primary-color: _primary-color-green | ||
--zhi-text-color: _text-color-green | ||
//--zhi-text-lighten-color: _text-lighten-color-green | ||
--zhi-border-color: _border-color-green | ||
//--zhi-code-bg: _code-bg-green | ||
//--zhi-code-color: _code-color-green | ||
--zhi-list-hover: _list-hover-green |
This file contains 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,14 @@ | ||
/* -------------------------------------------------颜色定义-浅色模式--------------------------------------------------- */ | ||
html[data-theme-mode="light"] | ||
--zhi-body-bg: _body-bg-light | ||
--zhi-main-bg: _main-bg-light | ||
--zhi-sidebar-bg: _sidebar-bg-light | ||
//--zhi-blur-bg: _blur-bg-light | ||
//--zhi-custom-block-bg: _custom-block-bg-light | ||
--zhi-primary-color: _primary-color-light | ||
--zhi-text-color: _text-color-light | ||
//--zhi-text-lighten-color: _text-lighten-color-light | ||
--zhi-border-color: _border-color-light | ||
//--zhi-code-bg: _code-bg-light | ||
//--zhi-code-color: _code-color-light | ||
--zhi-list-hover: _list-hover-light |
Oops, something went wrong.