<%*
const files = tp.app.vault.getMarkdownFiles();
const today = tp.date.now(“YYYYMMDD”);

let maxNumber = 0;

for (const file of files) {
const cache = tp.app.metadataCache.getFileCache(file);
const fm = cache?.frontmatter;

if (!fm) continue;

const values = [  
    fm.postId,  
    fm.commentKey,  
    fm.url  
];

for (const value of values) {  
    if (value === undefined || value === null) continue;

    const text = String(value);  
    const match = text.match(/lsb-(\d{8})-(\d+)/);

    if (!match || match[1] !== today) continue;

    const number = parseInt(match[2], 10);

    if (!isNaN(number) && number > maxNumber) {  
        maxNumber = number;  
    }  
}  

}

const nextNumber = maxNumber + 1;
const sequence = String(nextNumber).padStart(4, “0”);

const postId = lsb-${today}-${sequence};
-%>

title:
source:
author:

  • 李硕
    date:
    description:
    tags:
  • 博客
    summary:
    categories:
  • 博客
    isNote: false
    hiddenInHomeList: false
    personal: false
    searchHidden: false
    postId: “<% postId %>”
    commentKey: “<% postId %>”
    url: “/posts/<% postId %>/”