1
0
mirror of https://shylinux.com/x/icebergs synced 2025-05-04 20:37:00 +08:00

opt website.go

This commit is contained in:
harveyshao 2021-12-06 19:28:06 +08:00
parent 0e04e31f58
commit 71576fe085
3 changed files with 19 additions and 7 deletions

View File

@ -8,7 +8,7 @@ import (
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
) )
func _split_deep(m *ice.Message, text string) (deep int) { func _split_deep(text string) (deep int) {
for _, c := range text { for _, c := range text {
switch c { switch c {
case '\t': case '\t':
@ -21,9 +21,20 @@ func _split_deep(m *ice.Message, text string) (deep int) {
} }
return return
} }
func _split_deep2(stack []int, text string) ([]int, int) {
deep := _split_deep(text)
for i := len(stack) - 1; i >= 0; i-- {
if deep <= stack[i] {
stack = stack[:len(stack)-1]
}
}
stack = append(stack, deep)
return stack, len(stack)
}
func _split_list(m *ice.Message, file string, arg ...string) { func _split_list(m *ice.Message, file string, arg ...string) {
const DEEP = "_deep" const DEEP = "_deep"
list := kit.List(kit.Data(DEEP, -1)) list := kit.List(kit.Data(DEEP, -1))
stack, deep := []int{}, 0
m.Cmd(nfs.CAT, file, func(text string) { m.Cmd(nfs.CAT, file, func(text string) {
// if text = kit.Split(text, "#", "#")[0]; strings.TrimSpace(text) == "" { // if text = kit.Split(text, "#", "#")[0]; strings.TrimSpace(text) == "" {
// return // return
@ -35,7 +46,8 @@ func _split_list(m *ice.Message, file string, arg ...string) {
return return
} }
deep := _split_deep(m, text) // deep := _split_deep(text)
stack, deep = _split_deep2(stack, text)
data := kit.Data(DEEP, deep) data := kit.Data(DEEP, deep)
ls := kit.Split(text) ls := kit.Split(text)

View File

@ -25,13 +25,13 @@ func _website_parse(m *ice.Message, text string) map[string]interface{} {
} }
} }
switch deep { switch deep {
case 0: case 1:
storm = kit.Dict() storm = kit.Dict()
river[ls[0]] = kit.Dict(kit.MDB_NAME, ls[1], "storm", storm, data) river[ls[0]] = kit.Dict(kit.MDB_NAME, ls[1], "storm", storm, data)
case 4: case 2:
last = kit.Dict(kit.MDB_NAME, ls[1], kit.MDB_LIST, kit.List(), data) last = kit.Dict(kit.MDB_NAME, ls[1], kit.MDB_LIST, kit.List(), data)
storm[ls[0]] = last storm[ls[0]] = last
case 8: case 3:
last[kit.MDB_LIST] = append(last[kit.MDB_LIST].([]interface{}), last[kit.MDB_LIST] = append(last[kit.MDB_LIST].([]interface{}),
kit.Dict(kit.MDB_NAME, ls[0], kit.MDB_HELP, ls[1], kit.MDB_INDEX, ls[0], data)) kit.Dict(kit.MDB_NAME, ls[0], kit.MDB_HELP, ls[1], kit.MDB_INDEX, ls[0], data))
} }
@ -56,6 +56,7 @@ func init() {
switch text := kit.Format(value[kit.MDB_TEXT]); value[kit.MDB_TYPE] { switch text := kit.Format(value[kit.MDB_TEXT]); value[kit.MDB_TYPE] {
case "txt": case "txt":
res := _website_parse(msg, kit.Format(value[kit.MDB_TEXT])) res := _website_parse(msg, kit.Format(value[kit.MDB_TEXT]))
// web.RenderResult(msg, kit.Format(res))
web.RenderResult(msg, _website_template2, kit.Format(res)) web.RenderResult(msg, _website_template2, kit.Format(res))
case "json": case "json":
web.RenderResult(msg, _website_template2, kit.Format(kit.UnMarshal(text))) web.RenderResult(msg, _website_template2, kit.Format(kit.UnMarshal(text)))
@ -76,7 +77,7 @@ func init() {
m.Cmdy(nfs.DIR, arg[1:]).ProcessAgain() m.Cmdy(nfs.DIR, arg[1:]).ProcessAgain()
} }
}}, }},
mdb.CREATE: {Name: "create path type=html,js,json name text", Help: "创建"}, mdb.CREATE: {Name: "create path type=html,js,json,txt name text", Help: "创建"},
mdb.IMPORT: {Name: "import path=src/", Help: "导入", Hand: func(m *ice.Message, arg ...string) { mdb.IMPORT: {Name: "import path=src/", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
m.Cmd(nfs.DIR, kit.Dict(nfs.DIR_ROOT, m.Option(nfs.PATH)), func(p string) { m.Cmd(nfs.DIR, kit.Dict(nfs.DIR_ROOT, m.Option(nfs.PATH)), func(p string) {
switch kit.Ext(p) { switch kit.Ext(p) {

View File

@ -124,7 +124,6 @@ func init() {
if p := r.URL.Path; strings.HasPrefix(p, "/x/") { if p := r.URL.Path; strings.HasPrefix(p, "/x/") {
r.URL.Path = strings.Replace(r.URL.Path, "/x/", "/code/git/repos/", -1) r.URL.Path = strings.Replace(r.URL.Path, "/x/", "/code/git/repos/", -1)
m.Info("rewrite %v -> %v", p, r.URL.Path) m.Info("rewrite %v -> %v", p, r.URL.Path)
return true
} }
return false return false
}) })