目前写过最复杂的模板了,按文档名升序排列。
类似模板:【模板】汇总今天更新或指定日期范围的文档 · 语雀 (yuque.com)
注意:使用了 updated 和 created 字段,入围的文档至少在那个时间有创建过新块、改动过文字
上个月更新的文档
.action{/* -------1.获取今年年份和上个月的月份数字------- */}
.action{$this_year :=now | date "2006"}
.action{$this_month :=now | date "01"}
.action{$last_month := sub $this_month 1}
.action{/* 处理月份为两位整数,小于10,则为0x */}
.action{if gt $last_month 10}
.action{/* if语句内如果想要给外部的全局变量赋值,需要用=而不是:=*/}
.action{$last_month = $last_month}
.action{else}
.action{$last_month = nospace (cat "0" $last_month)}
.action{end}
.action{/* -------2.判断今年是否为闰年,得到这个月的最后一天------- */}
.action{/* 2.1判断闰年,相当于if year % 4 == 0 and year % 100 != 0 or year % 400 == 0 */}
.action{$is_leap := any (all (empty (mod $this_year 4)) (not (empty (mod $this_year 100)))) (empty (mod $this_year 400))}
.action{$MonthDict1 := dict "01" "31" "02" "28" "03" "31" "04" "30" "05" "31" "06" "30" "07" "31" "08" "31" "09" "30" "10" "31" "11" "30" "12" "31"}
.action{$MonthDict2 := dict "01" "31" "02" "29" "03" "31" "04" "30" "05" "31" "06" "30" "07" "31" "08" "31" "09" "30" "10" "31" "11" "30" "12" "31"}
.action{$Dicts := dict "true" $MonthDict2 "false" $MonthDict1}
.action{$MonthDict := get $Dicts (toString $is_leap)}
.action{/* 2.2得到这个月的最后一天 */}
.action{$last_day := get $MonthDict (toString $last_month)}
.action{$last_month_first :=nospace (cat $this_year "-" $last_month "-01")}
.action{$last_month_last :=nospace (cat $this_year "-" $last_month "-" $last_day)}
.action{/* 2.3格式化这个月的第一天和最后一天 */}
.action{$from:= toDate "2006-01-02 15:04:05" (cat $last_month_first "00:00:00")}
.action{$to := toDate "2006-01-02 15:04:05" (cat $last_month_last "23:59:59")}
.action{/* -------3.获得上个月更新的所有笔记文档------- */}
## .action{$from | date "2006.01.02 Mon"} \~ .action{$to | date "2006.01.02 Mon"} 期间更新的笔记文档
.action{$from:= $from | date "20060102150405"}
.action{$to:= $to | date "20060102150405"}
.action{/* 按文档名升序排列 */}
.action{$blocks :=queryBlocks "SELECT * FROM blocks WHERE id in (SELECT root_id FROM blocks WHERE root_id != '?' AND (created >= '?' AND created <= '?' OR updated >= '?' AND updated <= '?') ) order by HPath LIMIT -1" .id $from $to $from $to }
.action{range $v := $blocks}
- [.action{$v.HPath}](siyuan://blocks/.action{$v.ID})
.action{end}
某个月更新的文档
.action{/* 设置想查询的年份和月份 */}
.action{$this_year := 2021}
.action{$this_month := 7}
.action{/* -------1.获取今年年份和上个月的月份数字------- */}
.action{/* 处理月份为两位整数,小于10,则为0x */}
.action{if gt $this_month 10}
.action{/* if语句内如果想要给外部的全局变量赋值,需要用=而不是:=*/}
.action{$this_month = $this_month}
.action{else}
.action{$this_month = nospace (cat "0" $this_month)}
.action{end}
.action{/* -------2.判断今年是否为闰年,得到这个月的最后一天------- */}
.action{/* 2.1判断闰年,相当于if year % 4 == 0 and year % 100 != 0 or year % 400 == 0 */}
.action{$is_leap := any (all (empty (mod $this_year 4)) (not (empty (mod $this_year 100)))) (empty (mod $this_year 400))}
.action{$MonthDict1 := dict "01" "31" "02" "28" "03" "31" "04" "30" "05" "31" "06" "30" "07" "31" "08" "31" "09" "30" "10" "31" "11" "30" "12" "31"}
.action{$MonthDict2 := dict "01" "31" "02" "29" "03" "31" "04" "30" "05" "31" "06" "30" "07" "31" "08" "31" "09" "30" "10" "31" "11" "30" "12" "31"}
.action{$Dicts := dict "true" $MonthDict2 "false" $MonthDict1}
.action{$MonthDict := get $Dicts (toString $is_leap)}
.action{/* 2.2得到这个月的最后一天 */}
.action{$last_day := get $MonthDict (toString $this_month)}
.action{$this_month_first :=nospace (cat $this_year "-" $this_month "-01")}
.action{$this_month_last :=nospace (cat $this_year "-" $this_month "-" $last_day)}
.action{/* 2.3格式化这个月的第一天和最后一天 */}
.action{$from:= toDate "2006-01-02 15:04:05" (cat $this_month_first "00:00:00")}
.action{$to := toDate "2006-01-02 15:04:05" (cat $this_month_last "23:59:59")}
.action{/* -------3.获得上个月更新的所有笔记文档------- */}
## .action{$from | date "2006.01.02 Mon"} \~ .action{$to | date "2006.01.02 Mon"} 期间更新的笔记文档
.action{$from:= $from | date "20060102150405"}
.action{$to:= $to | date "20060102150405"}
.action{/* 按文档名升序排列 */}
.action{$blocks :=queryBlocks "SELECT * FROM blocks WHERE id in (SELECT root_id FROM blocks WHERE root_id != '?' AND (created >= '?' AND created <= '?' OR updated >= '?' AND updated <= '?') ) order by HPath LIMIT -1" .id $from $to $from $to }
.action{range $v := $blocks}
- [.action{$v.HPath}](siyuan://blocks/.action{$v.ID})
.action{end}
某一范围更新的文档
.action{/* 在这里更新查询的起始时间*/}
.action{$from:= toDate "2006-01-02 15:04:05" "2022-03-01 00:00:00"}
.action{$to := toDate "2006-01-02 15:04:05" "2022-03-31 23:59:59"}
## .action{$from | date "2006.01.02 Mon"} \~ .action{$to | date "2006.01.02 Mon"} 期间更新的笔记文档
.action{$from:= $from | date "20060102150405"}
.action{$to:= $to | date "20060102150405"}
.action{/* 按文档名升序排列 */}
.action{$blocks :=queryBlocks "SELECT * FROM blocks WHERE id in (SELECT root_id FROM blocks WHERE root_id != '?' AND (created >= '?' AND created <= '?' OR updated >= '?' AND updated <= '?') ) order by HPath LIMIT -1" .id $from $to $from $to }
.action{range $v := $blocks}
- [.action{$v.HPath}](siyuan://blocks/.action{$v.ID})
.action{end}
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于