[fix] format the code
This commit is contained in:
@@ -14,4 +14,4 @@ export const PostURL = (postId: string) => `https://${Config.SiteDomain}/blog/${
|
||||
export const SearchURL = (keyword: string) => `https://${Config.SiteDomain}/search/?q=${keyword}`;
|
||||
|
||||
const year = getCurrentTime().year;
|
||||
export const CopyrightAnnouncement = `COPYRIGHT © ${Config.YearStart}-${year} ${Config.AuthorName} ALL RIGHTS RESERVED`;
|
||||
export const CopyrightAnnouncement = `COPYRIGHT © ${Config.YearStart === year ? year : `${Config.YearStart}-${year}`} ${Config.AuthorName} ALL RIGHTS RESERVED`;
|
||||
|
||||
@@ -77,7 +77,7 @@ export const Config: TConfig = {
|
||||
},
|
||||
|
||||
// Website establishment year.
|
||||
YearStart: 2023,
|
||||
YearStart: "2023",
|
||||
// Please enter your legal name for use with the copyright mark.
|
||||
AuthorName: "JOHN DOE",
|
||||
};
|
||||
|
||||
28
lib/date.ts
28
lib/date.ts
@@ -2,10 +2,10 @@
|
||||
* Convert the date format of YYYY-MM-DD to American writing
|
||||
* @param date The date in format of YYYY-MM-DD.
|
||||
*/
|
||||
export const normalizeDate = (date: string = "1970-01-01"): string => {
|
||||
let [year, month, day] = date.split("-");
|
||||
let month_num = parseInt(month);
|
||||
let day_num = parseInt(day);
|
||||
export const normalizeDate = (date = "1970-01-01"): string => {
|
||||
const [year, month, day] = date.split("-");
|
||||
const month_num = Number.parseInt(month);
|
||||
const day_num = Number.parseInt(day);
|
||||
const month_en: {
|
||||
[index: number]: string;
|
||||
} = {
|
||||
@@ -43,3 +43,23 @@ export const getCurrentTime = (): {
|
||||
seconds: String(today.getSeconds()).padStart(2, "0"),
|
||||
};
|
||||
};
|
||||
|
||||
export const convertDateToISO8601 = (dateString: string, timezoneOffset = 8): string => {
|
||||
const date = new Date(dateString);
|
||||
|
||||
const offsetHours = timezoneOffset;
|
||||
const offsetMinutes = offsetHours * 60;
|
||||
|
||||
date.setMinutes(date.getMinutes() + offsetMinutes);
|
||||
|
||||
const isoString = date.toISOString();
|
||||
|
||||
const datePart = isoString.split("T")[0];
|
||||
const timePart = "00:00:00";
|
||||
|
||||
const offsetSign = offsetHours >= 0 ? "+" : "-";
|
||||
const absOffsetHours = Math.abs(offsetHours).toString().padStart(2, "0");
|
||||
const offsetString = `${offsetSign}${absOffsetHours}:00`;
|
||||
|
||||
return `${datePart}T${timePart}${offsetString}`;
|
||||
};
|
||||
|
||||
@@ -37,14 +37,15 @@ async function extractFrontmatters(filepath: string): Promise<TFrontmatter> {
|
||||
|
||||
function readPostsDirectory(): string[] {
|
||||
const result: string[] = [];
|
||||
fs.readdirSync(PostFilesDirectory).forEach((fileName) => {
|
||||
const files = fs.readdirSync(PostFilesDirectory);
|
||||
|
||||
for (const fileName of files) {
|
||||
const filePath = path.join(PostFilesDirectory, fileName);
|
||||
const fileStat = fs.statSync(filePath);
|
||||
|
||||
if (fileStat.isFile() && fileName.endsWith(".md")) {
|
||||
result.push(filePath);
|
||||
}
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,6 @@ export type TConfig = {
|
||||
Crypto?: { Name: string; Address: string; Blockchain: string }[];
|
||||
};
|
||||
|
||||
YearStart: number;
|
||||
YearStart: string;
|
||||
AuthorName: string;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user