mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 00:20:47 +02:00
Compare commits
4 commits
2570a971a2
...
dcefed26eb
Author | SHA1 | Date | |
---|---|---|---|
![]() |
dcefed26eb | ||
![]() |
d684bb41b1 | ||
![]() |
d445163b2f | ||
![]() |
b5d47b9600 |
4 changed files with 51 additions and 47 deletions
|
@ -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
|
|||
<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>
|
||||
</svg>
|
||||
`, colorScheme.Primary, colorScheme.Secondary, dateInfo["year"], dateInfo["week"])
|
||||
`, colorScheme.Primary, colorScheme.Secondary, dateInfo["isoYear"], dateInfo["week"])
|
||||
}
|
||||
|
||||
// Type 6: 仅显示星期
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
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, blockID)
|
||||
node = treenode.GetNodeInTree(tree, bID)
|
||||
if nil == node || "" == node.AttributeViewID {
|
||||
continue
|
||||
}
|
||||
|
||||
avID := node.AttributeViewID
|
||||
var existAv *AvSearchTempResult
|
||||
for _, tmpResult := range avSearchTmpResults {
|
||||
if tmpResult.AvID == avID {
|
||||
existAv = tmpResult
|
||||
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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue