This is an automated email from the ASF dual-hosted git repository. kumfo pushed a commit to branch feat/1.7.0/quicklinks in repository https://gitbox.apache.org/repos/asf/answer-plugins.git
commit f5d39e10554270026017fa3443e656e5f6e1bf0a Author: kumfo <ku...@sifou.com> AuthorDate: Wed Aug 13 14:42:37 2025 +0800 feat: add quick links plugin --- README.md | 6 +++ quick-links/basic.go | 88 +++++++++++++++++++++++++++++++++++++++++ quick-links/go.mod | 55 ++++++++++++++++++++++++++ quick-links/i18n/en_US.yaml | 36 +++++++++++++++++ quick-links/i18n/translation.go | 10 +++++ quick-links/i18n/zh_CN.yaml | 36 +++++++++++++++++ quick-links/info.yaml | 22 +++++++++++ 7 files changed, 253 insertions(+) diff --git a/README.md b/README.md index 41b0a27..26310d5 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,12 @@ The Notification plugin helps us to send messages to third-party notification sy - [x] [Ding talk](https://github.com/apache/answer-plugins/tree/main/notification-dingtalk) - [x] [WeCom](https://github.com/apache/answer-plugins/tree/main/notification-wecom) +### Sidebar + +Customize the sidebar tags or link. + +- [x] [Quicklinks](https://github.com/apache/answer-plugins/tree/main/quick-links) + ### Route Support for custom routing. diff --git a/quick-links/basic.go b/quick-links/basic.go new file mode 100644 index 0000000..4591067 --- /dev/null +++ b/quick-links/basic.go @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +// Package quick_links +package quick_links + +import ( + "embed" + "encoding/json" + "github.com/apache/answer-plugins/quick-links/i18n" + "github.com/apache/answer-plugins/util" + "github.com/apache/answer/plugin" +) + +//go:embed info.yaml +var Info embed.FS + +type QuickLinks struct { + Config *plugin.SidebarConfig +} + +func init() { + plugin.Register(&QuickLinks{ + Config: &plugin.SidebarConfig{}, + }) +} + +func (q *QuickLinks) Info() plugin.Info { + info := &util.Info{} + info.GetInfo(Info) + + return plugin.Info{ + Name: plugin.MakeTranslator(i18n.InfoName), + SlugName: info.SlugName, + Description: plugin.MakeTranslator(i18n.InfoDescription), + Author: info.Author, + Version: info.Version, + Link: info.Link, + } +} + +func (e *QuickLinks) ConfigFields() []plugin.ConfigField { + return []plugin.ConfigField{ + { + Name: "tags", + Type: plugin.ConfigTypeTagSelector, + Title: plugin.MakeTranslator(i18n.ConfigTagsTitle), + Description: plugin.MakeTranslator(i18n.ConfigTagsDescription), + Value: e.Config.Tags, + }, + { + Name: "links_text", + Type: plugin.ConfigTypeTextarea, + Title: plugin.MakeTranslator(i18n.ConfigLinksTitle), + Description: plugin.MakeTranslator(i18n.ConfigLinksDescription), + Value: e.Config.LinksText, + }, + } +} + +func (e *QuickLinks) ConfigReceiver(config []byte) error { + c := &plugin.SidebarConfig{} + _ = json.Unmarshal(config, c) + e.Config = c + return nil +} + +// todo +func (q *QuickLinks) GetSidebarConfig() (sidebarConfig *plugin.SidebarConfig, err error) { + sidebarConfig = q.Config + return +} diff --git a/quick-links/go.mod b/quick-links/go.mod new file mode 100644 index 0000000..fc1427e --- /dev/null +++ b/quick-links/go.mod @@ -0,0 +1,55 @@ +module github.com/apache/answer-plugins/quick-links + +go 1.23.3 + +require ( + github.com/apache/answer v1.7.0 + github.com/apache/answer-plugins/util v1.0.3 +) + +require ( + github.com/LinkinStars/go-i18n/v2 v2.2.2 // indirect + github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect + github.com/aymerick/douceur v0.2.0 // indirect + github.com/bytedance/sonic v1.12.2 // indirect + github.com/bytedance/sonic/loader v0.2.0 // indirect + github.com/cloudwego/base64x v0.1.4 // indirect + github.com/cloudwego/iasm v0.2.0 // indirect + github.com/gabriel-vasile/mimetype v1.4.5 // indirect + github.com/gin-contrib/sse v0.1.0 // indirect + github.com/gin-gonic/gin v1.10.0 // indirect + github.com/go-playground/locales v0.14.1 // indirect + github.com/go-playground/universal-translator v0.18.1 // indirect + github.com/go-playground/validator/v10 v10.22.1 // indirect + github.com/goccy/go-json v0.10.3 // indirect + github.com/golang/snappy v0.0.4 // indirect + github.com/google/wire v0.5.0 // indirect + github.com/gorilla/css v1.0.1 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/klauspost/cpuid/v2 v2.2.8 // indirect + github.com/leodido/go-urn v1.4.0 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/microcosm-cc/bluemonday v1.0.27 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/pelletier/go-toml/v2 v2.2.3 // indirect + github.com/segmentfault/pacman v1.0.5-0.20230822083413-c0075a2d401f // indirect + github.com/segmentfault/pacman/contrib/i18n v0.0.0-20230822083413-c0075a2d401f // indirect + github.com/syndtr/goleveldb v1.0.0 // indirect + github.com/tidwall/gjson v1.17.3 // indirect + github.com/tidwall/match v1.1.1 // indirect + github.com/tidwall/pretty v1.2.1 // indirect + github.com/twitchyliquid64/golang-asm v0.15.1 // indirect + github.com/ugorji/go/codec v1.2.12 // indirect + github.com/yuin/goldmark v1.7.4 // indirect + golang.org/x/arch v0.10.0 // indirect + golang.org/x/crypto v0.36.0 // indirect + golang.org/x/net v0.38.0 // indirect + golang.org/x/sys v0.31.0 // indirect + golang.org/x/text v0.23.0 // indirect + google.golang.org/protobuf v1.34.2 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect + sigs.k8s.io/yaml v1.4.0 // indirect + xorm.io/builder v0.3.13 // indirect + xorm.io/xorm v1.3.2 // indirect +) diff --git a/quick-links/i18n/en_US.yaml b/quick-links/i18n/en_US.yaml new file mode 100644 index 0000000..c1925dc --- /dev/null +++ b/quick-links/i18n/en_US.yaml @@ -0,0 +1,36 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +plugin: + quick_links: + backend: + info: + name: + other: Quick Links + description: + other: Customize the sidebar tags or links + config: + tags: + title: + other: Tags + description: + other: Quickly accessible tags in sidebar. + links: + title: + other: Links + description: + other: Separate “title, URL” with commas. One link per line. \ No newline at end of file diff --git a/quick-links/i18n/translation.go b/quick-links/i18n/translation.go new file mode 100644 index 0000000..69e74e8 --- /dev/null +++ b/quick-links/i18n/translation.go @@ -0,0 +1,10 @@ +package i18n + +const ( + InfoName = "plugin.quick_links.backend.info.name" + InfoDescription = "plugin.quick_links.backend.info.description" + ConfigTagsTitle = "plugin.quick_links.backend.config.tags.title" + ConfigTagsDescription = "plugin.quick_links.backend.config.tags.description" + ConfigLinksTitle = "plugin.quick_links.backend.config.links.title" + ConfigLinksDescription = "plugin.quick_links.backend.config.links.description" +) diff --git a/quick-links/i18n/zh_CN.yaml b/quick-links/i18n/zh_CN.yaml new file mode 100644 index 0000000..864bffb --- /dev/null +++ b/quick-links/i18n/zh_CN.yaml @@ -0,0 +1,36 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +plugin: + quick_links: + backend: + info: + name: + other: 快捷链接 + description: + other: 自定义侧边栏标签或链接 + config: + tags: + title: + other: 标签 + description: + other: 侧边栏中的标签可快速访问 + links: + title: + other: 链接 + description: + other: 用英文逗号分隔标题和链接,每行一个链接:“title, URL” \ No newline at end of file diff --git a/quick-links/info.yaml b/quick-links/info.yaml new file mode 100644 index 0000000..7c4068e --- /dev/null +++ b/quick-links/info.yaml @@ -0,0 +1,22 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +slug_name: quick_links +type: sidebar +version: 0.0.1 +author: answerdev +link: https://github.com/apache/answer-plugins/tree/main/quick-links