From 08f8ba87305469bc83f0a5c75f8e58e785c5a077 Mon Sep 17 00:00:00 2001 From: shaoying Date: Mon, 26 Jul 2021 07:36:09 +0800 Subject: [PATCH] opt wiki --- core/wiki/field.go | 3 +-- core/wiki/image.go | 5 +---- core/wiki/local.go | 3 +-- core/wiki/order.go | 5 +---- core/wiki/refer.go | 5 +---- core/wiki/shell.go | 5 +---- core/wiki/table.go | 4 +--- core/wiki/template.go | 1 - core/wiki/title.go | 47 ++++++++++++++++++++----------------------- core/wiki/video.go | 16 +++++++-------- core/wiki/wiki.go | 1 + core/wiki/wiki.shy | 40 +++++++++++++++++++++++------------- core/wiki/word.go | 6 +++--- misc.go | 1 + 14 files changed, 67 insertions(+), 75 deletions(-) delete mode 100644 core/wiki/template.go diff --git a/core/wiki/field.go b/core/wiki/field.go index 0ce7a8ea..3b7d983c 100644 --- a/core/wiki/field.go +++ b/core/wiki/field.go @@ -84,8 +84,7 @@ func init() { }, Configs: map[string]*ice.Config{ FIELD: {Name: FIELD, Help: "插件", Value: kit.Data( - kit.MDB_TEMPLATE, `
+ kit.MDB_TEMPLATE, `
{{.Option "name"}}
diff --git a/core/wiki/image.go b/core/wiki/image.go index 7aec5930..651386fc 100644 --- a/core/wiki/image.go +++ b/core/wiki/image.go @@ -42,10 +42,7 @@ func init() { }, Configs: map[string]*ice.Config{ IMAGE: {Name: IMAGE, Help: "图片", Value: kit.Data( - kit.MDB_TEMPLATE, ``, + kit.MDB_TEMPLATE, ``, )}, }, }) diff --git a/core/wiki/local.go b/core/wiki/local.go index 34ca9fce..c6d6d55f 100644 --- a/core/wiki/local.go +++ b/core/wiki/local.go @@ -24,8 +24,7 @@ func init() { }, Configs: map[string]*ice.Config{ LOCAL: {Name: LOCAL, Help: "文件", Value: kit.Data( - kit.MDB_TEMPLATE, `{{range $index, $value := .Optionv "input"}}{{$value}}{{end}}`, + kit.MDB_TEMPLATE, `{{range $index, $value := .Optionv "input"}}{{$value}}{{end}}`, )}, }, }) diff --git a/core/wiki/order.go b/core/wiki/order.go index b8b75848..eaa54ac0 100644 --- a/core/wiki/order.go +++ b/core/wiki/order.go @@ -25,10 +25,7 @@ func init() { }, Configs: map[string]*ice.Config{ ORDER: {Name: ORDER, Help: "列表", Value: kit.Data( - kit.MDB_TEMPLATE, `
    -{{range $index, $value := .Optionv "list"}}
  • {{$value}}
  • {{end}}
`, + kit.MDB_TEMPLATE, `
    {{range $index, $value := .Optionv "list"}}
  • {{$value}}
  • {{end}}
`, )}, }, }) diff --git a/core/wiki/refer.go b/core/wiki/refer.go index f8fb548c..80ea58d9 100644 --- a/core/wiki/refer.go +++ b/core/wiki/refer.go @@ -35,10 +35,7 @@ func init() { }, Configs: map[string]*ice.Config{ REFER: {Name: REFER, Help: "参考", Value: kit.Data( - kit.MDB_TEMPLATE, `
    -{{range $index, $value := .Optionv "list"}}
  • {{index $value 0}}: {{index $value 1}}
  • {{end}}
`, + kit.MDB_TEMPLATE, ``, )}, }, }) diff --git a/core/wiki/shell.go b/core/wiki/shell.go index 017ca366..835ebf88 100644 --- a/core/wiki/shell.go +++ b/core/wiki/shell.go @@ -24,10 +24,7 @@ func init() { }, Configs: map[string]*ice.Config{ SHELL: {Name: SHELL, Help: "命令", Value: kit.Data( - kit.MDB_TEMPLATE, `$ {{.Option "input"}} # {{.Option "name"}} + kit.MDB_TEMPLATE, `$ {{.Option "input"}} # {{.Option "name"}} {{.Option "output"}}`, )}, }, diff --git a/core/wiki/table.go b/core/wiki/table.go index 93d07dce..92e8baad 100644 --- a/core/wiki/table.go +++ b/core/wiki/table.go @@ -51,9 +51,7 @@ func init() { }, Configs: map[string]*ice.Config{ TABLE: {Name: TABLE, Help: "表格", Value: kit.Data( - kit.MDB_TEMPLATE, ` + kit.MDB_TEMPLATE, `
{{range $i, $v := .Optionv "head"}}{{end}} {{range $index, $value := .Optionv "list"}} {{range $i, $v := $value}}{{end}} diff --git a/core/wiki/template.go b/core/wiki/template.go deleted file mode 100644 index 3e1ef4c3..00000000 --- a/core/wiki/template.go +++ /dev/null @@ -1 +0,0 @@ -package wiki diff --git a/core/wiki/title.go b/core/wiki/title.go index 0b1c7775..635a0b63 100644 --- a/core/wiki/title.go +++ b/core/wiki/title.go @@ -1,7 +1,6 @@ package wiki import ( - "fmt" "strings" ice "github.com/shylinux/icebergs" @@ -9,40 +8,39 @@ import ( ) func _title_show(m *ice.Message, kind, text string, arg ...string) { - title, _ := m.Optionv(TITLE).(map[string]int) - switch kind { + switch title, _ := m.Optionv(TITLE).(map[string]int); kind { case PREMENU: // 前置目录 - m.RenderTemplate(premenu) + _option(m, kind, "", strings.TrimSpace(text), arg...) + m.RenderTemplate(m.Conf(TITLE, kit.Keym(kind))) return case ENDMENU: // 后置目录 - m.RenderTemplate(endmenu) + _option(m, kind, "", strings.TrimSpace(text), arg...) + m.RenderTemplate(m.Conf(TITLE, kit.Keym(kind))) return case SECTION: // 分节标题 title[SECTION]++ - m.Option("level", "h3") - m.Option("prefix", fmt.Sprintf("%d.%d ", title[CHAPTER], title[SECTION])) + m.Option(kit.MDB_LEVEL, "h3") + m.Option(kit.MDB_PREFIX, kit.Format("%d.%d ", title[CHAPTER], title[SECTION])) case CHAPTER: // 章节标题 title[CHAPTER]++ title[SECTION] = 0 - m.Option("level", "h2") - m.Option("prefix", fmt.Sprintf("%d ", title[CHAPTER])) + m.Option(kit.MDB_LEVEL, "h2") + m.Option(kit.MDB_PREFIX, kit.Format("%d ", title[CHAPTER])) default: // 文章标题 - m.Option("level", "h1") - m.Option("prefix", "") + m.Option(kit.MDB_LEVEL, "h1") + m.Option(kit.MDB_PREFIX, "") } - // 添加目录 - menu, _ := m.Optionv("menu").(map[string]interface{}) - menu["list"] = append(menu["list"].([]interface{}), map[string]interface{}{ - "level": m.Option("level"), "prefix": m.Option("prefix"), "content": m.Option("content", text), - }) - // 渲染引擎 _wiki_template(m, TITLE, "", text, arg...) + + // 添加目录 + menu, _ := m.Optionv(kit.MDB_MENU).(map[string]interface{}) + menu[kit.MDB_LIST] = append(menu[kit.MDB_LIST].([]interface{}), kit.Dict(m.OptionSimple("level,prefix,text"))) } const ( @@ -59,8 +57,8 @@ func init() { Commands: map[string]*ice.Command{ TITLE: {Name: "title [premenu|chapter|section|endmenu] text", Help: "标题", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) == 0 { - ns := strings.Split(ice.Info.NodeName, "-") - arg = append(arg, kit.Select(ns[len(ns)-1], "")) + ns := kit.Split(ice.Info.NodeName, "-") + arg = append(arg, ns[len(ns)-1]) } if len(arg) == 1 { arg = append(arg, "") @@ -70,13 +68,12 @@ func init() { }, Configs: map[string]*ice.Config{ TITLE: {Name: TITLE, Help: "标题", Value: kit.Data( - kit.MDB_TEMPLATE, `<{{.Option "level"}} {{.OptionTemplate}}>{{.Option "prefix"}} {{.Option "content"}}`, + kit.MDB_TEMPLATE, `<{{.Option "level"}} {{.OptionTemplate}}>{{.Option "prefix"}} {{.Option "text"}}`, + PREMENU, `
    `, + ENDMENU, `
      {{$menu := .Optionv "menu"}} +{{range $index, $value := Value $menu "list"}}
    • {{Value $value "prefix"}} {{Value $value "text"}}
    • {{end}} +
    `, )}, }, }) } - -var premenu = `
      ` -var endmenu = `
        {{$menu := .Optionv "menu"}}{{range $index, $value := Value $menu "list"}} -
      • {{Value $value "prefix"}} {{Value $value "content"}}
      • {{end}} -
      ` diff --git a/core/wiki/video.go b/core/wiki/video.go index ab4af5bd..92400fe7 100644 --- a/core/wiki/video.go +++ b/core/wiki/video.go @@ -9,11 +9,6 @@ import ( kit "github.com/shylinux/toolkits" ) -var video = `` - func _video_show(m *ice.Message, name, text string, arg ...string) { if !strings.HasPrefix(text, "http") && !strings.HasPrefix(text, "/") { text = path.Join("/share/local", _wiki_path(m, FEEL, text)) @@ -33,9 +28,6 @@ const VIDEO = "video" func init() { Index.Merge(&ice.Context{ - Configs: map[string]*ice.Config{ - VIDEO: {Name: "video", Help: "视频", Value: kit.Data(kit.MDB_TEMPLATE, video)}, - }, Commands: map[string]*ice.Command{ VIDEO: {Name: "video [name] url", Help: "视频", Action: map[string]*ice.Action{ mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) { @@ -45,5 +37,11 @@ func init() { arg = _name(m, arg) _video_show(m, arg[0], arg[1], arg[2:]...) }}, - }}) + }, + Configs: map[string]*ice.Config{ + VIDEO: {Name: "video", Help: "视频", Value: kit.Data( + kit.MDB_TEMPLATE, ``, + )}, + }, + }) } diff --git a/core/wiki/wiki.go b/core/wiki/wiki.go index b6d7a6df..fc638dfe 100644 --- a/core/wiki/wiki.go +++ b/core/wiki/wiki.go @@ -60,5 +60,6 @@ var Index = &ice.Context{Name: WIKI, Help: "文档中心", func init() { web.Index.Register(Index, &web.Frame{}, FEEL, WORD, DATA, DRAW, IMAGE, SPARK, + TITLE, ) } diff --git a/core/wiki/wiki.shy b/core/wiki/wiki.shy index 04608df6..d0e77c79 100644 --- a/core/wiki/wiki.shy +++ b/core/wiki/wiki.shy @@ -1,27 +1,39 @@ +title +title "hi" +premenu chapter "文档" +section "文档" +endmenu +return field "影音" web.wiki.feel field "数据" web.wiki.data -field "绘图" web.wiki.draw -return field "文档" web.wiki.word - -field "绘图" web.wiki.draw -field "绘图" web.wiki.draw field "绘图" web.wiki.draw -wiki.go -wiki.shy - -feel.go -word.go -data.go -draw.go +title.go +brief.go +refer.go +spark.go +order.go +table.go chart.go + image.go video.go music.go -baidu.go -template.go +field.go +shell.go +local.go +parse.go +other.go + +data.go +draw.go +feel.go +word.go + +wiki.go +wiki.shy diff --git a/core/wiki/word.go b/core/wiki/word.go index b50dba4d..bc16f4a0 100644 --- a/core/wiki/word.go +++ b/core/wiki/word.go @@ -31,9 +31,9 @@ func _option(m *ice.Message, kind, name, text string, arg ...string) { func _word_show(m *ice.Message, name string, arg ...string) { m.Set(ice.MSG_RESULT) m.Option(TITLE, map[string]int{}) - m.Option("menu", kit.Dict("list", []interface{}{})) + m.Option(kit.MDB_MENU, kit.Dict(kit.MDB_LIST, []interface{}{})) - m.Option(ice.MSG_ALIAS, m.Confv(WORD, kit.Keym("alias"))) + m.Option(ice.MSG_ALIAS, m.Confv(WORD, kit.Keym(kit.MDB_ALIAS))) m.Option(nfs.DIR_ROOT, _wiki_path(m, WORD)) m.Option(ice.MSG_RENDER, ice.RENDER_RAW) m.Cmdy(ssh.SOURCE, name) @@ -50,7 +50,7 @@ func init() { Index.Merge(&ice.Context{ Configs: map[string]*ice.Config{ WORD: {Name: WORD, Help: "语言文字", Value: kit.Data( - kit.MDB_PATH, "", kit.MDB_REGEXP, ".*\\.shy", "alias", kit.Dict( + kit.MDB_PATH, "", kit.MDB_REGEXP, ".*\\.shy", kit.MDB_ALIAS, kit.Dict( PREMENU, []interface{}{TITLE, PREMENU}, CHAPTER, []interface{}{TITLE, CHAPTER}, SECTION, []interface{}{TITLE, SECTION}, diff --git a/misc.go b/misc.go index 6482fe1c..ce983b97 100644 --- a/misc.go +++ b/misc.go @@ -275,6 +275,7 @@ func (m *Message) RenderResult(args ...interface{}) *Message { return m.Render(RENDER_RESULT, args...) } func (m *Message) RenderTemplate(args ...interface{}) *Message { + return m.Render(RENDER_TEMPLATE, args...) } func (m *Message) RenderDownload(args ...interface{}) *Message {
      {{$v}}
      {{$v}}