Skip to content
This repository has been archived by the owner on Sep 17, 2023. It is now read-only.

Commit

Permalink
上一次提交的
Browse files Browse the repository at this point in the history
  • Loading branch information
2234839 committed Aug 23, 2021
1 parent ff078c3 commit e2dec33
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 38 deletions.
43 changes: 7 additions & 36 deletions src/struct/DirToStructRes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/88250/lute/ast"
"github.com/88250/lute/parse"
"github.com/siyuan-note/oceanpress/src/conf"
"github.com/siyuan-note/oceanpress/src/util"
)

Expand Down Expand Up @@ -68,40 +67,11 @@ func (r *FileEntity) FileEntityRelativePath(target FileEntity, id string) string

// VirtualPath 是最终要在浏览器中可以访问的路径
func (r *FileEntity) VirtualPath() (path string) {

// 使用文档名作为路径名
if conf.OutMode == "title" {
entries := strings.Split(r.RelativePath, "/")
var virtualPath = []string{}
for _, v := range entries {
id := v
if strings.HasSuffix(v, util.NotesSuffix) {
id = v[:len(v)-len(util.NotesSuffix)]
}
if util.IsID(id) {
FileEntity, _, err := NoteStore.FindFileEntityFromID(id)
if err == nil {
virtualPath = append(virtualPath, FileEntity.Name)
continue
}
}
virtualPath = append(virtualPath, id)
}
path = strings.Join(virtualPath, "/")
if util.IsNotes(r.RelativePath) {
path += ".html"
}
return path
} else {
// 直接使用 ID 作为路径名
if conf.OutMode != "id" {
util.Warn("OutMode 参数的值在预设之外,默认采用 id 模式")
}
if util.IsNotes(r.RelativePath) {
return r.RelativePath[0:len(r.RelativePath)-len(util.NotesSuffix)] + ".html"
}
return r.RelativePath
path = PathResolve(r.RelativePath)
if util.IsNotes(path) {
return path[:len(path)-len(util.NotesSuffix)] + ".html"
}
return path
}

// RootPath 获取当前对象相对于 root 目录的路径
Expand All @@ -115,7 +85,7 @@ func (r *FileEntity) RootPath() string {
if Level > 0 {
LevelRoot += strings.Repeat("../", Level)
}
return LevelRoot
return PathResolve(LevelRoot)
}

// FindFileEntityFromID 通过 id 返回对应实体
Expand Down Expand Up @@ -161,8 +131,9 @@ type RssInfo struct {
LastBuildDate string
List []RssItem
}

// RedirectInfo 重定向模板所需信息
type RedirectInfo struct {
RedirectPath string
Title string
Title string
}
44 changes: 43 additions & 1 deletion src/struct/noteStore.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,48 @@
package structAll

import (
"strings"

"github.com/siyuan-note/oceanpress/src/conf"
"github.com/siyuan-note/oceanpress/src/util"
)

// 来自 main.go 的生成
var NoteStore = DirToStructRes{}


// PathResolve 处理不同模式下路径的变换
func PathResolve(path string) string {
// 使用文档名作为路径名
if conf.OutMode == "title" {
entries := strings.Split(path, "/")
var virtualPath = []string{}
for _, v := range entries {
if v == "" {
virtualPath = append(virtualPath, v)
continue
}
suffix := ""
fragment := strings.Split(v, ".")
id := fragment[0]
if len(fragment) > 1 {
suffix = "." + fragment[1]
}
if util.IsID(id) {
FileEntity, _, err := NoteStore.FindFileEntityFromID(id)
if err == nil {
virtualPath = append(virtualPath, FileEntity.Name+suffix)
continue
}
}
virtualPath = append(virtualPath, v)
}
path = strings.Join(virtualPath, "/")
return path
} else {
// 直接使用 ID 作为路径名
if conf.OutMode != "id" {
util.Warn("OutMode 参数的值在预设之外,默认采用 id 模式")
}
return path
}
}
1 change: 1 addition & 0 deletions src/util/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

// WriteFile 确保文件路径存在,且不超出 conf.outDir
func WriteFile(targetPath string, data []byte, perm os.FileMode) error {
targetPath = filepath.ToSlash(targetPath)
rel, err := filepath.Rel(conf.OutDir, targetPath)
if err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion src/util/notes_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func IsID(id string) bool {
reg, _ := regexp.Compile(`^\d{14}-[a-z0-9]{7}`)
return reg.MatchString(id)
}

// TimeFromID 从 id 中提取创建时间
func TimeFromID(id string) string {
reg, _ := regexp.Compile(`^\d+`)
Expand Down

0 comments on commit e2dec33

Please sign in to comment.