Skip to content

Commit 93422c1

Browse files
committed
🎨 Add field disabledInPublish to the code snippet to indicate whether it is disabled in the publish service #15806
Signed-off-by: Daniel <845765@qq.com>
1 parent 2f70ef4 commit 93422c1

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

app/changelogs/v3.3.2/v3.3.2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Below are the detailed changes in this version.
2525
* [Dragging multiple files into the editor will cause them to be opened by the default program](https://github.com/siyuan-note/siyuan/pull/15773)
2626
* [Improve HTML table clipping](https://github.com/siyuan-note/siyuan/issues/15781)
2727
* [Automatically create a new document when clicking on a notebook without documents](https://github.com/siyuan-note/siyuan/issues/15782)
28+
* [Add field `disabledInPublish` to the code snippet to indicate whether it is disabled in the publish service](https://github.com/siyuan-note/siyuan/issues/15806)
2829

2930
### Bugfix
3031

app/changelogs/v3.3.2/v3.3.2_zh_CHT.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* [拖入多個檔案到編輯器不再被預設程式開啟](https://github.com/siyuan-note/siyuan/pull/15773)
2626
* [改進 HTML 表格剪藏](https://github.com/siyuan-note/siyuan/issues/15781)
2727
* [點選無文件的筆記本時自動新建文件](https://github.com/siyuan-note/siyuan/issues/15782)
28+
* [程式碼片段新增欄位 `disabledInPublish`,用於識別發佈服務中是否已停用](https://github.com/siyuan-note/siyuan/issues/15806)
2829

2930
### 修復缺陷
3031

app/changelogs/v3.3.2/v3.3.2_zh_CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* [拖入多个文件到编辑器不再被默认程序打开](https://github.com/siyuan-note/siyuan/pull/15773)
2626
* [改进 HTML 表格剪藏](https://github.com/siyuan-note/siyuan/issues/15781)
2727
* [点击无文档的笔记本时自动新建文档](https://github.com/siyuan-note/siyuan/issues/15782)
28+
* [代码片段新增字段 `disabledInPublish`,用于标识发布服务中是否禁用](https://github.com/siyuan-note/siyuan/issues/15806)
2829

2930
### 修复缺陷
3031

kernel/api/snippet.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,20 @@ func getSnippet(c *gin.Context) {
5555
return
5656
}
5757

58+
isPublish := model.IsReadOnlyRole(model.GetGinContextRole(c))
5859
var snippets []*conf.Snippet
5960
for _, s := range confSnippets {
60-
if ("all" == typ || s.Type == typ) && (2 == enabledArg || s.Enabled == enabled) {
61-
snippets = append(snippets, s)
61+
if isPublish && s.DisabledInPublish {
62+
continue
6263
}
64+
if "all" != typ && s.Type != typ {
65+
continue
66+
}
67+
if 2 != enabledArg && s.Enabled != enabled {
68+
continue
69+
}
70+
71+
snippets = append(snippets, s)
6372
}
6473

6574
if "" != keyword {
@@ -101,6 +110,9 @@ func setSnippet(c *gin.Context) {
101110
Content: m["content"].(string),
102111
Enabled: m["enabled"].(bool),
103112
}
113+
if nil != m["disabledInPublish"] {
114+
snippet.DisabledInPublish = m["disabledInPublish"].(bool)
115+
}
104116
if "" == snippet.ID {
105117
snippet.ID = ast.NewNodeID()
106118
}

kernel/conf/snippet.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ func NewSnpt() *Snpt {
2929
}
3030

3131
type Snippet struct {
32-
ID string `json:"id"`
33-
Name string `json:"name"`
34-
Type string `json:"type"` // js/css
35-
Enabled bool `json:"enabled"`
36-
Content string `json:"content"`
32+
ID string `json:"id"`
33+
Name string `json:"name"`
34+
Type string `json:"type"` // js/css
35+
Enabled bool `json:"enabled"`
36+
DisabledInPublish bool `json:"disabledInPublish"`
37+
Content string `json:"content"`
3738
}

0 commit comments

Comments
 (0)