mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-02 14:58:49 +01:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
23ed5c8627
5 changed files with 76 additions and 55 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,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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue