From 5cb74b286f479efb19f6073ab82b21411d62bf31 Mon Sep 17 00:00:00 2001 From: nineya Date: Wed, 20 Dec 2023 01:47:37 +0800 Subject: [PATCH] =?UTF-8?q?feat(vditorOptions):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=B8=BB=E9=A2=98=E6=8E=A7=E5=88=B6=E7=BC=96=E8=BE=91=E5=99=A8?= =?UTF-8?q?=E7=9A=84=E9=85=8D=E7=BD=AE=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/js/editor-options.min.js | 1 + src/js/editor-options.js | 140 ++++++++++++++++++++++++++++++++ theme.yaml | 2 + 3 files changed, 143 insertions(+) create mode 100644 source/js/editor-options.min.js create mode 100644 src/js/editor-options.js diff --git a/source/js/editor-options.min.js b/source/js/editor-options.min.js new file mode 100644 index 0000000..6970a65 --- /dev/null +++ b/source/js/editor-options.min.js @@ -0,0 +1 @@ +!function(){const m=[{value:"$副标题",html:"mew-subtitle | 副标题"},{value:'',html:"mew-music | 网易云单曲"},{value:'',html:"mew-music | 网易云歌单"},{value:'',html:"mew-music | 自定义单曲"},{value:'',html:"mew-bilibili | bilibili视频"},{value:'\n\n$第一页内容\n\n\n$第二页内容\n\n',html:"mew-tabs | 标签页"},{value:'$文件资源描述说明',html:"mew-cloud | 网盘链接"},{value:'',html:"mew-progress | 进度条"},{value:'\n$面板内容\n',html:"mew-panel | 面板"},{value:'$消息内容',html:"mew-message | 消息"},{value:">",html:"mew-hr | 信封分割线"},{value:'\n $时间标题\n $时间子项1具体内容\n $时间子项2具体内容\n',html:"mew-timeline | 时间线"},{value:'打开博客 ',html:"mew-btn | 按钮"},{value:'$引言内容',html:"mew-quote | 引言"},{value:'$网页摘要说明',html:"mew-link | 外部链接"},{value:'',html:"mew-link | 博客文章/页面链接"},{value:'',html:"mew-video | 视频播放器"},{value:'\n $图1描述\n $图2描述\n',html:"mew-photos | 画廊"},{value:"\n$被隔离的内容\n",html:"mew-raw | 样式隔离"},{value:"\n$评论后可见的内容\n",html:"mew-hide | 评论后可见"}];window.handleEditorOptions=e=>(new Set(m.map(e=>e.html).map(e=>e.substring(0,e.indexOf(" ")))).forEach(e=>{console.log(customElements.get(e)),customElements.get(e)||customElements.define(e,class extends HTMLElement{constructor(){super(),this.hasAttribute("draw")||(this.innerText=this.outerHTML,this.style="display: block;background: #eee;padding: 9px;border-radius: 5px;color: #999;font-family: monospace;",this.setAttribute("draw",!0))}})}),{hint:{extend:[{key:"m.filter(e=>-1$副标题', + html: 'mew-subtitle | 副标题' + }, + { + value: '', + html: 'mew-music | 网易云单曲' + }, + { + value: '', + html: 'mew-music | 网易云歌单' + }, + { + value: '', + html: 'mew-music | 自定义单曲' + }, + { + value: '', + html: 'mew-bilibili | bilibili视频' + }, + { + value: '\n' + + '\n' + + '$第一页内容\n' + + '\n' + + '\n' + + '$第二页内容\n' + + '\n' + + '', + html: 'mew-tabs | 标签页' + }, + { + value: '$文件资源描述说明', + html: 'mew-cloud | 网盘链接' + }, + { + value: '', + html: 'mew-progress | 进度条' + }, + { + value: '\n' + + '$面板内容\n' + + '', + html: 'mew-panel | 面板' + }, + { + value: '$消息内容', + html: 'mew-message | 消息' + }, + { + value: '>', + html: 'mew-hr | 信封分割线' + }, + { + value: '\n' + + ' $时间标题\n' + + ' $时间子项1具体内容\n' + + ' $时间子项2具体内容\n' + + '', + html: 'mew-timeline | 时间线' + }, + { + value: '打开博客 ', + html: 'mew-btn | 按钮' + }, + { + value: '$引言内容', + html: 'mew-quote | 引言' + }, + { + value: '$网页摘要说明', + html: 'mew-link | 外部链接' + }, + { + value: '', + html: 'mew-link | 博客文章/页面链接' + }, + { + value: '', + html: 'mew-video | 视频播放器' + }, + { + value: '\n' + + ' $图1描述\n' + + ' $图2描述\n' + + '', + html: 'mew-photos | 画廊' + }, + { + value: '\n' + + '$被隔离的内容\n' + + '', + html: 'mew-raw | 样式隔离' + }, + { + value: '\n' + + '$评论后可见的内容\n' + + '', + html: 'mew-hide | 评论后可见' + } + ] + window.handleEditorOptions = (editorComponent) => { + handleCustomElement() + return { + hint: { + extend: [ + { + key: ' { + return customElement.filter(item => item.value.indexOf(key.toLocaleLowerCase()) > -1) + } + } + ] + } + } + } + + function handleCustomElement() { + let customs = new Set(customElement + .map(item => item.html) + .map(html => html.substring(0, html.indexOf(' ')))) + customs.forEach(item => { + if (customElements.get(item)) { + return + } + customElements.define(item, + class extends HTMLElement { + constructor() { + super() + if (this.hasAttribute('draw')) return + this.innerText = this.outerHTML + this.style = 'display: block;background: #eee;padding: 9px;border-radius: 5px;color: #999;font-family: monospace;' + this.setAttribute('draw', true) + } + }) + }) + } +})() \ No newline at end of file diff --git a/theme.yaml b/theme.yaml index b6b0b70..9964251 100644 --- a/theme.yaml +++ b/theme.yaml @@ -19,6 +19,8 @@ repo: https://github.com/nineya/halo-theme-dream version: 3.2.0 # 最低支持的 Halo-Plus 版本 require: 1.1.0 +# 编辑器配置参数 +editorOptions: http://127.0.0.1:8090/themes/dream/source/js/editor-options.min.js?mew=3.2.0 # 文章页 meta 变量 postMetaField: - enable_copyright