1.2.5 将文件夹结构改成了父子文档结构,如果希望直接在父文档创建子文档的朋友,现在通过新建块引建立文档已经默认是新建成子文档了,输入【【、((加文字,或者将已有文字通过 alt+【,就可新建子文档。

ps:如果需要新建块引在同级文件下,可以把笔记本设置里的新建块引路径改为../,两个点号代表到上一级文件

目前来说,思源的父子文档比 notion、wolai 更加灵活,不强迫展示子文档,可以在父文档上更自由的书写总结概括或是其他内容,更灵活的利用块引,而不是简单的当作一个建站页面,暴力展示所有子文档。而文件树的架构,本来就能展示子文档,所以不会太影响查看子文档。

但如果有朋友觉得父文档空空如也很不符合习惯,可以看看我下面分享的模板。

在父文档下只展示第一层级的子文档

moc_ref_1_layer.md

  1. .action{.title}
  2. .action{$docid:=.id}
  3. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $docid )}
  4. .action{range $v:=$block}
  5. - ((.action{$v.ID} ".action{$v.Content}"))
  6. .action{end}

解释思路

父文档下的第一层级子文档,与其他更深层级文档的差别,就是其路径是父文档路径 + 自己 id.sy,

运用了 sql 的 like 语法,下划线代表匹配一个位置的字符,于是就暴力用下划线代表思源文件存储格式 “14 位时间码”“ +“-”+“7 位随机数.sy”

(话说不知道 sql 有没有_{14}的语法)

该模板按子文档名字顺序排序,并以无序列表的方式展示

保存方法:可以将代码 copy 到工作空间下/data/templates/ 文件夹下,新建 md 文件。
使用方法:使用斜杠菜单,选项第一个就是模板,搜索对应的名字就好

【模板】父文档列出第一层级子文档和最多六层级的子文档 - 图1

但是我突然想到

notion、wolai 的子文档可不是块引用,而是链接!

如果展示子文档全部都用块引用,岂不是大材小用??有时候会增加特别直白无用的引用关系?

块引用不应该这样使用才对啊!

于是我又稍微改动了下,用思源超链接协议展示子文档,照样可以通过点击直达子文档,只是没有块引的鼠标悬浮功能罢了。

moc_link_1_layer.md

  1. .action{.title}
  2. .action{$docid:=.id}
  3. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $docid )}
  4. .action{range $v:=$block}
  5. - [.action{$v.Content}](siyuan://blocks/.action{$v.ID})
  6. .action{end}

【模板】父文档列出第一层级子文档和最多六层级的子文档 - 图2

用块超链接而不是块引的好处主要有

  • 块引搞的太多,程序负担很重
  • 父子文档的关系往往比较直白,没必要用双向块引
  • 块超链接可以复制到其他软件,点击依然能跳转思源对应的文档

坏处

  • 没有块引悬浮预览
  • 不能像块引一样不填锚文本的话可以自己填充
  • 文档删除后失效不会明显提示

在父文档下只展示两层级的子文档

moc_ref_2_layer.md

  1. .action{$docid:=.id}
  2. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $docid )}
  3. .action{range $v:=$block}
  4. - ((.action{$v.ID} ".action{$v.Content}"))
  5. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  6. .action{range $v:=$block}
  7. - ((.action{$v.ID} ".action{$v.Content}"))
  8. .action{end}
  9. .action{end}

moc_link_2_layer.md

  1. .action{$docid:=.id}
  2. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $docid )}
  3. .action{range $v:=$block}
  4. - [.action{$v.Content}](siyuan://blocks/.action{$v.ID})
  5. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  6. .action{range $v:=$block}
  7. - [.action{$v.Content}](siyuan://blocks/.action{$v.ID})
  8. .action{end}
  9. .action{end}

以此类推……

在父文档下只展示三层级的子文档

moc_ref_3_layer.md

  1. .action{$docid:=.id}
  2. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $docid )}
  3. .action{range $v:=$block}
  4. - ((.action{$v.ID} ".action{$v.Content}"))
  5. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  6. .action{range $v:=$block}
  7. - ((.action{$v.ID} ".action{$v.Content}"))
  8. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  9. .action{range $v:=$block}
  10. - ((.action{$v.ID} ".action{$v.Content}"))
  11. .action{end}
  12. .action{end}
  13. .action{end}

moc_link_3_layer.md

  1. .action{$docid:=.id}
  2. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $docid )}
  3. .action{range $v:=$block}
  4. - [.action{$v.Content}](siyuan://blocks/.action{$v.ID})
  5. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  6. .action{range $v:=$block}
  7. - [.action{$v.Content}](siyuan://blocks/.action{$v.ID})
  8. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  9. .action{range $v:=$block}
  10. - [.action{$v.Content}](siyuan://blocks/.action{$v.ID})
  11. .action{end}
  12. .action{end}
  13. .action{end}

在父文档下只展示四层级的子文档

moc_ref_4_layer.md

  1. .action{$docid:=.id}
  2. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $docid )}
  3. .action{range $v:=$block}
  4. - ((.action{$v.ID} ".action{$v.Content}"))
  5. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  6. .action{range $v:=$block}
  7. - ((.action{$v.ID} ".action{$v.Content}"))
  8. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  9. .action{range $v:=$block}
  10. - ((.action{$v.ID} ".action{$v.Content}"))
  11. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  12. .action{range $v:=$block}
  13. - ((.action{$v.ID} ".action{$v.Content}"))
  14. .action{end}
  15. .action{end}
  16. .action{end}
  17. .action{end}

moc_link_4_layer.md

  1. .action{$docid:=.id}
  2. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $docid )}
  3. .action{range $v:=$block}
  4. - [.action{$v.Content}](siyuan://blocks/.action{$v.ID})
  5. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  6. .action{range $v:=$block}
  7. - [.action{$v.Content}](siyuan://blocks/.action{$v.ID})
  8. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  9. .action{range $v:=$block}
  10. - [.action{$v.Content}](siyuan://blocks/.action{$v.ID})
  11. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  12. .action{range $v:=$block}
  13. - [.action{$v.Content}](siyuan://blocks/.action{$v.ID})
  14. .action{end}
  15. .action{end}
  16. .action{end}
  17. .action{end}

在父文档下只展示五层级的子文档

moc_ref_5_layer.md

  1. .action{$docid:=.id}
  2. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $docid )}
  3. .action{range $v:=$block}
  4. - ((.action{$v.ID} ".action{$v.Content}"))
  5. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  6. .action{range $v:=$block}
  7. - ((.action{$v.ID} ".action{$v.Content}"))
  8. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  9. .action{range $v:=$block}
  10. - ((.action{$v.ID} ".action{$v.Content}"))
  11. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  12. .action{range $v:=$block}
  13. - ((.action{$v.ID} ".action{$v.Content}"))
  14. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  15. .action{range $v:=$block}
  16. - ((.action{$v.ID} ".action{$v.Content}"))
  17. .action{end}
  18. .action{end}
  19. .action{end}
  20. .action{end}
  21. .action{end}

moc_link_5_layer.md

  1. .action{$docid:=.id}
  2. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $docid )}
  3. .action{range $v:=$block}
  4. - [.action{$v.Content}](siyuan://blocks/.action{$v.ID})
  5. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  6. .action{range $v:=$block}
  7. - [.action{$v.Content}](siyuan://blocks/.action{$v.ID})
  8. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  9. .action{range $v:=$block}
  10. - [.action{$v.Content}](siyuan://blocks/.action{$v.ID})
  11. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  12. .action{range $v:=$block}
  13. - [.action{$v.Content}](siyuan://blocks/.action{$v.ID})
  14. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  15. .action{range $v:=$block}
  16. - [.action{$v.Content}](siyuan://blocks/.action{$v.ID})
  17. .action{end}
  18. .action{end}
  19. .action{end}
  20. .action{end}
  21. .action{end}

在父文档下展示最多六层级子文档

有了前面的展示第一层级子文档,如果可以递归的话,就可以展示所有层级的子文档了
但是!!!!
我不知道模板里怎么设置函数、如何递归
所以呢,就手动 copy 几次吧!
六层也够我用了!hhh
(如果大佬们知道如何改进的话,务必告诉我!)

moc_ref_6_layer.md

  1. .action{$docid:=.id}
  2. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $docid )}
  3. .action{range $v:=$block}
  4. - ((.action{$v.ID} ".action{$v.Content}"))
  5. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  6. .action{range $v:=$block}
  7. - ((.action{$v.ID} ".action{$v.Content}"))
  8. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  9. .action{range $v:=$block}
  10. - ((.action{$v.ID} ".action{$v.Content}"))
  11. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  12. .action{range $v:=$block}
  13. - ((.action{$v.ID} ".action{$v.Content}"))
  14. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  15. .action{range $v:=$block}
  16. - ((.action{$v.ID} ".action{$v.Content}"))
  17. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  18. .action{range $v:=$block}
  19. - ((.action{$v.ID} ".action{$v.Content}"))
  20. .action{end}
  21. .action{end}
  22. .action{end}
  23. .action{end}
  24. .action{end}
  25. .action{end}

【模板】父文档列出第一层级子文档和最多六层级的子文档 - 图3

moc_link_6_layer.md

  1. .action{$docid:=.id}
  2. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $docid )}
  3. .action{range $v:=$block}
  4. - [.action{$v.Content}](siyuan://blocks/.action{$v.ID})
  5. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  6. .action{range $v:=$block}
  7. - [.action{$v.Content}](siyuan://blocks/.action{$v.ID})
  8. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  9. .action{range $v:=$block}
  10. - [.action{$v.Content}](siyuan://blocks/.action{$v.ID})
  11. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  12. .action{range $v:=$block}
  13. - [.action{$v.Content}](siyuan://blocks/.action{$v.ID})
  14. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  15. .action{range $v:=$block}
  16. - [.action{$v.Content}](siyuan://blocks/.action{$v.ID})
  17. .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
  18. .action{range $v:=$block}
  19. - [.action{$v.Content}](siyuan://blocks/.action{$v.ID})
  20. .action{end}
  21. .action{end}
  22. .action{end}
  23. .action{end}
  24. .action{end}
  25. .action{end}