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

add wiki.parse

This commit is contained in:
shaoying 2021-01-14 21:37:15 +08:00
parent d758042ab5
commit 690bff09e8
3 changed files with 80 additions and 40 deletions

View File

@ -335,6 +335,7 @@ func _zone_export(m *ice.Message, prefix, chain, file string) {
}) })
m.Log_EXPORT(kit.MDB_KEY, path.Join(prefix, chain), kit.MDB_FILE, p, kit.MDB_COUNT, count) m.Log_EXPORT(kit.MDB_KEY, path.Join(prefix, chain), kit.MDB_FILE, p, kit.MDB_COUNT, count)
m.Conf(prefix, chain, kit.MDB_HASH, "")
m.Echo(p) m.Echo(p)
} }
func _zone_import(m *ice.Message, prefix, chain, file string) { func _zone_import(m *ice.Message, prefix, chain, file string) {

View File

@ -26,11 +26,12 @@ func init() {
mdb.MODIFY: {Name: "modify", Help: "编辑", Hand: func(m *ice.Message, arg ...string) { mdb.MODIFY: {Name: "modify", Help: "编辑", Hand: func(m *ice.Message, arg ...string) {
_task_modify(m, m.Option(kit.MDB_ZONE), m.Option(kit.MDB_ID), arg[0], arg[1]) _task_modify(m, m.Option(kit.MDB_ZONE), m.Option(kit.MDB_ID), arg[0], arg[1])
}}, }},
mdb.EXPORT: {Name: "export file", Help: "导出", Hand: func(m *ice.Message, arg ...string) { mdb.EXPORT: {Name: "export", Help: "导出", Hand: func(m *ice.Message, arg ...string) {
_task_export(m, m.Option(kit.MDB_FILE)) _task_export(m, "")
}}, }},
mdb.IMPORT: {Name: "import file", Help: "导入", Hand: func(m *ice.Message, arg ...string) { mdb.IMPORT: {Name: "import", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
_task_import(m, m.Option(kit.MDB_FILE)) _task_import(m, "")
m.Option(ice.MSG_PROCESS, ice.PROCESS_REFRESH)
}}, }},
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) { mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
_task_inputs(m, kit.Select("", arg, 0), kit.Select("", arg, 1)) _task_inputs(m, kit.Select("", arg, 0), kit.Select("", arg, 1))

View File

@ -3,6 +3,7 @@ package wiki
import ( import (
ice "github.com/shylinux/icebergs" ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/cli" "github.com/shylinux/icebergs/base/cli"
"github.com/shylinux/icebergs/base/mdb"
"github.com/shylinux/icebergs/base/nfs" "github.com/shylinux/icebergs/base/nfs"
"github.com/shylinux/icebergs/base/ssh" "github.com/shylinux/icebergs/base/ssh"
"github.com/shylinux/icebergs/base/web" "github.com/shylinux/icebergs/base/web"
@ -12,6 +13,7 @@ import (
"bytes" "bytes"
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"net/url"
"path" "path"
"strings" "strings"
) )
@ -292,15 +294,15 @@ const (
REFER = "refer" REFER = "refer"
SPARK = "spark" SPARK = "spark"
CHART = "chart" ORDER = "order"
FIELD = "field" TABLE = "table"
SHELL = "shell" SHELL = "shell"
LOCAL = "local" LOCAL = "local"
ORDER = "order" FIELD = "field"
TABLE = "table"
IMAGE = "image" IMAGE = "image"
CHART = "chart"
PARSE = "parse"
OTHER = "other" OTHER = "other"
PREMENU = "premenu" PREMENU = "premenu"
@ -324,13 +326,13 @@ func init() {
"prompt", kit.Dict("shell", "$ "), "prompt", kit.Dict("shell", "$ "),
)}, )},
CHART: {Name: CHART, Help: "图表", Value: kit.Data("template", chart, "suffix", `</svg>`)}, ORDER: {Name: ORDER, Help: "列表", Value: kit.Data("template", order)},
FIELD: {Name: FIELD, Help: "插件", Value: kit.Data("template", field)}, TABLE: {Name: TABLE, Help: "表格", Value: kit.Data("template", table)},
SHELL: {Name: SHELL, Help: "命令", Value: kit.Data("template", shell)}, SHELL: {Name: SHELL, Help: "命令", Value: kit.Data("template", shell)},
LOCAL: {Name: LOCAL, Help: "文件", Value: kit.Data("template", local)}, LOCAL: {Name: LOCAL, Help: "文件", Value: kit.Data("template", local)},
ORDER: {Name: ORDER, Help: "列表", Value: kit.Data("template", order)}, FIELD: {Name: FIELD, Help: "插件", Value: kit.Data("template", field)},
TABLE: {Name: TABLE, Help: "表格", Value: kit.Data("template", table)}, CHART: {Name: CHART, Help: "图表", Value: kit.Data("template", chart, "suffix", `</svg>`)},
IMAGE: {Name: IMAGE, Help: "图片", Value: kit.Data("template", image)}, IMAGE: {Name: IMAGE, Help: "图片", Value: kit.Data("template", image)},
WORD: {Name: WORD, Help: "语言文字", Value: kit.Data( WORD: {Name: WORD, Help: "语言文字", Value: kit.Data(
@ -379,31 +381,6 @@ func init() {
_spark_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) _spark_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}}, }},
CHART: {Name: "chart label|chain [name] text", Help: "图表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 2 {
arg = []string{arg[0], "", arg[1]}
}
_chart_show(m, arg[0], arg[1], arg[2], arg[3:]...)
}},
FIELD: {Name: "field [name] cmd", Help: "插件", Action: map[string]*ice.Action{
"run": {Name: "run", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
if !m.Warn(!m.Right(arg[1:]), ice.ErrNotRight, arg[1:]) {
m.Cmdy(arg[1:])
}
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
arg = _name(m, arg)
_field_show(m, strings.ReplaceAll(kit.Select(path.Base(arg[1]), arg[0]), " ", "_"), arg[1], arg[2:]...)
}},
SHELL: {Name: "shell [name] cmd", Help: "命令", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
arg = _name(m, arg)
_shell_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}},
LOCAL: {Name: "local [name] file", Help: "文件", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
arg = _name(m, arg)
_local_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}},
ORDER: {Name: "order [name] `[item \n]...`", Help: "列表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { ORDER: {Name: "order [name] `[item \n]...`", Help: "列表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
arg = _name(m, arg) arg = _name(m, arg)
_order_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) _order_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
@ -417,6 +394,25 @@ func init() {
arg = _name(m, arg) arg = _name(m, arg)
_table_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) _table_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}}, }},
SHELL: {Name: "shell [name] cmd", Help: "命令", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
arg = _name(m, arg)
_shell_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}},
LOCAL: {Name: "local [name] file", Help: "文件", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
arg = _name(m, arg)
_local_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}},
FIELD: {Name: "field [name] cmd", Help: "插件", Action: map[string]*ice.Action{
"run": {Name: "run", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
if !m.Warn(!m.Right(arg[1:]), ice.ErrNotRight, arg[1:]) {
m.Cmdy(arg[1:])
}
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
arg = _name(m, arg)
_field_show(m, strings.ReplaceAll(kit.Select(path.Base(arg[1]), arg[0]), " ", "_"), arg[1], arg[2:]...)
}},
IMAGE: {Name: "image [name] url", Help: "图片", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { IMAGE: {Name: "image [name] url", Help: "图片", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if arg[0] == "qrcode" { if arg[0] == "qrcode" {
buf := bytes.NewBuffer(make([]byte, 0, 4096)) buf := bytes.NewBuffer(make([]byte, 0, 4096))
@ -430,17 +426,59 @@ func init() {
_image_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) _image_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
m.Render("") m.Render("")
}}, }},
CHART: {Name: "chart label|chain [name] text", Help: "图表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 2 {
arg = []string{arg[0], "", arg[1]}
}
_chart_show(m, arg[0], arg[1], arg[2], arg[3:]...)
}},
PARSE: {Name: "parse type=auto,json,http,form,list auto text:textarea", Help: "结构", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if arg[0] == "auto" && (strings.HasPrefix(arg[1], "{") || strings.HasPrefix(arg[1], "[")) {
arg[0] = "json"
} else if strings.HasPrefix(arg[1], "http") {
arg[0] = "http"
} else if strings.Contains(arg[1], "=") {
arg[0] = "form"
} else {
arg[0] = "list"
}
m.Option(mdb.FIELDS, mdb.DETAIL)
switch arg[0] {
case "json":
m.Echo(kit.Formats(kit.UnMarshal(arg[1])))
case "http":
u, _ := url.Parse(arg[1])
for k, v := range u.Query() {
for _, v := range v {
m.Push(k, v)
}
}
m.EchoQRCode(arg[1])
case "form":
for _, v := range kit.Split(arg[1], "&", "&", "&") {
ls := kit.Split(v, "=", "=", "=")
key, _ := url.QueryUnescape(ls[0])
value, _ := url.QueryUnescape(kit.Select("", ls, 1))
m.Push(key, value)
}
case "list":
for i, v := range kit.Split(arg[1]) {
m.Push(kit.Format(i), v)
}
}
}},
OTHER: {Name: "other [name] url", Help: "网页", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { OTHER: {Name: "other [name] url", Help: "网页", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
arg = _name(m, arg) arg = _name(m, arg)
_other_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...) _other_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
}}, }},
WORD: {Name: "word path=src/main.shy auto 演示", Help: "语言文字", Meta: kit.Dict( WORD: {Name: "word path=src/main.shy auto", Help: "语言文字", Meta: kit.Dict(
"display", "/plugin/local/wiki/word.js", "display", "/plugin/local/wiki/word.js",
), Action: map[string]*ice.Action{ ), Action: map[string]*ice.Action{
web.STORY: {Name: "story", Help: "运行", Hand: func(m *ice.Message, arg ...string) { web.STORY: {Name: "story", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(arg[0], "action", "run", arg[1:]) m.Cmdy(arg[0], kit.MDB_ACTION, "run", arg[1:])
}}, }},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if m.Option(nfs.DIR_DEEP, "true"); _wiki_list(m, cmd, arg...) { if m.Option(nfs.DIR_DEEP, "true"); _wiki_list(m, cmd, arg...) {