mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 17:44:05 +08:00
opt wiki
This commit is contained in:
parent
08f8ba8730
commit
da6ffe8b0d
@ -358,6 +358,11 @@ func init() {
|
|||||||
m.Cmdy(mdb.DELETE, SPIDE, "", mdb.HASH, CLIENT_NAME, m.Option(CLIENT_NAME))
|
m.Cmdy(mdb.DELETE, SPIDE, "", mdb.HASH, CLIENT_NAME, m.Option(CLIENT_NAME))
|
||||||
}},
|
}},
|
||||||
}, 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 len(arg) == 2 {
|
||||||
|
m.Option(SPIDE_HEADER, ContentType, ContentJSON)
|
||||||
|
m.Echo(kit.Formats(kit.UnMarshal(m.Cmdx(SPIDE, SPIDE_DEV, SPIDE_RAW, SPIDE_POST, arg[0], SPIDE_DATA, arg[1:]))))
|
||||||
|
return
|
||||||
|
}
|
||||||
m.Echo(kit.Formats(kit.UnMarshal(m.Cmdx(SPIDE, SPIDE_DEV, SPIDE_RAW, SPIDE_POST, arg[0], SPIDE_JSON, arg[1:]))))
|
m.Echo(kit.Formats(kit.UnMarshal(m.Cmdx(SPIDE, SPIDE_DEV, SPIDE_RAW, SPIDE_POST, arg[0], SPIDE_JSON, arg[1:]))))
|
||||||
}},
|
}},
|
||||||
}})
|
}})
|
||||||
|
@ -10,8 +10,8 @@ const BRIEF = "brief"
|
|||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{
|
Index.Merge(&ice.Context{
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
BRIEF: {Name: "brief [name] text", Help: "摘要", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
BRIEF: {Name: "brief text", Help: "摘要", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
_word_template(m, cmd, arg...)
|
_wiki_template(m, cmd, "", arg[0], arg[1:]...)
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
|
@ -357,7 +357,7 @@ func Stack(m *ice.Message, name string, level int, data interface{}) {
|
|||||||
m.Echo("</ul>")
|
m.Echo("</ul>")
|
||||||
}
|
}
|
||||||
|
|
||||||
func _chart_show(m *ice.Message, kind, name, text string, arg ...string) {
|
func _chart_show(m *ice.Message, kind, text string, arg ...string) {
|
||||||
var chart Chart
|
var chart Chart
|
||||||
switch kind {
|
switch kind {
|
||||||
case LABEL: // 标签
|
case LABEL: // 标签
|
||||||
@ -366,11 +366,6 @@ func _chart_show(m *ice.Message, kind, name, text string, arg ...string) {
|
|||||||
chart = &Chain{}
|
chart = &Chain{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 基本参数
|
|
||||||
m.Option(kit.MDB_TYPE, strings.TrimSpace(kind))
|
|
||||||
m.Option(kit.MDB_NAME, strings.TrimSpace(name))
|
|
||||||
m.Option(kit.MDB_TEXT, strings.TrimSpace(text))
|
|
||||||
|
|
||||||
// 扩展参数
|
// 扩展参数
|
||||||
m.Option("font-size", "24")
|
m.Option("font-size", "24")
|
||||||
m.Option("stroke", "blue")
|
m.Option("stroke", "blue")
|
||||||
@ -397,13 +392,13 @@ func _chart_show(m *ice.Message, kind, name, text string, arg ...string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 计算尺寸
|
// 计算尺寸
|
||||||
chart.Init(m, m.Option(kit.MDB_TEXT))
|
chart.Init(m, text)
|
||||||
m.Option("height", chart.GetHeight())
|
|
||||||
m.Option("width", chart.GetWidth())
|
m.Option("width", chart.GetWidth())
|
||||||
|
m.Option("height", chart.GetHeight())
|
||||||
|
|
||||||
// 渲染引擎
|
// 渲染引擎
|
||||||
m.RenderTemplate(m.Conf(CHART, kit.Keym(kit.MDB_TEMPLATE)))
|
_wiki_template(m, CHART, "", text)
|
||||||
defer m.RenderTemplate(m.Conf(CHART, kit.Keym("suffix")))
|
defer m.Echo(`</svg>`)
|
||||||
chart.Draw(m, 0, 0)
|
chart.Draw(m, 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,11 +411,8 @@ const CHART = "chart"
|
|||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{
|
Index.Merge(&ice.Context{
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
CHART: {Name: "chart label|chain [name] text", Help: "图表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
CHART: {Name: "chart label|chain text", Help: "图表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if len(arg) == 2 {
|
_chart_show(m, arg[0], strings.TrimSpace(arg[1]), arg[2:]...)
|
||||||
arg = []string{arg[0], "", arg[1]}
|
|
||||||
}
|
|
||||||
_chart_show(m, arg[0], arg[1], arg[2], arg[3:]...)
|
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
@ -430,7 +422,7 @@ vertion="1.1" xmlns="http://www.w3.org/2000/svg" dominant-baseline="middle" text
|
|||||||
font-size="{{.Option "font-size"}}" stroke="{{.Option "stroke"}}" fill="{{.Option "fill"}}"
|
font-size="{{.Option "font-size"}}" stroke="{{.Option "stroke"}}" fill="{{.Option "fill"}}"
|
||||||
stroke-width="{{.Option "stroke-width"}}" font-family="{{.Option "font-family"}}"
|
stroke-width="{{.Option "stroke-width"}}" font-family="{{.Option "font-family"}}"
|
||||||
width="{{.Option "width"}}" height="{{.Option "height"}}"
|
width="{{.Option "width"}}" height="{{.Option "height"}}"
|
||||||
>`, "suffix", `</svg>`,
|
>`,
|
||||||
)},
|
)},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -22,7 +22,7 @@ func init() {
|
|||||||
ice.Display("/plugin/local/wiki/draw.js"),
|
ice.Display("/plugin/local/wiki/draw.js"),
|
||||||
), Action: map[string]*ice.Action{
|
), Action: map[string]*ice.Action{
|
||||||
nfs.SAVE: {Name: "save path", Help: "保存", Hand: func(m *ice.Message, arg ...string) {
|
nfs.SAVE: {Name: "save path", Help: "保存", Hand: func(m *ice.Message, arg ...string) {
|
||||||
_wiki_save(m, DRAW, path.Join(arg...), m.Option("content"))
|
_wiki_save(m, DRAW, path.Join(arg...), m.Option(kit.MDB_CONTENT))
|
||||||
}},
|
}},
|
||||||
}, 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 !_wiki_list(m, DRAW, kit.Select("./", path.Join(arg...))) {
|
if !_wiki_list(m, DRAW, kit.Select("./", path.Join(arg...))) {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package wiki
|
package wiki
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
ice "github.com/shylinux/icebergs"
|
ice "github.com/shylinux/icebergs"
|
||||||
@ -10,62 +9,66 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func _field_show(m *ice.Message, name, text string, arg ...string) {
|
func _field_show(m *ice.Message, name, text string, arg ...string) {
|
||||||
// 基本参数
|
|
||||||
m.Option(kit.MDB_TYPE, FIELD)
|
|
||||||
m.Option(kit.MDB_NAME, name)
|
|
||||||
m.Option(kit.MDB_TEXT, text)
|
|
||||||
|
|
||||||
// 命令参数
|
// 命令参数
|
||||||
data := kit.Dict(kit.MDB_NAME, name)
|
meta, cmds := kit.Dict(), kit.Split(text)
|
||||||
cmds := kit.Split(text)
|
|
||||||
m.Search(cmds[0], func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) {
|
m.Search(cmds[0], func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) {
|
||||||
data["feature"], data["inputs"] = cmd.Meta, cmd.List
|
if meta[FEATURE], meta[INPUTS] = cmd.Meta, cmd.List; name == "" {
|
||||||
|
name = cmd.Help
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
name = strings.ReplaceAll(name, " ", "_")
|
||||||
|
meta[kit.MDB_NAME] = name
|
||||||
|
|
||||||
// 扩展参数
|
// 扩展参数
|
||||||
for i := 0; i < len(arg)-1; i += 2 {
|
for i := 0; i < len(arg)-1; i += 2 {
|
||||||
if strings.HasPrefix(arg[i], "args.") {
|
if strings.HasPrefix(arg[i], "args.") {
|
||||||
m.Option(arg[i], strings.TrimSpace(arg[i+1]))
|
m.Option(arg[i], strings.TrimSpace(arg[i+1]))
|
||||||
kit.Value(data, arg[i], m.Option(arg[i]))
|
kit.Value(meta, arg[i], m.Option(arg[i]))
|
||||||
} else if strings.HasPrefix(arg[i], "args") {
|
} else if strings.HasPrefix(arg[i], ARGS) {
|
||||||
m.Option(arg[i], kit.Split(strings.TrimSuffix(strings.TrimPrefix(arg[i+1], "["), "]")))
|
m.Option(arg[i], kit.Split(strings.TrimSuffix(strings.TrimPrefix(arg[i+1], "["), "]")))
|
||||||
kit.Value(data, arg[i], m.Optionv(arg[i]))
|
kit.Value(meta, arg[i], m.Optionv(arg[i]))
|
||||||
} else {
|
} else {
|
||||||
m.Parse("option", arg[i], arg[i+1])
|
m.Parse(ice.MSG_OPTION, arg[i], arg[i+1])
|
||||||
kit.Value(data, arg[i], m.Optionv(arg[i]))
|
kit.Value(meta, arg[i], m.Optionv(arg[i]))
|
||||||
}
|
}
|
||||||
|
|
||||||
switch arg[i] {
|
switch arg[i] {
|
||||||
case "content":
|
case kit.MDB_CONTENT:
|
||||||
data[arg[i]] = arg[i+1]
|
meta[arg[i]] = arg[i+1]
|
||||||
|
|
||||||
case "args":
|
case ARGS:
|
||||||
args := kit.Simple(m.Optionv(arg[i]))
|
args := kit.Simple(m.Optionv(arg[i]))
|
||||||
|
|
||||||
count := 0
|
count := 0
|
||||||
kit.Fetch(data["inputs"], func(index int, value map[string]interface{}) {
|
kit.Fetch(meta[INPUTS], func(index int, value map[string]interface{}) {
|
||||||
if value["_input"] != "button" && value["type"] != "button" {
|
if value[kit.MDB_INPUT] != kit.MDB_BUTTON && value[kit.MDB_TYPE] != kit.MDB_BUTTON {
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if len(args) > count {
|
if len(args) > count {
|
||||||
list := data["inputs"].([]interface{})
|
list := meta[INPUTS].([]interface{})
|
||||||
for i := count; i < len(args); i++ {
|
for i := count; i < len(args); i++ {
|
||||||
list = append(list, kit.Dict(
|
list = append(list, kit.Dict(
|
||||||
"_input", "text", "name", "args", "value", args[i],
|
kit.MDB_INPUT, "text", kit.MDB_NAME, "args", kit.MDB_VALUE, args[i],
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
data["inputs"] = list
|
meta[INPUTS] = list
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m.Option(kit.MDB_META, meta)
|
||||||
|
|
||||||
// 渲染引擎
|
// 渲染引擎
|
||||||
m.Option(kit.MDB_META, data)
|
_wiki_template(m, FIELD, name, text)
|
||||||
m.RenderTemplate(m.Conf(FIELD, kit.Keym(kit.MDB_TEMPLATE)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
FEATURE = "feature"
|
||||||
|
INPUTS = "inputs"
|
||||||
|
ARGS = "args"
|
||||||
|
)
|
||||||
const FIELD = "field"
|
const FIELD = "field"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -79,7 +82,7 @@ func init() {
|
|||||||
}},
|
}},
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
arg = _name(m, arg)
|
arg = _name(m, arg)
|
||||||
_field_show(m, strings.ReplaceAll(kit.Select(path.Base(arg[1]), arg[0]), " ", "_"), arg[1], arg[2:]...)
|
_field_show(m, arg[0], arg[1], arg[2:]...)
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
|
@ -2,20 +2,14 @@ package wiki
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
|
||||||
|
|
||||||
ice "github.com/shylinux/icebergs"
|
ice "github.com/shylinux/icebergs"
|
||||||
"github.com/shylinux/icebergs/base/mdb"
|
"github.com/shylinux/icebergs/base/mdb"
|
||||||
kit "github.com/shylinux/toolkits"
|
kit "github.com/shylinux/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
func _image_show(m *ice.Message, name, text string, arg ...string) {
|
func _image_show(m *ice.Message, text string, arg ...string) {
|
||||||
if !strings.HasPrefix(text, "http") && !strings.HasPrefix(text, "/") {
|
_wiki_template(m, IMAGE, "", _wiki_link(m, IMAGE, text), arg...)
|
||||||
text = path.Join("/share/local", _wiki_path(m, FEEL, text))
|
|
||||||
}
|
|
||||||
|
|
||||||
_option(m, IMAGE, name, text, arg...)
|
|
||||||
m.RenderTemplate(m.Conf(IMAGE, kit.Keym(kit.MDB_TEMPLATE)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -31,18 +25,18 @@ func init() {
|
|||||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
m.Cmd(mdb.RENDER, mdb.CREATE, PNG, m.Prefix(IMAGE))
|
m.Cmd(mdb.RENDER, mdb.CREATE, PNG, m.Prefix(IMAGE))
|
||||||
}},
|
}},
|
||||||
IMAGE: {Name: "image [name] url", Help: "图片", Action: map[string]*ice.Action{
|
IMAGE: {Name: "image url", Help: "图片", Action: map[string]*ice.Action{
|
||||||
mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
|
mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
|
||||||
_image_show(m, arg[1], path.Join(arg[2], arg[1]))
|
_image_show(m, path.Join(arg[2], 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) {
|
||||||
arg = _name(m, arg)
|
_image_show(m, arg[0], arg[1:]...)
|
||||||
_image_show(m, arg[0], arg[1], arg[2:]...)
|
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
IMAGE: {Name: IMAGE, Help: "图片", Value: kit.Data(
|
IMAGE: {Name: IMAGE, Help: "图片", Value: kit.Data(
|
||||||
kit.MDB_TEMPLATE, `<img {{.OptionTemplate}} title="{{.Option "text"}}" src="{{.Option "text"}}">`,
|
kit.MDB_TEMPLATE, `<img {{.OptionTemplate}} title="{{.Option "text"}}" src="{{.Option "text"}}">`,
|
||||||
|
kit.MDB_PATH, "usr/local/image",
|
||||||
)},
|
)},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -7,9 +7,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func _local_show(m *ice.Message, name, text string, arg ...string) {
|
func _local_show(m *ice.Message, name, text string, arg ...string) {
|
||||||
m.Option("input", m.Cmdx(nfs.CAT, text))
|
m.Option(INPUT, m.Cmdx(nfs.CAT, text))
|
||||||
_option(m, LOCAL, name, text, arg...)
|
_wiki_template(m, LOCAL, name, text, arg...)
|
||||||
m.RenderTemplate(m.Conf(LOCAL, kit.Keym(kit.MDB_TEMPLATE)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const LOCAL = "local"
|
const LOCAL = "local"
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
package wiki
|
|
||||||
|
|
||||||
import (
|
|
||||||
ice "github.com/shylinux/icebergs"
|
|
||||||
"github.com/shylinux/icebergs/base/mdb"
|
|
||||||
kit "github.com/shylinux/toolkits"
|
|
||||||
)
|
|
||||||
|
|
||||||
func _music_show(m *ice.Message, name, text string, arg ...string) {
|
|
||||||
_option(m, MUSIC, name, text, arg...)
|
|
||||||
}
|
|
||||||
func _music_search(m *ice.Message, kind, name, text string) {
|
|
||||||
if kit.Contains(kind, kit.MDB_FOREACH) || kit.Contains(kind, MUSIC) {
|
|
||||||
m.PushSearchWeb(MUSIC, name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const MUSIC = "music"
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
Index.Merge(&ice.Context{
|
|
||||||
Configs: map[string]*ice.Config{
|
|
||||||
MUSIC: {Name: "music", Help: "音乐", Value: kit.Data(kit.MDB_SHORT, kit.MDB_TEXT)},
|
|
||||||
},
|
|
||||||
Commands: map[string]*ice.Command{
|
|
||||||
MUSIC: {Name: "music [name] url", Help: "视频", Action: map[string]*ice.Action{
|
|
||||||
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
_music_search(m, arg[0], arg[1], arg[2])
|
|
||||||
}},
|
|
||||||
mdb.CREATE: {Name: "create type name text", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
m.Cmd(mdb.INSERT, m.Prefix(MUSIC), "", mdb.HASH, arg)
|
|
||||||
}},
|
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
|
||||||
arg = _name(m, arg)
|
|
||||||
_music_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
|
|
||||||
}},
|
|
||||||
}})
|
|
||||||
}
|
|
@ -7,10 +7,9 @@ import (
|
|||||||
kit "github.com/shylinux/toolkits"
|
kit "github.com/shylinux/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
func _order_show(m *ice.Message, name, text string, arg ...string) {
|
func _order_show(m *ice.Message, text string, arg ...string) {
|
||||||
m.Optionv("list", kit.Split(strings.TrimSpace(text), "\n"))
|
m.Optionv(kit.MDB_LIST, kit.Split(strings.TrimSpace(text), ice.MOD_NL))
|
||||||
_option(m, ORDER, name, text, arg...)
|
_wiki_template(m, ORDER, "", text, arg...)
|
||||||
m.RenderTemplate(m.Conf(ORDER, kit.Keym(kit.MDB_TEMPLATE)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const ORDER = "order"
|
const ORDER = "order"
|
||||||
@ -18,9 +17,8 @@ const ORDER = "order"
|
|||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{
|
Index.Merge(&ice.Context{
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
ORDER: {Name: "order [name] `[item \n]...`", Help: "列表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
ORDER: {Name: "order `[item\n]...`", Help: "列表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
arg = _name(m, arg)
|
_order_show(m, arg[0], arg[1:]...)
|
||||||
_order_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
|
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
package wiki
|
|
||||||
|
|
||||||
import (
|
|
||||||
ice "github.com/shylinux/icebergs"
|
|
||||||
kit "github.com/shylinux/toolkits"
|
|
||||||
)
|
|
||||||
|
|
||||||
func _other_show(m *ice.Message, name, text string, arg ...string) {
|
|
||||||
_option(m, OTHER, name, text, arg...)
|
|
||||||
m.RenderTemplate(m.Conf(OTHER, kit.Keym(kit.MDB_TEMPLATE)))
|
|
||||||
}
|
|
||||||
|
|
||||||
const OTHER = "other"
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
Index.Merge(&ice.Context{
|
|
||||||
Commands: map[string]*ice.Command{
|
|
||||||
OTHER: {Name: "other [name] url", Help: "网页", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
|
||||||
arg = _name(m, arg)
|
|
||||||
_other_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
|
|
||||||
}},
|
|
||||||
},
|
|
||||||
Configs: map[string]*ice.Config{
|
|
||||||
OTHER: {Name: FIELD, Help: "网页", Value: kit.Data(
|
|
||||||
kit.MDB_TEMPLATE, ``,
|
|
||||||
)},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
@ -2,7 +2,9 @@ package wiki
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
ice "github.com/shylinux/icebergs"
|
ice "github.com/shylinux/icebergs"
|
||||||
"github.com/shylinux/icebergs/base/mdb"
|
"github.com/shylinux/icebergs/base/mdb"
|
||||||
@ -12,49 +14,57 @@ import (
|
|||||||
const PARSE = "parse"
|
const PARSE = "parse"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{
|
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||||
Commands: map[string]*ice.Command{
|
PARSE: {Name: "parse type=auto,json,http,form,time,list auto text:textarea", Help: "解析", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
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 len(arg) < 2 {
|
||||||
if len(arg) < 2 {
|
return
|
||||||
return
|
}
|
||||||
|
|
||||||
|
if arg[1] = strings.TrimSpace(arg[1]); arg[0] != "auto" {
|
||||||
|
|
||||||
|
} else if 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 if _, e := strconv.ParseInt(arg[1], 10, 64); e == nil {
|
||||||
|
arg[0] = "time"
|
||||||
|
} else {
|
||||||
|
arg[0] = "list"
|
||||||
|
}
|
||||||
|
|
||||||
|
switch m.Option(mdb.FIELDS, mdb.DETAIL); 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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if arg[0] == "auto" && (strings.HasPrefix(arg[1], "{") || strings.HasPrefix(arg[1], "[")) {
|
m.EchoQRCode(arg[1])
|
||||||
arg[0] = "json"
|
|
||||||
} else if strings.HasPrefix(arg[1], "http") {
|
case "form":
|
||||||
arg[0] = "http"
|
for _, v := range kit.Split(arg[1], "&", "&", "&") {
|
||||||
} else if strings.Contains(arg[1], "=") {
|
ls := kit.Split(v, "=", "=", "=")
|
||||||
arg[0] = "form"
|
key, _ := url.QueryUnescape(ls[0])
|
||||||
} else {
|
value, _ := url.QueryUnescape(kit.Select("", ls, 1))
|
||||||
arg[0] = "list"
|
m.Push(key, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Option(mdb.FIELDS, mdb.DETAIL)
|
case "time":
|
||||||
switch arg[0] {
|
if i, e := strconv.ParseInt(arg[1], 10, 64); e == nil {
|
||||||
case "json":
|
m.Echo(time.Unix(i, 0).Format(ice.MOD_TIME))
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}},
|
|
||||||
},
|
case "list":
|
||||||
Configs: map[string]*ice.Config{},
|
for i, v := range kit.Split(arg[1]) {
|
||||||
})
|
m.Push(kit.Format(i), v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}},
|
||||||
|
}})
|
||||||
}
|
}
|
||||||
|
@ -8,19 +8,17 @@ import (
|
|||||||
kit "github.com/shylinux/toolkits"
|
kit "github.com/shylinux/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
func _refer_show(m *ice.Message, name, text string, arg ...string) {
|
func _refer_show(m *ice.Message, text string, arg ...string) {
|
||||||
list := [][]string{}
|
list := [][]string{}
|
||||||
for _, v := range kit.Split(strings.TrimSpace(text), "\n", "\n") {
|
for _, v := range kit.Split(strings.TrimSpace(text), ice.MOD_NL, ice.MOD_NL) {
|
||||||
if ls := kit.Split(v); len(ls) == 1 {
|
if ls := kit.Split(v); len(ls) == 1 {
|
||||||
list = append(list, []string{path.Base(ls[0]), ls[0]})
|
list = append(list, []string{path.Base(ls[0]), ls[0]})
|
||||||
} else {
|
} else {
|
||||||
list = append(list, ls)
|
list = append(list, ls)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.Optionv("list", list)
|
m.Optionv(kit.MDB_LIST, list)
|
||||||
|
_wiki_template(m, REFER, "", text, arg...)
|
||||||
_option(m, REFER, name, text, arg...)
|
|
||||||
m.RenderTemplate(m.Conf(REFER, kit.Keym(kit.MDB_TEMPLATE)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const REFER = "refer"
|
const REFER = "refer"
|
||||||
@ -28,9 +26,8 @@ const REFER = "refer"
|
|||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{
|
Index.Merge(&ice.Context{
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
REFER: {Name: "refer [name] `[name url]...`", Help: "参考", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
REFER: {Name: "refer `[[name] url\n]...`", Help: "参考", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
arg = _name(m, arg)
|
_refer_show(m, arg[0], arg[1:]...)
|
||||||
_refer_show(m, arg[0], arg[1], arg[2:]...)
|
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
|
@ -7,11 +7,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func _shell_show(m *ice.Message, name, text string, arg ...string) {
|
func _shell_show(m *ice.Message, name, text string, arg ...string) {
|
||||||
m.Option("output", m.Cmdx(cli.SYSTEM, "sh", "-c", m.Option("input", text)))
|
m.Option(OUTPUT, m.Cmdx(cli.SYSTEM, "sh", "-c", m.Option(INPUT, text)))
|
||||||
_option(m, SHELL, name, text, arg...)
|
_wiki_template(m, SHELL, name, text, arg...)
|
||||||
m.RenderTemplate(m.Conf(SHELL, kit.Keym(kit.MDB_TEMPLATE)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
INPUT = "input"
|
||||||
|
OUTPUT = "output"
|
||||||
|
)
|
||||||
const SHELL = "shell"
|
const SHELL = "shell"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -13,7 +13,7 @@ func _spark_show(m *ice.Message, name, text string, arg ...string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
prompt := kit.Select(name+"> ", m.Conf(SPARK, kit.Keym("prompt", name)))
|
prompt := kit.Select(name+"> ", m.Conf(SPARK, kit.Keym(kit.MDB_PROMPT, name)))
|
||||||
m.Echo(`<div class="story" data-type="spark" data-name="%s">`, name)
|
m.Echo(`<div class="story" data-type="spark" data-name="%s">`, name)
|
||||||
for _, l := range strings.Split(text, "\n") {
|
for _, l := range strings.Split(text, "\n") {
|
||||||
m.Echo("<div>")
|
m.Echo("<div>")
|
||||||
@ -24,6 +24,10 @@ func _spark_show(m *ice.Message, name, text string, arg ...string) {
|
|||||||
m.Echo("</div>")
|
m.Echo("</div>")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
PROMPT = "prompt"
|
||||||
|
)
|
||||||
|
|
||||||
const SPARK = "spark"
|
const SPARK = "spark"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -42,7 +46,7 @@ func init() {
|
|||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
SPARK: {Name: SPARK, Help: "段落", Value: kit.Data(
|
SPARK: {Name: SPARK, Help: "段落", Value: kit.Data(
|
||||||
kit.MDB_TEMPLATE, `<p {{.OptionTemplate}}>{{.Option "text"}}</p>`,
|
kit.MDB_TEMPLATE, `<p {{.OptionTemplate}}>{{.Option "text"}}</p>`,
|
||||||
"prompt", kit.Dict("shell", "$ "),
|
kit.MDB_PROMPT, kit.Dict("shell", "$ "),
|
||||||
)},
|
)},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -7,9 +7,9 @@ import (
|
|||||||
kit "github.com/shylinux/toolkits"
|
kit "github.com/shylinux/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
func _table_show(m *ice.Message, name, text string, arg ...string) {
|
func _table_show(m *ice.Message, text string, arg ...string) {
|
||||||
head, list := []string{}, [][]string{}
|
head, list := []string{}, [][]string{}
|
||||||
for i, v := range kit.Split(strings.TrimSpace(text), "\n") {
|
for i, v := range kit.Split(strings.TrimSpace(text), ice.MOD_NL) {
|
||||||
if v = strings.ReplaceAll(v, "%", "%%"); i == 0 {
|
if v = strings.ReplaceAll(v, "%", "%%"); i == 0 {
|
||||||
head = kit.Split(v)
|
head = kit.Split(v)
|
||||||
} else {
|
} else {
|
||||||
@ -35,8 +35,7 @@ func _table_show(m *ice.Message, name, text string, arg ...string) {
|
|||||||
m.Optionv("head", head)
|
m.Optionv("head", head)
|
||||||
m.Optionv("list", list)
|
m.Optionv("list", list)
|
||||||
|
|
||||||
_option(m, TABLE, name, text, arg...)
|
_wiki_template(m, ORDER, "", text, arg...)
|
||||||
m.RenderTemplate(m.Conf(TABLE, kit.Keym(kit.MDB_TEMPLATE)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const TABLE = "table"
|
const TABLE = "table"
|
||||||
@ -44,9 +43,8 @@ const TABLE = "table"
|
|||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{
|
Index.Merge(&ice.Context{
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
TABLE: {Name: "table [name] `[item item\n]...`", Help: "表格", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
TABLE: {Name: "table `[item item\n]...`", Help: "表格", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
arg = _name(m, arg)
|
_table_show(m, arg[0], arg[1:]...)
|
||||||
_table_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
|
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package wiki
|
package wiki
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
|
|
||||||
ice "github.com/shylinux/icebergs"
|
ice "github.com/shylinux/icebergs"
|
||||||
kit "github.com/shylinux/toolkits"
|
kit "github.com/shylinux/toolkits"
|
||||||
)
|
)
|
||||||
@ -10,12 +8,12 @@ import (
|
|||||||
func _title_show(m *ice.Message, kind, text string, arg ...string) {
|
func _title_show(m *ice.Message, kind, text string, arg ...string) {
|
||||||
switch title, _ := m.Optionv(TITLE).(map[string]int); kind {
|
switch title, _ := m.Optionv(TITLE).(map[string]int); kind {
|
||||||
case PREMENU: // 前置目录
|
case PREMENU: // 前置目录
|
||||||
_option(m, kind, "", strings.TrimSpace(text), arg...)
|
_option(m, kind, "", "", arg...)
|
||||||
m.RenderTemplate(m.Conf(TITLE, kit.Keym(kind)))
|
m.RenderTemplate(m.Conf(TITLE, kit.Keym(kind)))
|
||||||
return
|
return
|
||||||
|
|
||||||
case ENDMENU: // 后置目录
|
case ENDMENU: // 后置目录
|
||||||
_option(m, kind, "", strings.TrimSpace(text), arg...)
|
_option(m, kind, "", "", arg...)
|
||||||
m.RenderTemplate(m.Conf(TITLE, kit.Keym(kind)))
|
m.RenderTemplate(m.Conf(TITLE, kit.Keym(kind)))
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -60,10 +58,14 @@ func init() {
|
|||||||
ns := kit.Split(ice.Info.NodeName, "-")
|
ns := kit.Split(ice.Info.NodeName, "-")
|
||||||
arg = append(arg, ns[len(ns)-1])
|
arg = append(arg, ns[len(ns)-1])
|
||||||
}
|
}
|
||||||
if len(arg) == 1 {
|
switch arg[0] {
|
||||||
arg = append(arg, "")
|
case PREMENU, ENDMENU:
|
||||||
|
_title_show(m, arg[0], "", arg[1:]...)
|
||||||
|
case CHAPTER, SECTION:
|
||||||
|
_title_show(m, arg[0], arg[1], arg[2:]...)
|
||||||
|
default:
|
||||||
|
_title_show(m, "", arg[0], arg[1:]...)
|
||||||
}
|
}
|
||||||
_title_show(m, arg[0], kit.Select(arg[0], arg[1]), arg[2:]...)
|
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
|
@ -2,20 +2,14 @@ package wiki
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
|
||||||
|
|
||||||
ice "github.com/shylinux/icebergs"
|
ice "github.com/shylinux/icebergs"
|
||||||
"github.com/shylinux/icebergs/base/mdb"
|
"github.com/shylinux/icebergs/base/mdb"
|
||||||
kit "github.com/shylinux/toolkits"
|
kit "github.com/shylinux/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
func _video_show(m *ice.Message, name, text string, arg ...string) {
|
func _video_show(m *ice.Message, text string, arg ...string) {
|
||||||
if !strings.HasPrefix(text, "http") && !strings.HasPrefix(text, "/") {
|
_wiki_template(m, VIDEO, "", _wiki_link(m, VIDEO, text), arg...)
|
||||||
text = path.Join("/share/local", _wiki_path(m, FEEL, text))
|
|
||||||
}
|
|
||||||
|
|
||||||
_option(m, VIDEO, name, text, arg...)
|
|
||||||
m.RenderTemplate(m.Conf(VIDEO, kit.Keym(kit.MDB_TEMPLATE)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -29,18 +23,18 @@ const VIDEO = "video"
|
|||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{
|
Index.Merge(&ice.Context{
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
VIDEO: {Name: "video [name] url", Help: "视频", Action: map[string]*ice.Action{
|
VIDEO: {Name: "video url", Help: "视频", Action: map[string]*ice.Action{
|
||||||
mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
|
mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
|
||||||
_video_show(m, arg[1], path.Join(arg[2], arg[1]))
|
_video_show(m, path.Join(arg[2], 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) {
|
||||||
arg = _name(m, arg)
|
_video_show(m, arg[0], arg[1:]...)
|
||||||
_video_show(m, arg[0], arg[1], arg[2:]...)
|
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
VIDEO: {Name: "video", Help: "视频", Value: kit.Data(
|
VIDEO: {Name: "video", Help: "视频", Value: kit.Data(
|
||||||
kit.MDB_TEMPLATE, `<video {{.OptionTemplate}} title="{{.Option "text"}}" src="{{.Option "text"}}" controls></video>`,
|
kit.MDB_TEMPLATE, `<video {{.OptionTemplate}} title="{{.Option "text"}}" src="{{.Option "text"}}" controls></video>`,
|
||||||
|
kit.MDB_PATH, "usr/local/image",
|
||||||
)},
|
)},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -13,6 +13,12 @@ import (
|
|||||||
func _wiki_path(m *ice.Message, cmd string, arg ...string) string {
|
func _wiki_path(m *ice.Message, cmd string, arg ...string) string {
|
||||||
return path.Join(m.Option(ice.MSG_LOCAL), m.Conf(cmd, kit.META_PATH), path.Join(arg...))
|
return path.Join(m.Option(ice.MSG_LOCAL), m.Conf(cmd, kit.META_PATH), path.Join(arg...))
|
||||||
}
|
}
|
||||||
|
func _wiki_link(m *ice.Message, cmd string, text string) string {
|
||||||
|
if !strings.HasPrefix(text, "http") && !strings.HasPrefix(text, "/") {
|
||||||
|
text = path.Join("/share/local", _wiki_path(m, cmd, text))
|
||||||
|
}
|
||||||
|
return text
|
||||||
|
}
|
||||||
func _wiki_list(m *ice.Message, cmd string, arg ...string) bool {
|
func _wiki_list(m *ice.Message, cmd string, arg ...string) bool {
|
||||||
m.Option(nfs.DIR_ROOT, _wiki_path(m, cmd))
|
m.Option(nfs.DIR_ROOT, _wiki_path(m, cmd))
|
||||||
if len(arg) == 0 || strings.HasSuffix(arg[0], "/") {
|
if len(arg) == 0 || strings.HasSuffix(arg[0], "/") {
|
||||||
@ -59,7 +65,9 @@ var Index = &ice.Context{Name: WIKI, Help: "文档中心",
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
web.Index.Register(Index, &web.Frame{},
|
web.Index.Register(Index, &web.Frame{},
|
||||||
FEEL, WORD, DATA, DRAW, IMAGE, SPARK,
|
FEEL, WORD, DATA, DRAW,
|
||||||
TITLE,
|
TITLE, BRIEF,
|
||||||
|
|
||||||
|
IMAGE, SPARK,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,3 @@
|
|||||||
title
|
|
||||||
title "hi"
|
|
||||||
premenu
|
|
||||||
chapter "文档"
|
|
||||||
section "文档"
|
|
||||||
endmenu
|
|
||||||
return
|
|
||||||
|
|
||||||
field "影音" web.wiki.feel
|
|
||||||
field "数据" web.wiki.data
|
|
||||||
field "文档" web.wiki.word
|
|
||||||
field "绘图" web.wiki.draw
|
|
||||||
|
|
||||||
title.go
|
title.go
|
||||||
brief.go
|
brief.go
|
||||||
refer.go
|
refer.go
|
||||||
@ -19,16 +6,13 @@ spark.go
|
|||||||
order.go
|
order.go
|
||||||
table.go
|
table.go
|
||||||
chart.go
|
chart.go
|
||||||
|
|
||||||
image.go
|
image.go
|
||||||
video.go
|
video.go
|
||||||
music.go
|
|
||||||
|
|
||||||
field.go
|
field.go
|
||||||
shell.go
|
shell.go
|
||||||
local.go
|
local.go
|
||||||
parse.go
|
parse.go
|
||||||
other.go
|
|
||||||
|
|
||||||
data.go
|
data.go
|
||||||
draw.go
|
draw.go
|
||||||
@ -37,3 +21,9 @@ word.go
|
|||||||
|
|
||||||
wiki.go
|
wiki.go
|
||||||
wiki.shy
|
wiki.shy
|
||||||
|
|
||||||
|
field "影音" web.wiki.feel
|
||||||
|
field "数据" web.wiki.data
|
||||||
|
field "文档" web.wiki.word
|
||||||
|
field "绘图" web.wiki.draw
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user