From b5d47b9600be59381efbb893da52cebc759fc863 Mon Sep 17 00:00:00 2001 From: Achuan-2 Date: Tue, 26 Aug 2025 21:04:29 +0800 Subject: [PATCH 1/4] :recycle: Refactor week number calculation to include ISO year (#15680) --- kernel/api/icon.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/kernel/api/icon.go b/kernel/api/icon.go index 58466bfea..aa244f075 100644 --- a/kernel/api/icon.go +++ b/kernel/api/icon.go @@ -18,7 +18,6 @@ package api import ( "fmt" - "github.com/siyuan-note/siyuan/kernel/util" "math" "net/http" "regexp" @@ -26,6 +25,8 @@ import ( "strings" "time" + "github.com/siyuan-note/siyuan/kernel/util" + "github.com/gin-gonic/gin" "github.com/siyuan-note/siyuan/kernel/model" ) @@ -238,8 +239,8 @@ func getDateInfo(dateStr string, lang string, weekdayType string) map[string]int weekdayStr = date.Format("Mon") } } - // Calculate week number - _, weekNum := date.ISOWeek() + // Calculate week number and ISO year + isoYear, weekNum := date.ISOWeek() weekNumStr := fmt.Sprintf("%dW", weekNum) switch lang { @@ -259,6 +260,7 @@ func getDateInfo(dateStr string, lang string, weekdayType string) map[string]int return map[string]interface{}{ "year": year, + "isoYear": isoYear, "month": month, "day": day, "date": fmt.Sprintf("%02d-%02d", date.Month(), date.Day()), @@ -399,7 +401,7 @@ func generateTypeFiveSVG(color string, lang string, dateInfo map[string]interfac %d %s - `, colorScheme.Primary, colorScheme.Secondary, dateInfo["year"], dateInfo["week"]) + `, colorScheme.Primary, colorScheme.Secondary, dateInfo["isoYear"], dateInfo["week"]) } // Type 6: 仅显示星期 From d445163b2f440147c4ccc8575c06cadfba0edc63 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Tue, 26 Aug 2025 21:16:15 +0800 Subject: [PATCH 2/4] :art: Clean code --- kernel/api/icon.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/api/icon.go b/kernel/api/icon.go index aa244f075..c0d56123d 100644 --- a/kernel/api/icon.go +++ b/kernel/api/icon.go @@ -25,10 +25,9 @@ import ( "strings" "time" - "github.com/siyuan-note/siyuan/kernel/util" - "github.com/gin-gonic/gin" "github.com/siyuan-note/siyuan/kernel/model" + "github.com/siyuan-note/siyuan/kernel/util" ) type ColorScheme struct { From d684bb41b17fcbe2943070c98a6ea670e9eb010e Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Tue, 26 Aug 2025 21:16:34 +0800 Subject: [PATCH 3/4] :art: New template functions `ISOYear` and `ISOMonth` https://github.com/siyuan-note/siyuan/issues/15679 --- kernel/filesys/template.go | 2 ++ kernel/util/time.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/kernel/filesys/template.go b/kernel/filesys/template.go index 9acaa54fc..3184da077 100644 --- a/kernel/filesys/template.go +++ b/kernel/filesys/template.go @@ -44,6 +44,8 @@ func BuiltInTemplateFuncs() (ret template.FuncMap) { ret["WeekdayCN"] = util.WeekdayCN ret["WeekdayCN2"] = util.WeekdayCN2 ret["ISOWeek"] = util.ISOWeek + ret["ISOYear"] = util.ISOYear + ret["ISOMonth"] = util.ISOMonth ret["pow"] = pow ret["powf"] = powf ret["log"] = log diff --git a/kernel/util/time.go b/kernel/util/time.go index bd9fad5ea..5a49b88d6 100644 --- a/kernel/util/time.go +++ b/kernel/util/time.go @@ -62,6 +62,21 @@ func ISOWeek(date time.Time) int { return week } +// ISOYear returns the ISO 8601 year in which date occurs. +func ISOYear(date time.Time) int { + year, _ := date.ISOWeek() + return year +} + +// ISOMonth returns the month in which the first day of the ISO 8601 week of date occurs. +func ISOMonth(date time.Time) int { + year, week := date.ISOWeek() + // ISO 8601 week starts from Monday + isoWeekStart := time.Date(year, 0, (week-1)*7+ + 1-(int(time.Date(year, 0, (week-1)*7+1, 0, 0, 0, 0, time.Local).Weekday())+6)%7, 0, 0, 0, 0, time.Local) + return int(isoWeekStart.Month()) +} + func Millisecond2Time(t int64) time.Time { sec := t / 1000 msec := t % 1000 From dcefed26ebdd49548ac35bd53475dd694098bfa9 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Tue, 26 Aug 2025 22:13:22 +0800 Subject: [PATCH 4/4] :art: Improve `Add to Database` https://github.com/siyuan-note/siyuan/issues/10659 --- kernel/model/attribute_view.go | 72 ++++++++++++++-------------------- 1 file changed, 29 insertions(+), 43 deletions(-) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index c1c5c7e61..12bf96965 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -1263,7 +1263,12 @@ func SearchAttributeView(keyword string, excludeAvIDs []string) (ret []*AvSearch logging.LogErrorf("read directory [%s] failed: %s", avDir, err) return } + avBlockRels := av.GetBlockRels() + if 1 > len(avBlockRels) { + return + } + for _, entry := range entries { if entry.IsDir() { continue @@ -1322,48 +1327,29 @@ func SearchAttributeView(keyword string, excludeAvIDs []string) (ret []*AvSearch if 12 <= len(avSearchTmpResults) { avSearchTmpResults = avSearchTmpResults[:12] } - var avIDs []string - for _, a := range avSearchTmpResults { - avIDs = append(avIDs, a.AvID) - } - var blockIDs []string - for _, bIDs := range avBlockRels { - blockIDs = append(blockIDs, bIDs...) - } - blockIDs = gulu.Str.RemoveDuplicatedElem(blockIDs) - - trees := filesys.LoadTrees(blockIDs) - hitAttrViews := map[string]bool{} - for _, blockID := range blockIDs { - tree := trees[blockID] - if nil == tree { - continue - } - - node := treenode.GetNodeInTree(tree, blockID) - if nil == node || "" == node.AttributeViewID { - continue - } - - avID := node.AttributeViewID - var existAv *AvSearchTempResult - for _, tmpResult := range avSearchTmpResults { - if tmpResult.AvID == avID { - existAv = tmpResult - break + for _, tmpResult := range avSearchTmpResults { + bIDs := avBlockRels[tmpResult.AvID] + var node *ast.Node + for _, bID := range bIDs { + tree, _ := LoadTreeByBlockID(bID) + if nil == tree { + continue } + + node = treenode.GetNodeInTree(tree, bID) + if nil == node || "" == node.AttributeViewID { + continue + } + + break } - if nil == existAv || gulu.Str.Contains(avID, excludeAvIDs) { + + if nil == node { continue } - if hitAttrViews[avID] { - continue - } - hitAttrViews[avID] = true - - attrView, _ := av.ParseAttributeView(avID) + attrView, _ := av.ParseAttributeView(tmpResult.AvID) if nil == attrView { continue } @@ -1378,27 +1364,27 @@ func SearchAttributeView(keyword string, excludeAvIDs []string) (ret []*AvSearch hPath = box.Name + hPath } - name := existAv.AvName + name := tmpResult.AvName if "" == name { name = Conf.language(267) } parent := &AvSearchResult{ - AvID: avID, - AvName: existAv.AvName, - BlockID: blockID, + AvID: tmpResult.AvID, + AvName: tmpResult.AvName, + BlockID: node.ID, HPath: hPath, } ret = append(ret, parent) for _, view := range attrView.Views { child := &AvSearchResult{ - AvID: avID, - AvName: existAv.AvName, + AvID: tmpResult.AvID, + AvName: tmpResult.AvName, ViewName: view.Name, ViewID: view.ID, ViewLayout: view.LayoutType, - BlockID: blockID, + BlockID: node.ID, HPath: hPath, } parent.Children = append(parent.Children, child)