Compare commits

...

4 commits

4 changed files with 51 additions and 47 deletions

View file

@ -18,7 +18,6 @@ package api
import ( import (
"fmt" "fmt"
"github.com/siyuan-note/siyuan/kernel/util"
"math" "math"
"net/http" "net/http"
"regexp" "regexp"
@ -28,6 +27,7 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/siyuan-note/siyuan/kernel/model" "github.com/siyuan-note/siyuan/kernel/model"
"github.com/siyuan-note/siyuan/kernel/util"
) )
type ColorScheme struct { type ColorScheme struct {
@ -238,8 +238,8 @@ func getDateInfo(dateStr string, lang string, weekdayType string) map[string]int
weekdayStr = date.Format("Mon") weekdayStr = date.Format("Mon")
} }
} }
// Calculate week number // Calculate week number and ISO year
_, weekNum := date.ISOWeek() isoYear, weekNum := date.ISOWeek()
weekNumStr := fmt.Sprintf("%dW", weekNum) weekNumStr := fmt.Sprintf("%dW", weekNum)
switch lang { switch lang {
@ -259,6 +259,7 @@ func getDateInfo(dateStr string, lang string, weekdayType string) map[string]int
return map[string]interface{}{ return map[string]interface{}{
"year": year, "year": year,
"isoYear": isoYear,
"month": month, "month": month,
"day": day, "day": day,
"date": fmt.Sprintf("%02d-%02d", date.Month(), date.Day()), "date": fmt.Sprintf("%02d-%02d", date.Month(), date.Day()),
@ -399,7 +400,7 @@ func generateTypeFiveSVG(color string, lang string, dateInfo map[string]interfac
<text transform="translate(22 146.5)" style="fill: #fff;font-size: 120px; font-family: -apple-system, BlinkMacSystemFont, 'Noto Sans', 'Noto Sans CJK SC', 'Microsoft YaHei'; ">%d</text> <text transform="translate(22 146.5)" style="fill: #fff;font-size: 120px; font-family: -apple-system, BlinkMacSystemFont, 'Noto Sans', 'Noto Sans CJK SC', 'Microsoft YaHei'; ">%d</text>
<text x="50%%" y="410.5" style="fill: #66757f;font-size: 200px;text-anchor: middle;font-family: -apple-system, BlinkMacSystemFont, 'Noto Sans', 'Noto Sans CJK SC', 'Microsoft YaHei'; ">%s</text> <text x="50%%" y="410.5" style="fill: #66757f;font-size: 200px;text-anchor: middle;font-family: -apple-system, BlinkMacSystemFont, 'Noto Sans', 'Noto Sans CJK SC', 'Microsoft YaHei'; ">%s</text>
</svg> </svg>
`, colorScheme.Primary, colorScheme.Secondary, dateInfo["year"], dateInfo["week"]) `, colorScheme.Primary, colorScheme.Secondary, dateInfo["isoYear"], dateInfo["week"])
} }
// Type 6: 仅显示星期 // Type 6: 仅显示星期

View file

@ -44,6 +44,8 @@ func BuiltInTemplateFuncs() (ret template.FuncMap) {
ret["WeekdayCN"] = util.WeekdayCN ret["WeekdayCN"] = util.WeekdayCN
ret["WeekdayCN2"] = util.WeekdayCN2 ret["WeekdayCN2"] = util.WeekdayCN2
ret["ISOWeek"] = util.ISOWeek ret["ISOWeek"] = util.ISOWeek
ret["ISOYear"] = util.ISOYear
ret["ISOMonth"] = util.ISOMonth
ret["pow"] = pow ret["pow"] = pow
ret["powf"] = powf ret["powf"] = powf
ret["log"] = log ret["log"] = log

View file

@ -1263,7 +1263,12 @@ func SearchAttributeView(keyword string, excludeAvIDs []string) (ret []*AvSearch
logging.LogErrorf("read directory [%s] failed: %s", avDir, err) logging.LogErrorf("read directory [%s] failed: %s", avDir, err)
return return
} }
avBlockRels := av.GetBlockRels() avBlockRels := av.GetBlockRels()
if 1 > len(avBlockRels) {
return
}
for _, entry := range entries { for _, entry := range entries {
if entry.IsDir() { if entry.IsDir() {
continue continue
@ -1322,48 +1327,29 @@ func SearchAttributeView(keyword string, excludeAvIDs []string) (ret []*AvSearch
if 12 <= len(avSearchTmpResults) { if 12 <= len(avSearchTmpResults) {
avSearchTmpResults = avSearchTmpResults[:12] avSearchTmpResults = avSearchTmpResults[:12]
} }
var avIDs []string
for _, a := range avSearchTmpResults {
avIDs = append(avIDs, a.AvID)
}
var blockIDs []string for _, tmpResult := range avSearchTmpResults {
for _, bIDs := range avBlockRels { bIDs := avBlockRels[tmpResult.AvID]
blockIDs = append(blockIDs, bIDs...) var node *ast.Node
} for _, bID := range bIDs {
blockIDs = gulu.Str.RemoveDuplicatedElem(blockIDs) tree, _ := LoadTreeByBlockID(bID)
if nil == tree {
trees := filesys.LoadTrees(blockIDs) continue
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
} }
node = treenode.GetNodeInTree(tree, bID)
if nil == node || "" == node.AttributeViewID {
continue
}
break
} }
if nil == existAv || gulu.Str.Contains(avID, excludeAvIDs) {
if nil == node {
continue continue
} }
if hitAttrViews[avID] { attrView, _ := av.ParseAttributeView(tmpResult.AvID)
continue
}
hitAttrViews[avID] = true
attrView, _ := av.ParseAttributeView(avID)
if nil == attrView { if nil == attrView {
continue continue
} }
@ -1378,27 +1364,27 @@ func SearchAttributeView(keyword string, excludeAvIDs []string) (ret []*AvSearch
hPath = box.Name + hPath hPath = box.Name + hPath
} }
name := existAv.AvName name := tmpResult.AvName
if "" == name { if "" == name {
name = Conf.language(267) name = Conf.language(267)
} }
parent := &AvSearchResult{ parent := &AvSearchResult{
AvID: avID, AvID: tmpResult.AvID,
AvName: existAv.AvName, AvName: tmpResult.AvName,
BlockID: blockID, BlockID: node.ID,
HPath: hPath, HPath: hPath,
} }
ret = append(ret, parent) ret = append(ret, parent)
for _, view := range attrView.Views { for _, view := range attrView.Views {
child := &AvSearchResult{ child := &AvSearchResult{
AvID: avID, AvID: tmpResult.AvID,
AvName: existAv.AvName, AvName: tmpResult.AvName,
ViewName: view.Name, ViewName: view.Name,
ViewID: view.ID, ViewID: view.ID,
ViewLayout: view.LayoutType, ViewLayout: view.LayoutType,
BlockID: blockID, BlockID: node.ID,
HPath: hPath, HPath: hPath,
} }
parent.Children = append(parent.Children, child) parent.Children = append(parent.Children, child)

View file

@ -62,6 +62,21 @@ func ISOWeek(date time.Time) int {
return week 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 { func Millisecond2Time(t int64) time.Time {
sec := t / 1000 sec := t / 1000
msec := t % 1000 msec := t % 1000