这是我的Template模板
![[<% tp.date.weekday(“YYYY-MM-DD”,0)%>]]
![[<% tp.date.weekday(“YYYY-MM-DD”,1)%>]]
这是显示内容
我想可以控制显示内容的字数
这是我的Template模板
![[<% tp.date.weekday(“YYYY-MM-DD”,0)%>]]
![[<% tp.date.weekday(“YYYY-MM-DD”,1)%>]]
这是显示内容
我想可以控制显示内容的字数
加个css控制嵌入的最大高度
刚好前几天折腾了一个,希望对你有帮助
<%*
const year = await tp.system.prompt("请输入年份:");
const month = await tp.system.prompt("请输入月份:");
const monthStart = moment().year(year).month(month - 1).startOf('month');
const monthEnd = moment().year(year).month(month - 1).endOf('month');
const folderPath = "90.日记";
let output = `| 日期 | 工作 | 日常 |\n| ---- | ---- | ---- |\n`;
let hasData = false; // 数据标志
const files = await app.vault.getFiles();
let rows = []; // 存储表格行的数组
for (const file of files) {
const fileDate = moment(file.name, "YYYY-MM-DD");
if (file.path.startsWith(folderPath) && fileDate.isBetween(monthStart, monthEnd, null, '[]')) {
const fileData = await app.vault.read(file);
const lines = fileData.split('\n');
let work = [], daily = [];
let currentCategory = null;
for (const line of lines) {
const level = line.match(/^(#+)/);
const title = line.replace(/^#+\s*/, '').trim();
if (level) {
const headingLevel = level[0].length;
if (headingLevel === 1 && ['工作', '日常'].includes(title)) {
currentCategory = title;
} else if (headingLevel >= 2 && headingLevel <= 6 && currentCategory) {
if (currentCategory === '工作') {
work.push(title);
} else if (currentCategory === '日常') {
daily.push(title);
}
}
}
}
if (work.length > 0 || daily.length > 0) {
hasData = true;
const dayOfWeek = fileDate.format('dddd');
rows.push({
date: fileDate.format("YYYY-MM-DD"),
day: dayOfWeek,
work: work.join('<br>').replace(/\|/g, '\\|'),
daily: daily.join('<br>').replace(/\|/g, '\\|')
});
}
}
}
// 按日期升序排序
rows.sort((a, b) => moment(a.date).diff(moment(b.date)));
for (const row of rows) {
output += `| [[${row.date}]] (${row.day}) | ${row.work} | ${row.daily} |\n`;
}
if (!hasData) {
output = "这个月啥都没干";
}
%>
<% '# ' + year + '年' + month + '月' %>
## 1.当月总览
<% output %>
## 2.当月总结