This is an automated email from the ASF dual-hosted git repository. kumfo pushed a commit to branch feat/embed in repository https://gitbox.apache.org/repos/asf/incubator-answer-plugins.git
commit f83100fcd1992647cbf96504cf401f41df6610a4 Author: kumfo <[email protected]> AuthorDate: Mon May 27 14:34:58 2024 +0800 feat(embed): add basic embed plugin --- embed-basic/basic.go | 153 ++++++++++++++++++++++++++++++++++++++++ embed-basic/go.mod | 43 +++++++++++ embed-basic/i18n/en_US.yaml | 49 +++++++++++++ embed-basic/i18n/translation.go | 36 ++++++++++ embed-basic/i18n/zh_CN.yaml | 49 +++++++++++++ 5 files changed, 330 insertions(+) diff --git a/embed-basic/basic.go b/embed-basic/basic.go new file mode 100644 index 0000000..3abfebb --- /dev/null +++ b/embed-basic/basic.go @@ -0,0 +1,153 @@ +/* + * 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 embed_basic + +import ( + "encoding/json" + "github.com/apache/incubator-answer-plugins/embed-basic/i18n" + "github.com/apache/incubator-answer/plugin" +) + +type Embed struct { + Config *EmbedConfig +} + +type EmbedConfig struct { + Codepen bool `json:"codepen"` + Dropbox bool `json:"dropbox"` + Excalidraw bool `json:"excalidraw"` + Figma bool `json:"figma"` + Githubgist bool `json:"githubgist"` + Jsfiddle bool `json:"jsfiddle"` + Loom bool `json:"loom"` + Twitter bool `json:"twitter"` + Youtube bool `json:"youtube"` +} + +func init() { + plugin.Register(&Embed{ + Config: &EmbedConfig{}, + }) +} + +func (e *Embed) Info() plugin.Info { + return plugin.Info{ + Name: plugin.MakeTranslator(i18n.InfoName), + SlugName: "basic_embed", + Description: plugin.MakeTranslator(i18n.InfoDescription), + Author: "answerdev", + Version: "1.0.0", + Link: "https://github.com/apache/incubator-answer-plugins/tree/main/embed-basic", + } +} + +func (e *Embed) ConfigFields() []plugin.ConfigField { + return []plugin.ConfigField{ + { + Name: "CodePen", + Type: plugin.ConfigTypeSwitch, + Title: plugin.MakeTranslator(i18n.ConfigEmbedsTitle), + UIOptions: plugin.ConfigFieldUIOptions{ + Label: plugin.MakeTranslator(i18n.ConfigOptionCodepen), + FieldClassName: "mb-0", + }, + Value: e.Config.Codepen, + }, + { + Name: "Dropbox", + Type: plugin.ConfigTypeSwitch, + UIOptions: plugin.ConfigFieldUIOptions{ + Label: plugin.MakeTranslator(i18n.ConfigOptionDropbox), + FieldClassName: "mb-0", + }, + Value: e.Config.Dropbox, + }, + { + Name: "Excalidraw", + Type: plugin.ConfigTypeSwitch, + UIOptions: plugin.ConfigFieldUIOptions{ + Label: plugin.MakeTranslator(i18n.ConfigOptionExcalidraw), + FieldClassName: "mb-0", + }, + Value: e.Config.Excalidraw, + }, + { + Name: "Figma", + Type: plugin.ConfigTypeSwitch, + UIOptions: plugin.ConfigFieldUIOptions{ + Label: plugin.MakeTranslator(i18n.ConfigOptionFigma), + FieldClassName: "mb-0", + }, + Value: e.Config.Figma, + }, + { + Name: "GithubGist", + Type: plugin.ConfigTypeSwitch, + UIOptions: plugin.ConfigFieldUIOptions{ + Label: plugin.MakeTranslator(i18n.ConfigOptionGithubgist), + FieldClassName: "mb-0", + }, + Value: e.Config.Githubgist, + }, + { + Name: "JSFiddle", + Type: plugin.ConfigTypeSwitch, + UIOptions: plugin.ConfigFieldUIOptions{ + Label: plugin.MakeTranslator(i18n.ConfigOptionJsfiddle), + FieldClassName: "mb-0", + }, + Value: e.Config.Jsfiddle, + }, + { + Name: "Loom", + Type: plugin.ConfigTypeSwitch, + UIOptions: plugin.ConfigFieldUIOptions{ + Label: plugin.MakeTranslator(i18n.ConfigOptionLoom), + FieldClassName: "mb-0", + }, + Value: e.Config.Loom, + }, + { + Name: "Twitter", + Type: plugin.ConfigTypeSwitch, + UIOptions: plugin.ConfigFieldUIOptions{ + Label: plugin.MakeTranslator(i18n.ConfigOptionTwitter), + FieldClassName: "mb-0", + }, + Value: e.Config.Twitter, + }, + { + Name: "YouTube", + Type: plugin.ConfigTypeSwitch, + UIOptions: plugin.ConfigFieldUIOptions{ + Label: plugin.MakeTranslator(i18n.ConfigOptionYoutube), + }, + Value: e.Config.Youtube, + Description: plugin.MakeTranslator(i18n.ConfigEmbedsDescription), + }, + } +} + +func (e *Embed) ConfigReceiver(config []byte) error { + c := &EmbedConfig{} + _ = json.Unmarshal(config, c) + e.Config = c + return nil +} diff --git a/embed-basic/go.mod b/embed-basic/go.mod new file mode 100644 index 0000000..6602618 --- /dev/null +++ b/embed-basic/go.mod @@ -0,0 +1,43 @@ +module github.com/apache/incubator-answer-plugins/embed-basic + +go 1.19 + +require github.com/apache/incubator-answer v1.2.5-RC1.0.20240315093158-ba71c22bc841 + +require ( + github.com/LinkinStars/go-i18n/v2 v2.2.2 // indirect + github.com/aymerick/douceur v0.2.0 // indirect + github.com/bytedance/sonic v1.9.1 // indirect + github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect + github.com/gabriel-vasile/mimetype v1.4.2 // indirect + github.com/gin-contrib/sse v0.1.0 // indirect + github.com/gin-gonic/gin v1.9.1 // 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.14.0 // indirect + github.com/goccy/go-json v0.10.2 // indirect + github.com/google/wire v0.5.0 // indirect + github.com/gorilla/css v1.0.0 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/klauspost/cpuid/v2 v2.2.4 // indirect + github.com/kr/text v0.2.0 // indirect + github.com/leodido/go-urn v1.2.4 // indirect + github.com/mattn/go-isatty v0.0.19 // indirect + github.com/microcosm-cc/bluemonday v1.0.21 // 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.0.8 // indirect + github.com/segmentfault/pacman v1.0.5-0.20230822083413-c0075a2d401f // indirect + github.com/segmentfault/pacman/contrib/i18n v0.0.0-20230516093754-b76aef1c1150 // indirect + github.com/twitchyliquid64/golang-asm v0.15.1 // indirect + github.com/ugorji/go/codec v1.2.11 // indirect + golang.org/x/arch v0.3.0 // indirect + golang.org/x/crypto v0.21.0 // indirect + golang.org/x/net v0.21.0 // indirect + golang.org/x/sys v0.18.0 // indirect + golang.org/x/text v0.14.0 // indirect + google.golang.org/protobuf v1.30.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect + sigs.k8s.io/yaml v1.3.0 // indirect +) diff --git a/embed-basic/i18n/en_US.yaml b/embed-basic/i18n/en_US.yaml new file mode 100644 index 0000000..c12aab1 --- /dev/null +++ b/embed-basic/i18n/en_US.yaml @@ -0,0 +1,49 @@ +# 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: + basic_embed: + backend: + info: + name: + other: Embed + description: + other: Embed content from other sites + config: + embeds: + title: + other: Supported embeds + description: + other: Embed rich content such as Tweets, YouTube videos, etc. + options: + codepen: + other: CodePen + dropbox: + other: Dropbox + excalidraw: + other: Excalidraw + figma: + other: Figma + githubgist: + other: GitHub Gist + jsfiddle: + other: JSFiddle + loom: + other: Loom + twitter: + other: X(Twitter) + youtube: + other: YouTube \ No newline at end of file diff --git a/embed-basic/i18n/translation.go b/embed-basic/i18n/translation.go new file mode 100644 index 0000000..5f7292b --- /dev/null +++ b/embed-basic/i18n/translation.go @@ -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. + */ + +package i18n + +const ( + InfoName = "plugin.basic_embed.backend.info.name" + InfoDescription = "plugin.basic_embed.backend.info.description" + ConfigEmbedsTitle = "plugin.basic_embed.backend.config.embeds.title" + ConfigEmbedsDescription = "plugin.basic_embed.backend.config.embeds.description" + ConfigOptionCodepen = "plugin.basic_embed.backend.config.options.codepen" + ConfigOptionDropbox = "plugin.basic_embed.backend.config.options.dropbox" + ConfigOptionExcalidraw = "plugin.basic_embed.backend.config.options.excalidraw" + ConfigOptionFigma = "plugin.basic_embed.backend.config.options.figma" + ConfigOptionGithubgist = "plugin.basic_embed.backend.config.options.githubgist" + ConfigOptionJsfiddle = "plugin.basic_embed.backend.config.options.jsfiddle" + ConfigOptionLoom = "plugin.basic_embed.backend.config.options.loom" + ConfigOptionTwitter = "plugin.basic_embed.backend.config.options.twitter" + ConfigOptionYoutube = "plugin.basic_embed.backend.config.options.youtube" +) diff --git a/embed-basic/i18n/zh_CN.yaml b/embed-basic/i18n/zh_CN.yaml new file mode 100644 index 0000000..b9cec97 --- /dev/null +++ b/embed-basic/i18n/zh_CN.yaml @@ -0,0 +1,49 @@ +# 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: + basic_embed: + backend: + info: + name: + other: 内容嵌入 + description: + other: 在内容中嵌入其他网站 + config: + embeds: + title: + other: 支持的嵌入 + description: + other: 嵌入富文本,例如: Tweets,YouTube 视频等等 + options: + codepen: + other: CodePen + dropbox: + other: Dropbox + excalidraw: + other: Excalidraw + figma: + other: Figma + githubgist: + other: GitHub Gist + jsfiddle: + other: JSFiddle + loom: + other: Loom + twitter: + other: X(Twitter) + youtube: + other: YouTube \ No newline at end of file
