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

本贴最后更新于 1152 天前,其中的信息可能已经时移世改

本文已停止更新,最新情况见【模板】父文档列出第一层级子文档和最多六层级的子文档 · 语雀 (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}
  • 思源笔记

    思源笔记是一款隐私优先的个人知识管理系统,支持完全离线使用,同时也支持端到端加密同步。

    融合块、大纲和双向链接,重构你的思维。

    22378 引用 • 89573 回帖

相关帖子

欢迎来到这里!

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

注册 关于
请输入回帖内容 ...