diff --git a/kernel/api/icon.go b/kernel/api/icon.go
index 58466bfea..c0d56123d 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"
@@ -28,6 +27,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/siyuan-note/siyuan/kernel/model"
+ "github.com/siyuan-note/siyuan/kernel/util"
)
type ColorScheme struct {
@@ -238,8 +238,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 +259,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 +400,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: 仅显示星期
diff --git a/kernel/filesys/template.go b/kernel/filesys/template.go
index 9acaa54fc..2e22f416e 100644
--- a/kernel/filesys/template.go
+++ b/kernel/filesys/template.go
@@ -44,6 +44,9 @@ 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["ISOWeekDate"] = util.ISOWeekDate
ret["pow"] = pow
ret["powf"] = powf
ret["log"] = log
diff --git a/kernel/harmony/kernel.go b/kernel/harmony/kernel.go
index b9b3f754c..40bf54a27 100644
--- a/kernel/harmony/kernel.go
+++ b/kernel/harmony/kernel.go
@@ -93,18 +93,18 @@ func SetHttpServerPort(port int) {
}
//export GetCurrentWorkspacePath
-func GetCurrentWorkspacePath() string {
- return util.WorkspaceDir
+func GetCurrentWorkspacePath() *C.char {
+ return C.CString(util.WorkspaceDir)
}
//export GetAssetAbsPath
-func GetAssetAbsPath(asset string) (ret string) {
- ret, err := model.GetAssetAbsPath(asset)
- if err != nil {
- logging.LogErrorf("get asset [%s] abs path failed: %s", asset, err)
- ret = asset
+func GetAssetAbsPath(relativePath *C.char) *C.char {
+ absPath, err := model.GetAssetAbsPath(C.GoString(relativePath))
+ if nil != err {
+ logging.LogErrorf("get asset abs path failed: %s", err)
+ return relativePath
}
- return
+ return C.CString(absPath)
}
//export GetMimeTypeByExt
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)
diff --git a/kernel/util/time.go b/kernel/util/time.go
index bd9fad5ea..933e88084 100644
--- a/kernel/util/time.go
+++ b/kernel/util/time.go
@@ -62,6 +62,37 @@ 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 {
+ weekday := int(date.Weekday())
+ if weekday == 0 {
+ weekday = 7
+ }
+
+ daysToMonday := weekday - 1
+ monday := date.AddDate(0, 0, -daysToMonday)
+ return int(monday.Month())
+}
+
+// ISOWeekDate returns the date of the specified day of the week in the ISO 8601 week of date.
+// day: Monday=1, ..., Sunday=7.
+func ISOWeekDate(date time.Time, day int) time.Time {
+ weekday := int(date.Weekday())
+ if weekday == 0 {
+ weekday = 7
+ }
+
+ daysToMonday := weekday - 1
+ monday := date.AddDate(0, 0, -daysToMonday)
+ return monday.AddDate(0, 0, day-1)
+}
+
func Millisecond2Time(t int64) time.Time {
sec := t / 1000
msec := t % 1000