siyuan/kernel/model/template.go

344 lines
10 KiB
Go
Raw Normal View History

// SiYuan - Refactor your thinking
// Copyright (c) 2020-present, b3log.org
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package model
import (
"bytes"
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"
"sort"
"strings"
"text/template"
"time"
"github.com/88250/gulu"
"github.com/88250/lute/ast"
"github.com/88250/lute/parse"
"github.com/88250/lute/render"
sprig "github.com/Masterminds/sprig/v3"
"github.com/araddon/dateparse"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/search"
"github.com/siyuan-note/siyuan/kernel/sql"
"github.com/siyuan-note/siyuan/kernel/treenode"
"github.com/siyuan-note/siyuan/kernel/util"
)
func RenderGoTemplate(templateContent string) (ret string, err error) {
tpl, err := template.New("").Funcs(sprig.TxtFuncMap()).Parse(templateContent)
if nil != err {
return "", errors.New(fmt.Sprintf(Conf.Language(44), err.Error()))
}
buf := &bytes.Buffer{}
buf.Grow(4096)
err = tpl.Execute(buf, nil)
if nil != err {
return "", errors.New(fmt.Sprintf(Conf.Language(44), err.Error()))
}
ret = buf.String()
return
}
func RemoveTemplate(p string) (err error) {
err = filelock.Remove(p)
if nil != err {
logging.LogErrorf("remove template failed: %s", err)
}
return
}
func SearchTemplate(keyword string) (ret []*Block) {
ret = []*Block{}
templates := filepath.Join(util.DataDir, "templates")
:art: Widgets search supports symlink subdirectory * :art: bazaar resource directories support symlink * :art: bazaar resource directories support symlink * Squashed commit of the following: commit a335101d49382de3db8981f6a2476435580c4bd6 Author: Liang Ding <d@b3log.org> Date: Tue May 16 12:53:33 2023 +0800 :bookmark: Release v2.8.8 commit 6a6dec05f3b74e91254faa526ca71ed782fb2495 Author: Liang Ding <d@b3log.org> Date: Tue May 16 11:30:33 2023 +0800 :memo: Update changelogs commit a819656c0aa033234a61487a942fab534906778d Author: Liang Ding <d@b3log.org> Date: Tue May 16 11:15:53 2023 +0800 :memo: Update changelogs commit 56a2c368d96de1e845ad3e287e566c4fc76a972b Author: Liang Ding <d@b3log.org> Date: Tue May 16 11:11:54 2023 +0800 :bug: Remove inconsistent scroll IAL commit 8b6abec8e90b1518220e6178d51fab8ec6dc41e5 Author: Liang Ding <d@b3log.org> Date: Tue May 16 10:39:48 2023 +0800 :art: Bazaar resource directories support symlink https://github.com/siyuan-note/siyuan/pull/8263 commit 945508682061a0db7b4f7be485ec135a4d88dc1b Author: Liang Ding <d@b3log.org> Date: Tue May 16 10:35:46 2023 +0800 :memo: Update changelogs commit fdbfe6b8487cf5848332f3219f2b897d615ff1d1 Author: 颖逸 <49649786+Zuoqiu-Yingyi@users.noreply.github.com> Date: Tue May 16 10:34:38 2023 +0800 Bazaar resource directories support symlink (#8263) * :art: bazaar resource directories support symlink * :art: bazaar resource directories support symlink commit 85496345ef7b52e753ec247e5ced633232a8f66c Author: Vanessa <lly219@gmail.com> Date: Tue May 16 10:31:01 2023 +0800 :sparkles: enable plugin commit f3d1acd166c1747d8522b276910a89da56723335 Author: Liang Ding <d@b3log.org> Date: Tue May 16 09:39:01 2023 +0800 :memo: Update changelogs commit bf4b88a00770fd130e0b174d27f7ce3b06836e75 Author: Liang Ding <d@b3log.org> Date: Tue May 16 09:38:50 2023 +0800 :art: Plugin hot load commit 516276db49388e7c1bf94ffa3de12b71431e003d Author: Liang Ding <d@b3log.org> Date: Tue May 16 09:09:31 2023 +0800 :art: Data sync connectivity check supports redirection Fix https://github.com/siyuan-note/siyuan/issues/8264 commit d24f5ae3cfe9e9ae7a1acfec0043882ce21dcaf3 Author: Vanessa <lly219@gmail.com> Date: Tue May 16 00:05:18 2023 +0800 :rotating_light: commit 1ac623ebb1a272ffdc63a8d02f9f6916669b4005 Author: Vanessa <lly219@gmail.com> Date: Tue May 16 00:04:25 2023 +0800 :art: fix https://github.com/siyuan-note/siyuan/issues/8258 commit fdf9f0d9e4af6dbc2aa03ae54d96a421a1648a28 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 22:33:36 2023 +0800 :art: https://github.com/siyuan-note/siyuan/issues/5066 removeData commit 7c7f3db0b8f1fdfddea1e0dd5d1a9d867cb95199 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 22:26:11 2023 +0800 :bug: fix https://github.com/siyuan-note/siyuan/issues/8259 commit ba4e5e8eede49d3e349ac89390a8349147e3fec2 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 19:59:13 2023 +0800 :lipstick: fix https://github.com/siyuan-note/siyuan/issues/8260 commit 4f099bd99086bb815780f124e2b594243039e1cb Merge: b892fadd 856c7e09 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 19:35:33 2023 +0800 Merge remote-tracking branch 'origin/dev' into dev commit b892fadd19cfce2ed0ea957eda8a77f134a18c15 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 19:35:19 2023 +0800 :lipstick: commit 856c7e0973ce153b57b4a586d13195ff1c8e47c4 Author: Liang Ding <d@b3log.org> Date: Mon May 15 18:48:33 2023 +0800 :memo: Improve initialization data sync interaction https://github.com/siyuan-note/siyuan/issues/8220 commit ab6cb335e495f4a97b7514108fabd3c9475d7ee7 Author: Liang Ding <d@b3log.org> Date: Mon May 15 18:41:51 2023 +0800 :memo: Improve initialization data sync interaction https://github.com/siyuan-note/siyuan/issues/8220 commit a759936208de16515885d62d7b677262f1ab9357 Author: Liang Ding <d@b3log.org> Date: Mon May 15 16:02:58 2023 +0800 :memo: Improve initialization data sync interaction https://github.com/siyuan-note/siyuan/issues/8220 commit 2513cbc31de29bf936408952dbdb88ec6c2bd5a1 Author: Liang Ding <d@b3log.org> Date: Mon May 15 15:53:46 2023 +0800 :memo: Improve initialization data sync interaction https://github.com/siyuan-note/siyuan/issues/8220 commit 9a03f1e73667092241b88d29e43f2e54fa47b68a Author: Liang Ding <d@b3log.org> Date: Mon May 15 15:52:00 2023 +0800 :memo: Update changelogs commit 4cb952361eafe82f0b7330c0cf0292ce1b192d55 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 15:51:31 2023 +0800 :art: https://github.com/siyuan-note/siyuan/issues/8220 commit 7d58ab0607963c06b17d3404e03a319c39698480 Merge: 6ca68174 0a102851 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 15:43:33 2023 +0800 Merge remote-tracking branch 'origin/dev' into dev commit 6ca6817465ba739fbc958cc4dbe8314d01fefd4b Author: Vanessa <lly219@gmail.com> Date: Mon May 15 15:43:16 2023 +0800 :art: https://github.com/siyuan-note/siyuan/issues/8220 commit 0a10285167e45fb5a1e7d849ff1dcf1e5de230d0 Author: Liang Ding <d@b3log.org> Date: Mon May 15 14:56:12 2023 +0800 :art: Escape the notification message https://github.com/siyuan-note/siyuan/issues/7811 commit 7dbfa43de471b8df263f919bcc96239da45872e2 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 13:59:50 2023 +0800 :art: https://github.com/siyuan-note/siyuan/issues/8220 commit 15141dde1fc09048656262661649cbeb062dc238 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 13:54:30 2023 +0800 :art: https://github.com/siyuan-note/siyuan/issues/8220 commit dc1941da3c74039d9a4b25e3c4e7b8b8fb4656de Author: Vanessa <lly219@gmail.com> Date: Mon May 15 12:11:45 2023 +0800 :art: catch plugin load commit e7288185beaa6edb8c8e3fe457829f9a0bbc5557 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 12:04:22 2023 +0800 :art: catch plugin load commit 6690084caa56b07a90ae6793d283c753c64dfe6a Author: Vanessa <lly219@gmail.com> Date: Mon May 15 11:46:51 2023 +0800 :art: fix https://github.com/siyuan-note/siyuan/issues/8256 commit 53a95ffbf708909ad683dde2894437330339a484 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 00:27:27 2023 +0800 :lipstick: account commit 4c7fe248e45e112e7a52272948cf3b256a3069fd Merge: 3674e834 2cf8a819 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 00:11:08 2023 +0800 Merge remote-tracking branch 'origin/dev' into dev commit 3674e834284a08551f43071a5ba4df376a2f1471 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 00:10:46 2023 +0800 :lipstick: account commit 2cf8a8191a33f4ad396fe9d28ae0f09aa78a977a Author: Liang Ding <d@b3log.org> Date: Sun May 14 23:21:32 2023 +0800 :art: Improve images render in the marketplace package https://github.com/siyuan-note/bazaar/issues/1119 commit 7572db4012843b3befa2b04477ac92fc05f837e0 Author: Vanessa <lly219@gmail.com> Date: Sun May 14 12:10:47 2023 +0800 :art: fix https://github.com/siyuan-note/siyuan/issues/8216 commit 18071638cfffab481ab41f402aaf03bb9d9c9a4d Author: Vanessa <lly219@gmail.com> Date: Sun May 14 12:09:52 2023 +0800 :art: fix https://github.com/siyuan-note/siyuan/issues/8216 commit 300a60aa4521900ba8f0808782614a8fe39d9437 Merge: 0b001595 a6ecb981 Author: Vanessa <lly219@gmail.com> Date: Sun May 14 11:50:55 2023 +0800 Merge remote-tracking branch 'origin/dev' into dev commit 0b001595115b942af58c23bd33836fa36e63c37d Author: Vanessa <lly219@gmail.com> Date: Sun May 14 11:50:41 2023 +0800 :bug: open new window commit a6ecb981b2cd4742c68118bca7b628a5b2400a64 Author: Liang Ding <d@b3log.org> Date: Sun May 14 11:43:54 2023 +0800 :art: Sponsorship through the Open Collective is no longer supported commit 6c3c8d44ade083ed02279638a3ef26311bcf6d5d Author: Liang Ding <d@b3log.org> Date: Sun May 14 10:44:39 2023 +0800 :art: When multiple windows exist, each window should be isolated using the `Optimize Typesetting` https://github.com/siyuan-note/siyuan/issues/8216 commit 3edd8230d33e351ee075a9ff12065546b8827d2d Author: Vanessa <lly219@gmail.com> Date: Sun May 14 10:34:48 2023 +0800 :art: https://github.com/siyuan-note/siyuan/issues/8216 commit f8412a49c42a146d00d979592bb1746cf81c4f60 Author: Vanessa <lly219@gmail.com> Date: Sun May 14 10:27:16 2023 +0800 :bug: fix https://github.com/siyuan-note/siyuan/issues/8187 commit a74ee348f737902e3d1f60766e3af2d11733d2ad Author: Vanessa <lly219@gmail.com> Date: Sun May 14 10:17:43 2023 +0800 :art: fix https://github.com/siyuan-note/siyuan/issues/8242 commit 518ce9491252fed4a40a023b15b3ee06576b2622 Author: Vanessa <lly219@gmail.com> Date: Sun May 14 10:09:11 2023 +0800 :lipstick: bazaar commit e6923bdebce702cab742f9eb902566cb06d824ea Author: Vanessa <lly219@gmail.com> Date: Sun May 14 09:55:50 2023 +0800 :art: https://github.com/siyuan-note/siyuan/issues/8245?utm_source=ld246.com * :art: widgets search support symlink directory * :art: templates directory support symlink * Update template.go
2023-05-17 15:27:32 +08:00
if !util.IsPathRegularDirOrSymlinkDir(templates) {
return
}
groups, err := os.ReadDir(templates)
if nil != err {
logging.LogErrorf("read templates failed: %s", err)
return
}
sort.Slice(ret, func(i, j int) bool {
return util.PinYinCompare(filepath.Base(groups[i].Name()), filepath.Base(groups[j].Name()))
})
k := strings.ToLower(keyword)
for _, group := range groups {
if strings.HasPrefix(group.Name(), ".") {
continue
}
if group.IsDir() {
var templateBlocks []*Block
templateDir := filepath.Join(templates, group.Name())
:art: Widgets search supports symlink subdirectory * :art: bazaar resource directories support symlink * :art: bazaar resource directories support symlink * Squashed commit of the following: commit a335101d49382de3db8981f6a2476435580c4bd6 Author: Liang Ding <d@b3log.org> Date: Tue May 16 12:53:33 2023 +0800 :bookmark: Release v2.8.8 commit 6a6dec05f3b74e91254faa526ca71ed782fb2495 Author: Liang Ding <d@b3log.org> Date: Tue May 16 11:30:33 2023 +0800 :memo: Update changelogs commit a819656c0aa033234a61487a942fab534906778d Author: Liang Ding <d@b3log.org> Date: Tue May 16 11:15:53 2023 +0800 :memo: Update changelogs commit 56a2c368d96de1e845ad3e287e566c4fc76a972b Author: Liang Ding <d@b3log.org> Date: Tue May 16 11:11:54 2023 +0800 :bug: Remove inconsistent scroll IAL commit 8b6abec8e90b1518220e6178d51fab8ec6dc41e5 Author: Liang Ding <d@b3log.org> Date: Tue May 16 10:39:48 2023 +0800 :art: Bazaar resource directories support symlink https://github.com/siyuan-note/siyuan/pull/8263 commit 945508682061a0db7b4f7be485ec135a4d88dc1b Author: Liang Ding <d@b3log.org> Date: Tue May 16 10:35:46 2023 +0800 :memo: Update changelogs commit fdbfe6b8487cf5848332f3219f2b897d615ff1d1 Author: 颖逸 <49649786+Zuoqiu-Yingyi@users.noreply.github.com> Date: Tue May 16 10:34:38 2023 +0800 Bazaar resource directories support symlink (#8263) * :art: bazaar resource directories support symlink * :art: bazaar resource directories support symlink commit 85496345ef7b52e753ec247e5ced633232a8f66c Author: Vanessa <lly219@gmail.com> Date: Tue May 16 10:31:01 2023 +0800 :sparkles: enable plugin commit f3d1acd166c1747d8522b276910a89da56723335 Author: Liang Ding <d@b3log.org> Date: Tue May 16 09:39:01 2023 +0800 :memo: Update changelogs commit bf4b88a00770fd130e0b174d27f7ce3b06836e75 Author: Liang Ding <d@b3log.org> Date: Tue May 16 09:38:50 2023 +0800 :art: Plugin hot load commit 516276db49388e7c1bf94ffa3de12b71431e003d Author: Liang Ding <d@b3log.org> Date: Tue May 16 09:09:31 2023 +0800 :art: Data sync connectivity check supports redirection Fix https://github.com/siyuan-note/siyuan/issues/8264 commit d24f5ae3cfe9e9ae7a1acfec0043882ce21dcaf3 Author: Vanessa <lly219@gmail.com> Date: Tue May 16 00:05:18 2023 +0800 :rotating_light: commit 1ac623ebb1a272ffdc63a8d02f9f6916669b4005 Author: Vanessa <lly219@gmail.com> Date: Tue May 16 00:04:25 2023 +0800 :art: fix https://github.com/siyuan-note/siyuan/issues/8258 commit fdf9f0d9e4af6dbc2aa03ae54d96a421a1648a28 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 22:33:36 2023 +0800 :art: https://github.com/siyuan-note/siyuan/issues/5066 removeData commit 7c7f3db0b8f1fdfddea1e0dd5d1a9d867cb95199 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 22:26:11 2023 +0800 :bug: fix https://github.com/siyuan-note/siyuan/issues/8259 commit ba4e5e8eede49d3e349ac89390a8349147e3fec2 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 19:59:13 2023 +0800 :lipstick: fix https://github.com/siyuan-note/siyuan/issues/8260 commit 4f099bd99086bb815780f124e2b594243039e1cb Merge: b892fadd 856c7e09 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 19:35:33 2023 +0800 Merge remote-tracking branch 'origin/dev' into dev commit b892fadd19cfce2ed0ea957eda8a77f134a18c15 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 19:35:19 2023 +0800 :lipstick: commit 856c7e0973ce153b57b4a586d13195ff1c8e47c4 Author: Liang Ding <d@b3log.org> Date: Mon May 15 18:48:33 2023 +0800 :memo: Improve initialization data sync interaction https://github.com/siyuan-note/siyuan/issues/8220 commit ab6cb335e495f4a97b7514108fabd3c9475d7ee7 Author: Liang Ding <d@b3log.org> Date: Mon May 15 18:41:51 2023 +0800 :memo: Improve initialization data sync interaction https://github.com/siyuan-note/siyuan/issues/8220 commit a759936208de16515885d62d7b677262f1ab9357 Author: Liang Ding <d@b3log.org> Date: Mon May 15 16:02:58 2023 +0800 :memo: Improve initialization data sync interaction https://github.com/siyuan-note/siyuan/issues/8220 commit 2513cbc31de29bf936408952dbdb88ec6c2bd5a1 Author: Liang Ding <d@b3log.org> Date: Mon May 15 15:53:46 2023 +0800 :memo: Improve initialization data sync interaction https://github.com/siyuan-note/siyuan/issues/8220 commit 9a03f1e73667092241b88d29e43f2e54fa47b68a Author: Liang Ding <d@b3log.org> Date: Mon May 15 15:52:00 2023 +0800 :memo: Update changelogs commit 4cb952361eafe82f0b7330c0cf0292ce1b192d55 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 15:51:31 2023 +0800 :art: https://github.com/siyuan-note/siyuan/issues/8220 commit 7d58ab0607963c06b17d3404e03a319c39698480 Merge: 6ca68174 0a102851 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 15:43:33 2023 +0800 Merge remote-tracking branch 'origin/dev' into dev commit 6ca6817465ba739fbc958cc4dbe8314d01fefd4b Author: Vanessa <lly219@gmail.com> Date: Mon May 15 15:43:16 2023 +0800 :art: https://github.com/siyuan-note/siyuan/issues/8220 commit 0a10285167e45fb5a1e7d849ff1dcf1e5de230d0 Author: Liang Ding <d@b3log.org> Date: Mon May 15 14:56:12 2023 +0800 :art: Escape the notification message https://github.com/siyuan-note/siyuan/issues/7811 commit 7dbfa43de471b8df263f919bcc96239da45872e2 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 13:59:50 2023 +0800 :art: https://github.com/siyuan-note/siyuan/issues/8220 commit 15141dde1fc09048656262661649cbeb062dc238 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 13:54:30 2023 +0800 :art: https://github.com/siyuan-note/siyuan/issues/8220 commit dc1941da3c74039d9a4b25e3c4e7b8b8fb4656de Author: Vanessa <lly219@gmail.com> Date: Mon May 15 12:11:45 2023 +0800 :art: catch plugin load commit e7288185beaa6edb8c8e3fe457829f9a0bbc5557 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 12:04:22 2023 +0800 :art: catch plugin load commit 6690084caa56b07a90ae6793d283c753c64dfe6a Author: Vanessa <lly219@gmail.com> Date: Mon May 15 11:46:51 2023 +0800 :art: fix https://github.com/siyuan-note/siyuan/issues/8256 commit 53a95ffbf708909ad683dde2894437330339a484 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 00:27:27 2023 +0800 :lipstick: account commit 4c7fe248e45e112e7a52272948cf3b256a3069fd Merge: 3674e834 2cf8a819 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 00:11:08 2023 +0800 Merge remote-tracking branch 'origin/dev' into dev commit 3674e834284a08551f43071a5ba4df376a2f1471 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 00:10:46 2023 +0800 :lipstick: account commit 2cf8a8191a33f4ad396fe9d28ae0f09aa78a977a Author: Liang Ding <d@b3log.org> Date: Sun May 14 23:21:32 2023 +0800 :art: Improve images render in the marketplace package https://github.com/siyuan-note/bazaar/issues/1119 commit 7572db4012843b3befa2b04477ac92fc05f837e0 Author: Vanessa <lly219@gmail.com> Date: Sun May 14 12:10:47 2023 +0800 :art: fix https://github.com/siyuan-note/siyuan/issues/8216 commit 18071638cfffab481ab41f402aaf03bb9d9c9a4d Author: Vanessa <lly219@gmail.com> Date: Sun May 14 12:09:52 2023 +0800 :art: fix https://github.com/siyuan-note/siyuan/issues/8216 commit 300a60aa4521900ba8f0808782614a8fe39d9437 Merge: 0b001595 a6ecb981 Author: Vanessa <lly219@gmail.com> Date: Sun May 14 11:50:55 2023 +0800 Merge remote-tracking branch 'origin/dev' into dev commit 0b001595115b942af58c23bd33836fa36e63c37d Author: Vanessa <lly219@gmail.com> Date: Sun May 14 11:50:41 2023 +0800 :bug: open new window commit a6ecb981b2cd4742c68118bca7b628a5b2400a64 Author: Liang Ding <d@b3log.org> Date: Sun May 14 11:43:54 2023 +0800 :art: Sponsorship through the Open Collective is no longer supported commit 6c3c8d44ade083ed02279638a3ef26311bcf6d5d Author: Liang Ding <d@b3log.org> Date: Sun May 14 10:44:39 2023 +0800 :art: When multiple windows exist, each window should be isolated using the `Optimize Typesetting` https://github.com/siyuan-note/siyuan/issues/8216 commit 3edd8230d33e351ee075a9ff12065546b8827d2d Author: Vanessa <lly219@gmail.com> Date: Sun May 14 10:34:48 2023 +0800 :art: https://github.com/siyuan-note/siyuan/issues/8216 commit f8412a49c42a146d00d979592bb1746cf81c4f60 Author: Vanessa <lly219@gmail.com> Date: Sun May 14 10:27:16 2023 +0800 :bug: fix https://github.com/siyuan-note/siyuan/issues/8187 commit a74ee348f737902e3d1f60766e3af2d11733d2ad Author: Vanessa <lly219@gmail.com> Date: Sun May 14 10:17:43 2023 +0800 :art: fix https://github.com/siyuan-note/siyuan/issues/8242 commit 518ce9491252fed4a40a023b15b3ee06576b2622 Author: Vanessa <lly219@gmail.com> Date: Sun May 14 10:09:11 2023 +0800 :lipstick: bazaar commit e6923bdebce702cab742f9eb902566cb06d824ea Author: Vanessa <lly219@gmail.com> Date: Sun May 14 09:55:50 2023 +0800 :art: https://github.com/siyuan-note/siyuan/issues/8245?utm_source=ld246.com * :art: widgets search support symlink directory * :art: templates directory support symlink * Update template.go
2023-05-17 15:27:32 +08:00
// filepath.Walk 与 filepath.WalkDir 均不支持跟踪符号链接
filepath.WalkDir(templateDir, func(path string, entry fs.DirEntry, err error) error {
name := strings.ToLower(entry.Name())
if strings.HasPrefix(name, ".") {
:art: Widgets search supports symlink subdirectory * :art: bazaar resource directories support symlink * :art: bazaar resource directories support symlink * Squashed commit of the following: commit a335101d49382de3db8981f6a2476435580c4bd6 Author: Liang Ding <d@b3log.org> Date: Tue May 16 12:53:33 2023 +0800 :bookmark: Release v2.8.8 commit 6a6dec05f3b74e91254faa526ca71ed782fb2495 Author: Liang Ding <d@b3log.org> Date: Tue May 16 11:30:33 2023 +0800 :memo: Update changelogs commit a819656c0aa033234a61487a942fab534906778d Author: Liang Ding <d@b3log.org> Date: Tue May 16 11:15:53 2023 +0800 :memo: Update changelogs commit 56a2c368d96de1e845ad3e287e566c4fc76a972b Author: Liang Ding <d@b3log.org> Date: Tue May 16 11:11:54 2023 +0800 :bug: Remove inconsistent scroll IAL commit 8b6abec8e90b1518220e6178d51fab8ec6dc41e5 Author: Liang Ding <d@b3log.org> Date: Tue May 16 10:39:48 2023 +0800 :art: Bazaar resource directories support symlink https://github.com/siyuan-note/siyuan/pull/8263 commit 945508682061a0db7b4f7be485ec135a4d88dc1b Author: Liang Ding <d@b3log.org> Date: Tue May 16 10:35:46 2023 +0800 :memo: Update changelogs commit fdbfe6b8487cf5848332f3219f2b897d615ff1d1 Author: 颖逸 <49649786+Zuoqiu-Yingyi@users.noreply.github.com> Date: Tue May 16 10:34:38 2023 +0800 Bazaar resource directories support symlink (#8263) * :art: bazaar resource directories support symlink * :art: bazaar resource directories support symlink commit 85496345ef7b52e753ec247e5ced633232a8f66c Author: Vanessa <lly219@gmail.com> Date: Tue May 16 10:31:01 2023 +0800 :sparkles: enable plugin commit f3d1acd166c1747d8522b276910a89da56723335 Author: Liang Ding <d@b3log.org> Date: Tue May 16 09:39:01 2023 +0800 :memo: Update changelogs commit bf4b88a00770fd130e0b174d27f7ce3b06836e75 Author: Liang Ding <d@b3log.org> Date: Tue May 16 09:38:50 2023 +0800 :art: Plugin hot load commit 516276db49388e7c1bf94ffa3de12b71431e003d Author: Liang Ding <d@b3log.org> Date: Tue May 16 09:09:31 2023 +0800 :art: Data sync connectivity check supports redirection Fix https://github.com/siyuan-note/siyuan/issues/8264 commit d24f5ae3cfe9e9ae7a1acfec0043882ce21dcaf3 Author: Vanessa <lly219@gmail.com> Date: Tue May 16 00:05:18 2023 +0800 :rotating_light: commit 1ac623ebb1a272ffdc63a8d02f9f6916669b4005 Author: Vanessa <lly219@gmail.com> Date: Tue May 16 00:04:25 2023 +0800 :art: fix https://github.com/siyuan-note/siyuan/issues/8258 commit fdf9f0d9e4af6dbc2aa03ae54d96a421a1648a28 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 22:33:36 2023 +0800 :art: https://github.com/siyuan-note/siyuan/issues/5066 removeData commit 7c7f3db0b8f1fdfddea1e0dd5d1a9d867cb95199 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 22:26:11 2023 +0800 :bug: fix https://github.com/siyuan-note/siyuan/issues/8259 commit ba4e5e8eede49d3e349ac89390a8349147e3fec2 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 19:59:13 2023 +0800 :lipstick: fix https://github.com/siyuan-note/siyuan/issues/8260 commit 4f099bd99086bb815780f124e2b594243039e1cb Merge: b892fadd 856c7e09 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 19:35:33 2023 +0800 Merge remote-tracking branch 'origin/dev' into dev commit b892fadd19cfce2ed0ea957eda8a77f134a18c15 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 19:35:19 2023 +0800 :lipstick: commit 856c7e0973ce153b57b4a586d13195ff1c8e47c4 Author: Liang Ding <d@b3log.org> Date: Mon May 15 18:48:33 2023 +0800 :memo: Improve initialization data sync interaction https://github.com/siyuan-note/siyuan/issues/8220 commit ab6cb335e495f4a97b7514108fabd3c9475d7ee7 Author: Liang Ding <d@b3log.org> Date: Mon May 15 18:41:51 2023 +0800 :memo: Improve initialization data sync interaction https://github.com/siyuan-note/siyuan/issues/8220 commit a759936208de16515885d62d7b677262f1ab9357 Author: Liang Ding <d@b3log.org> Date: Mon May 15 16:02:58 2023 +0800 :memo: Improve initialization data sync interaction https://github.com/siyuan-note/siyuan/issues/8220 commit 2513cbc31de29bf936408952dbdb88ec6c2bd5a1 Author: Liang Ding <d@b3log.org> Date: Mon May 15 15:53:46 2023 +0800 :memo: Improve initialization data sync interaction https://github.com/siyuan-note/siyuan/issues/8220 commit 9a03f1e73667092241b88d29e43f2e54fa47b68a Author: Liang Ding <d@b3log.org> Date: Mon May 15 15:52:00 2023 +0800 :memo: Update changelogs commit 4cb952361eafe82f0b7330c0cf0292ce1b192d55 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 15:51:31 2023 +0800 :art: https://github.com/siyuan-note/siyuan/issues/8220 commit 7d58ab0607963c06b17d3404e03a319c39698480 Merge: 6ca68174 0a102851 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 15:43:33 2023 +0800 Merge remote-tracking branch 'origin/dev' into dev commit 6ca6817465ba739fbc958cc4dbe8314d01fefd4b Author: Vanessa <lly219@gmail.com> Date: Mon May 15 15:43:16 2023 +0800 :art: https://github.com/siyuan-note/siyuan/issues/8220 commit 0a10285167e45fb5a1e7d849ff1dcf1e5de230d0 Author: Liang Ding <d@b3log.org> Date: Mon May 15 14:56:12 2023 +0800 :art: Escape the notification message https://github.com/siyuan-note/siyuan/issues/7811 commit 7dbfa43de471b8df263f919bcc96239da45872e2 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 13:59:50 2023 +0800 :art: https://github.com/siyuan-note/siyuan/issues/8220 commit 15141dde1fc09048656262661649cbeb062dc238 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 13:54:30 2023 +0800 :art: https://github.com/siyuan-note/siyuan/issues/8220 commit dc1941da3c74039d9a4b25e3c4e7b8b8fb4656de Author: Vanessa <lly219@gmail.com> Date: Mon May 15 12:11:45 2023 +0800 :art: catch plugin load commit e7288185beaa6edb8c8e3fe457829f9a0bbc5557 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 12:04:22 2023 +0800 :art: catch plugin load commit 6690084caa56b07a90ae6793d283c753c64dfe6a Author: Vanessa <lly219@gmail.com> Date: Mon May 15 11:46:51 2023 +0800 :art: fix https://github.com/siyuan-note/siyuan/issues/8256 commit 53a95ffbf708909ad683dde2894437330339a484 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 00:27:27 2023 +0800 :lipstick: account commit 4c7fe248e45e112e7a52272948cf3b256a3069fd Merge: 3674e834 2cf8a819 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 00:11:08 2023 +0800 Merge remote-tracking branch 'origin/dev' into dev commit 3674e834284a08551f43071a5ba4df376a2f1471 Author: Vanessa <lly219@gmail.com> Date: Mon May 15 00:10:46 2023 +0800 :lipstick: account commit 2cf8a8191a33f4ad396fe9d28ae0f09aa78a977a Author: Liang Ding <d@b3log.org> Date: Sun May 14 23:21:32 2023 +0800 :art: Improve images render in the marketplace package https://github.com/siyuan-note/bazaar/issues/1119 commit 7572db4012843b3befa2b04477ac92fc05f837e0 Author: Vanessa <lly219@gmail.com> Date: Sun May 14 12:10:47 2023 +0800 :art: fix https://github.com/siyuan-note/siyuan/issues/8216 commit 18071638cfffab481ab41f402aaf03bb9d9c9a4d Author: Vanessa <lly219@gmail.com> Date: Sun May 14 12:09:52 2023 +0800 :art: fix https://github.com/siyuan-note/siyuan/issues/8216 commit 300a60aa4521900ba8f0808782614a8fe39d9437 Merge: 0b001595 a6ecb981 Author: Vanessa <lly219@gmail.com> Date: Sun May 14 11:50:55 2023 +0800 Merge remote-tracking branch 'origin/dev' into dev commit 0b001595115b942af58c23bd33836fa36e63c37d Author: Vanessa <lly219@gmail.com> Date: Sun May 14 11:50:41 2023 +0800 :bug: open new window commit a6ecb981b2cd4742c68118bca7b628a5b2400a64 Author: Liang Ding <d@b3log.org> Date: Sun May 14 11:43:54 2023 +0800 :art: Sponsorship through the Open Collective is no longer supported commit 6c3c8d44ade083ed02279638a3ef26311bcf6d5d Author: Liang Ding <d@b3log.org> Date: Sun May 14 10:44:39 2023 +0800 :art: When multiple windows exist, each window should be isolated using the `Optimize Typesetting` https://github.com/siyuan-note/siyuan/issues/8216 commit 3edd8230d33e351ee075a9ff12065546b8827d2d Author: Vanessa <lly219@gmail.com> Date: Sun May 14 10:34:48 2023 +0800 :art: https://github.com/siyuan-note/siyuan/issues/8216 commit f8412a49c42a146d00d979592bb1746cf81c4f60 Author: Vanessa <lly219@gmail.com> Date: Sun May 14 10:27:16 2023 +0800 :bug: fix https://github.com/siyuan-note/siyuan/issues/8187 commit a74ee348f737902e3d1f60766e3af2d11733d2ad Author: Vanessa <lly219@gmail.com> Date: Sun May 14 10:17:43 2023 +0800 :art: fix https://github.com/siyuan-note/siyuan/issues/8242 commit 518ce9491252fed4a40a023b15b3ee06576b2622 Author: Vanessa <lly219@gmail.com> Date: Sun May 14 10:09:11 2023 +0800 :lipstick: bazaar commit e6923bdebce702cab742f9eb902566cb06d824ea Author: Vanessa <lly219@gmail.com> Date: Sun May 14 09:55:50 2023 +0800 :art: https://github.com/siyuan-note/siyuan/issues/8245?utm_source=ld246.com * :art: widgets search support symlink directory * :art: templates directory support symlink * Update template.go
2023-05-17 15:27:32 +08:00
if entry.IsDir() {
return filepath.SkipDir
}
return nil
}
2023-05-07 15:39:27 +08:00
if !strings.HasSuffix(name, ".md") || strings.HasPrefix(name, "readme") || !strings.Contains(name, k) {
return nil
}
content := strings.TrimPrefix(path, templates)
content = strings.TrimSuffix(content, ".md")
content = filepath.ToSlash(content)
content = strings.TrimPrefix(content, "/")
_, content = search.MarkText(content, keyword, 32, Conf.Search.CaseSensitive)
b := &Block{Path: path, Content: content}
templateBlocks = append(templateBlocks, b)
return nil
})
sort.Slice(templateBlocks, func(i, j int) bool {
return util.PinYinCompare(filepath.Base(templateBlocks[i].Path), filepath.Base(templateBlocks[j].Path))
})
ret = append(ret, templateBlocks...)
} else {
name := strings.ToLower(group.Name())
if strings.HasPrefix(name, ".") || !strings.HasSuffix(name, ".md") || "readme.md" == name || !strings.Contains(name, k) {
continue
}
content := group.Name()
content = strings.TrimSuffix(content, ".md")
content = filepath.ToSlash(content)
_, content = search.MarkText(content, keyword, 32, Conf.Search.CaseSensitive)
b := &Block{Path: filepath.Join(templates, group.Name()), Content: content}
ret = append(ret, b)
}
}
return
}
func DocSaveAsTemplate(id, name string, overwrite bool) (code int, err error) {
bt := treenode.GetBlockTree(id)
if nil == bt {
return
}
tree := prepareExportTree(bt)
addBlockIALNodes(tree, true)
luteEngine := NewLute()
formatRenderer := render.NewFormatRenderer(tree, luteEngine.RenderOptions)
md := formatRenderer.Render()
name = util.FilterFileName(name) + ".md"
name = util.TruncateLenFileName(name)
savePath := filepath.Join(util.DataDir, "templates", name)
if gulu.File.IsExist(savePath) {
if !overwrite {
code = 1
return
}
}
err = filelock.WriteFile(savePath, md)
return
}
func RenderTemplate(p, id string) (string, error) {
return renderTemplate(p, id)
}
func renderTemplate(p, id string) (string, error) {
tree, err := loadTreeByBlockID(id)
if nil != err {
return "", err
}
node := treenode.GetNodeInTree(tree, id)
if nil == node {
return "", ErrBlockNotFound
}
block := sql.BuildBlockFromNode(node, tree)
md, err := os.ReadFile(p)
if nil != err {
return "", err
}
dataModel := map[string]string{}
var titleVar string
if nil != block {
titleVar = block.Name
if "d" == block.Type {
titleVar = block.Content
}
dataModel["title"] = titleVar
dataModel["id"] = block.ID
dataModel["name"] = block.Name
dataModel["alias"] = block.Alias
}
funcMap := sprig.TxtFuncMap()
funcMap["queryBlocks"] = func(stmt string, args ...string) (ret []*sql.Block) {
for _, arg := range args {
stmt = strings.Replace(stmt, "?", arg, 1)
}
ret = sql.SelectBlocksRawStmt(stmt, 1, Conf.Search.Limit)
return
}
funcMap["querySpans"] = func(stmt string, args ...string) (ret []*sql.Span) {
for _, arg := range args {
stmt = strings.Replace(stmt, "?", arg, 1)
}
ret = sql.SelectSpansRawStmt(stmt, Conf.Search.Limit)
return
}
funcMap["parseTime"] = func(dateStr string) time.Time {
now := time.Now()
ret, err := dateparse.ParseIn(dateStr, now.Location())
if nil != err {
logging.LogWarnf("parse date [%s] failed [%s], return current time instead", dateStr, err)
return now
}
return ret
}
goTpl := template.New("").Delims(".action{", "}")
tpl, err := goTpl.Funcs(funcMap).Parse(gulu.Str.FromBytes(md))
if nil != err {
return "", errors.New(fmt.Sprintf(Conf.Language(44), err.Error()))
}
buf := &bytes.Buffer{}
buf.Grow(4096)
if err = tpl.Execute(buf, dataModel); nil != err {
return "", errors.New(fmt.Sprintf(Conf.Language(44), err.Error()))
}
md = buf.Bytes()
tree = parseKTree(md)
if nil == tree {
msg := fmt.Sprintf("parse tree [%s] failed", p)
logging.LogErrorf(msg)
return "", errors.New(msg)
}
var nodesNeedAppendChild, unlinks []*ast.Node
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering {
return ast.WalkContinue
}
if "" != n.ID {
// 重新生成 ID
n.ID = ast.NewNodeID()
n.SetIALAttr("id", n.ID)
// Blocks created via template update time earlier than creation time https://github.com/siyuan-note/siyuan/issues/8607
refreshUpdated(n)
}
if (ast.NodeListItem == n.Type && (nil == n.FirstChild ||
(3 == n.ListData.Typ && (nil == n.FirstChild.Next || ast.NodeKramdownBlockIAL == n.FirstChild.Next.Type)))) ||
(ast.NodeBlockquote == n.Type && nil != n.FirstChild && nil != n.FirstChild.Next && ast.NodeKramdownBlockIAL == n.FirstChild.Next.Type) {
nodesNeedAppendChild = append(nodesNeedAppendChild, n)
}
// 块引缺失锚文本情况下自动补全 https://github.com/siyuan-note/siyuan/issues/6087
if n.IsTextMarkType("block-ref") {
if refText := n.Text(); "" == refText {
refText = sql.GetRefText(n.TextMarkBlockRefID)
if "" != refText {
treenode.SetDynamicBlockRefText(n, refText)
} else {
unlinks = append(unlinks, n)
}
}
} else if n.IsTextMarkType("inline-math") {
if n.ParentIs(ast.NodeTableCell) {
// 表格中的公式中带有管道符时使用 HTML 实体替换管道符 Improve the handling of inline-math containing `|` in the table https://github.com/siyuan-note/siyuan/issues/9227
n.TextMarkInlineMathContent = strings.ReplaceAll(n.TextMarkInlineMathContent, "|", "&#124;")
}
}
return ast.WalkContinue
})
for _, n := range nodesNeedAppendChild {
if ast.NodeBlockquote == n.Type {
n.FirstChild.InsertAfter(treenode.NewParagraph())
} else {
n.AppendChild(treenode.NewParagraph())
}
}
for _, n := range unlinks {
n.Unlink()
}
// 折叠标题导出为模板后使用会出现内容重复 https://github.com/siyuan-note/siyuan/issues/4488
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering {
return ast.WalkContinue
}
if "1" == n.IALAttr("heading-fold") { // 为标题折叠下方块添加属性,前端渲染以后会统一做移除处理
n.SetIALAttr("status", "temp")
}
return ast.WalkContinue
})
luteEngine := NewLute()
dom := luteEngine.Tree2BlockDOM(tree, luteEngine.RenderOptions)
return dom, nil
}
func addBlockIALNodes(tree *parse.Tree, removeUpdated bool) {
var blocks []*ast.Node
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering || !n.IsBlock() {
return ast.WalkContinue
}
if ast.NodeBlockQueryEmbed == n.Type {
if script := n.ChildByType(ast.NodeBlockQueryEmbedScript); nil != script {
script.Tokens = bytes.ReplaceAll(script.Tokens, []byte("\n"), []byte(" "))
}
} else if ast.NodeHTMLBlock == n.Type {
n.Tokens = bytes.TrimSpace(n.Tokens)
// 使用 <div> 包裹,否则后续解析时会识别为行级 HTML https://github.com/siyuan-note/siyuan/issues/4244
if !bytes.HasPrefix(n.Tokens, []byte("<div>")) {
n.Tokens = append([]byte("<div>\n"), n.Tokens...)
}
if !bytes.HasSuffix(n.Tokens, []byte("</div>")) {
n.Tokens = append(n.Tokens, []byte("\n</div>")...)
}
}
if removeUpdated {
n.RemoveIALAttr("updated")
}
if 0 < len(n.KramdownIAL) {
blocks = append(blocks, n)
}
return ast.WalkContinue
})
for _, block := range blocks {
block.InsertAfter(&ast.Node{Type: ast.NodeKramdownBlockIAL, Tokens: parse.IAL2Tokens(block.KramdownIAL)})
}
}