Skip to content
This repository was archived by the owner on Sep 17, 2023. It is now read-only.

Commit 8dd0f1a

Browse files
committed
✨feat(#6): 排除当前块的渲染
1 parent f86bcee commit 8dd0f1a

File tree

6 files changed

+46
-32
lines changed

6 files changed

+46
-32
lines changed

.github/workflows/build.yml

+4-13
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,14 @@ jobs:
3434
- name: cd build
3535
run: cd build && ls
3636

37-
- name: Deploy to GitHub Pages
38-
if: success()
39-
uses: crazy-max/ghaction-github-pages@v2
40-
with:
41-
target_branch: app-build
42-
build_dir: build
43-
env:
44-
GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }}
45-
4637
- name: chmod app
4738
run: chmod 777 ./build/md2website-linux-amd64
48-
- name: test 2
49-
run: ls
39+
5040
- name: build doc
5141
run: ./build/md2website-linux-amd64 "./test-doc" "./outHTML" "./src/views/" ""
52-
- name: test 3
53-
run: ls
42+
43+
- name: zip views
44+
run: zip -q -r ./build/views.zip ./src/views/
5445

5546
- name: Deploy to GitHub Pages
5647
if: success()

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ mac_md2website
2323
__debug_bin
2424

2525

26-
outHTML
26+
outHTML
27+
28+
docHTML

.vscode/launch.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111
"mode": "auto",
1212
"program": "${workspaceFolder}/src/",
1313
"env": {},
14+
"args": [
15+
"D:\\code\\doc\\doc",
16+
"../docHTML/",
17+
"./views/",
18+
"C:/Users/llej/AppData/Local/Temp/siyuan/siyuan.db",
19+
],
1420
// "args": [
15-
// "D:\\code\\doc\\doc",
21+
// "../test-doc/",
1622
// "../outHTML/",
1723
// "./views/",
1824
// "C:/Users/llej/AppData/Local/Temp/siyuan/siyuan.db",
19-
// ],
20-
"args": [
21-
"../test-doc/",
22-
"../outHTML/",
23-
"./views/",
24-
"C:/Users/llej/AppData/Local/Temp/siyuan/siyuan.db",
25-
]
25+
// ]
2626
}
2727
]
2828
}

src/fileEntity.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func FileToFileEntity(path string, info os.FileInfo) FileEntity {
4141
virtualPath = FilePathToWebPath(relativePath)
4242
mdByte, err := ioutil.ReadFile(path)
4343
if err != nil {
44-
util.Log("读取文件失败", err)
44+
util.Warn("读取文件失败", err)
4545
}
4646
mdStr = string(mdByte)
4747
mdStructInfo = GetMdStructInfo("", mdStr)
@@ -88,4 +88,3 @@ func FindFileEntityFromID(id string) (FileEntity, MdStructInfo, error) {
8888
}
8989
return fileEntity, mdInfo, nil
9090
}
91-

src/luteEngine.go

+29-6
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,13 @@ func init() {
135135
sql := n.TokensStr()
136136
ids := db.SQLToID(sql)
137137

138+
curID := getNodeRelativeBlockID(n)
139+
138140
for _, id := range ids {
139-
// if id == baseEntity. {
140-
// continue
141-
// }
141+
if id == curID {
142+
// 派除当前块,查询出自身并不方便阅读
143+
continue
144+
}
142145

143146
fileEntity, mdInfo, err := FindFileEntityFromID(id)
144147
if err != nil {
@@ -199,9 +202,10 @@ func GetMdStructInfo(name string, md string) []MdStructInfo {
199202
}
200203
content := renderBlockMarkdown(n)
201204
if strings.Contains(n.Text(), "岁,一事无成,未来还有希望吗?") {
202-
var id = n.IALAttr("id")
203-
util.Log(id)
204-
util.Log(22)
205+
// 这里有一个 bug 待 lute 修复
206+
// var id = n.IALAttr("id")
207+
// util.Log(id)
208+
// util.Log(22)
205209
}
206210
infoList = append(infoList, MdStructInfo{
207211
blockID: n.IALAttr("id"),
@@ -307,3 +311,22 @@ func headingChildren(heading *ast.Node) (ret []*ast.Node) {
307311
ret = append(ret, blocks...)
308312
return
309313
}
314+
315+
// 获取和 node 最相关的 block ID,从node 一直往他的父级找
316+
func getNodeRelativeBlockID(node *ast.Node) string {
317+
curID := node.IALAttr("id")
318+
cursor := node
319+
for true {
320+
if curID != "" {
321+
break
322+
} else {
323+
if cursor.Parent != nil {
324+
cursor = cursor.Parent
325+
curID = cursor.IALAttr("id")
326+
} else {
327+
break
328+
}
329+
}
330+
}
331+
return curID
332+
}

src/main.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import (
1313
)
1414

1515
func main() {
16-
17-
1816
util.RunningLog("0", "=== 🛬 开始转换 🛫 ===")
1917
// 流程 1 用户输入 {源目录 输出目录}
2018
util.RunningLog("1", "用户输入")
@@ -23,6 +21,7 @@ func main() {
2321
util.RunningLog("1.1", "sourceDir:"+sourceDir)
2422
util.RunningLog("1.2", "outDir:"+outDir)
2523
util.RunningLog("1.3", "viewsDir:"+TemplateDir)
24+
util.RunningLog("1.4", "dbPath:"+SqlitePath)
2625

2726
// 流程 2 copy 源目录中资源文件至输出目录
2827
util.RunningLog("2", "copy 资源到 outDir")

0 commit comments

Comments
 (0)