1343
This commit is contained in:
1 parent
4b4387cf57
commit
8ef2f7613f
5 files changed
+4
-30
No files matched your search
@@ -15,7 +15,7 @@ export interface Session {
|
||||
dirPath: string;
|
||||
}
|
||||
|
||||
function computeDirPath(title: string, date?: string): string {
|
||||
function computeDirPath(title: string, date?: string, slug?: string): string {
|
||||
const d = date ? new Date(date) : new Date();
|
||||
const year = d.getFullYear().toString();
|
||||
const dateStr = d.toISOString().slice(0, 10);
|
||||
@@ -23,9 +23,8 @@ function computeDirPath(title: string, date?: string): string {
|
||||
.replace(/[^\w一-鿿㐀-䶿]+/g, "-")
|
||||
.replace(/^-+|-+$/g, "")
|
||||
.toLowerCase() || "post";
|
||||
// 加时间戳避免同标题同天冲突
|
||||
const ts = Date.now().toString(36);
|
||||
return path.join(CONTENT_DIR, year, `${dateStr}-${titlePart}-${ts}`);
|
||||
const uniquePart = slug || Date.now().toString(36);
|
||||
return path.join(CONTENT_DIR, year, `${dateStr}-${titlePart}-${uniquePart}`);
|
||||
}
|
||||
|
||||
const sessions = new Map<number, Session>();
|
||||
@@ -75,7 +74,7 @@ export function undoLastChunk(chatId: number): boolean {
|
||||
export function initSessionDir(chatId: number, title: string, date?: string): void {
|
||||
const s = getSession(chatId);
|
||||
if (!s.dirPath) {
|
||||
s.dirPath = computeDirPath(title, date);
|
||||
s.dirPath = computeDirPath(title, date, s.slug);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user