【模板分享】父文档列出第一层级子文档和最多六层级的子文档

本文已停止更新,最新情况见【模板】父文档列出第一层级子文档和最多六层级的子文档 · 语雀 (yuque.com)

如需要展示全部层级的模板见,【模板】父文档列出所有子文档目录模板 · 语雀 (yuque.com)


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

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

目前来说,思源的父子文档比 notion、wolai 更加灵活,不强迫展示子文档,可以在父文档上更自由的书写总结概括或是其他内容,更灵活的利用块引,而不是简单的当作一个建站页面,暴力展示所有子文档。而文件树的架构,本来就能展示子文档,所以不会太影响查看子文档。
但如果有朋友觉得父文档空空如也很不符合习惯,可以看看我下面分享的模板。

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

moc_ref_1_layer.md

.action{.title}
.action{$docid:=.id}
.action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $docid )}

.action{range $v:=$block} 
- ((.action{$v.ID} ".action{$v.Content}")) 
.action{end}

解释思路
父文档下的第一层级子文档,与其他更深层级文档的差别,就是其路径是父文档路径 + 自己 id.sy,
运用了 sql 的 like 语法,下划线代表匹配一个位置的字符,于是就暴力用下划线代表思源文件存储格式 “14 位时间码”“ +“-”+“7 位随机数.sy”

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

该模板按子文档名字顺序排序,并以无序列表的方式展示
保存方法:可以将代码 copy 到工作空间下/data/templates/ 文件夹下,新建 md 文件。使用方法:使用斜杠菜单,选项第一个就是模板,搜索对应的名字就好

但是我突然想到
notion、wolai 的子文档可不是块引用,而是链接!
如果展示子文档全部都用块引用,岂不是大材小用??有时候会增加特别直白无用的引用关系?
块引用不应该这样使用才对啊!
于是我又稍微改动了下,用思源超链接协议展示子文档,照样可以通过点击直达子文档,只是没有块引的鼠标悬浮功能罢了。

.action{.title}

.action{$docid:=.id}
.action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $docid )}

.action{range $v:=$block} 
- [.action{$v.Content}](siyuan://block/.action{$v.ID})
.action{end}


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

坏处

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

moc_ref_2_layer.md

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


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

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


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


以此类推……

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

moc_ref_3_layer.md

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


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



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


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



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

moc_ref_4_layer.md

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


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

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


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

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

moc_ref_5_layer.md

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


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

     .action{end}              
          
    .action{end}
            
.action{end}



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


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

     .action{end}              
          
    .action{end}
            
.action{end}



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

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

moc_ref_6_layer.md

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


    .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
    .action{range $v:=$block}
    - ((.action{$v.ID} ".action{$v.Content}")) 
      .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
      .action{range $v:=$block}
      - ((.action{$v.ID} ".action{$v.Content}"))   
        .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
        .action{range $v:=$block}
        - ((.action{$v.ID} ".action{$v.Content}")) 
            .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
            .action{range $v:=$block}
            - ((.action{$v.ID} ".action{$v.Content}"))   
                .action{$block:= (queryBlocks "SELECT * FROM blocks WHERE type= 'd' AND path like '%/?/______________-_______.sy' Order BY hpath" $v.ID)}
                .action{range $v:=$block}
                - ((.action{$v.ID} ".action{$v.Content}"))   

                .action{end}
            .action{end}
        .action{end}

     .action{end}  
  
    .action{end}
  
.action{end}

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


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

                .action{end}
            .action{end}
        .action{end}

     .action{end}  
  
    .action{end}
  
.action{end}

广告 我要投放

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...
  • larryggao
    支持者 订阅者

    感谢分享模版!已经在用了。

    但这种方式有两个问题:

    • 如果目录下新增或者删除子文档,目录不会自动更新
    • 超链接点击的时候,有一个停顿感,不知道是个例还是普遍现象?

    还是期待思源原生解决此问题。

    1 回复
  • 其他回帖
  • a1993613 1 评论
    支持者 订阅者

    的确,但是不能预览又有点不方便。我对 booting 速度还是可以忍一忍 😂

    嗯,就我自己而言,反正点击查看速度很快,现在也有后退功能,影响不大,以后子文档链接我会尽量用块超链接而不是块引用的
    Achuan-2
  • a1993613
    支持者 订阅者

    666,多谢分享 👍

  • Kikkawa
    支持者 订阅者

    你好,很感谢分享,我也使用了好几次,但是我想问一下,能做一个有序列表的吗

    1 回复
  • 查看全部回帖