JS 求助 - 按更新时间排序,查询当前文档内的块

3 个 JS 语句
查标题
  1. 自动查询当前及子文档(手动填思源随机生成的文档 ID 也行)
  2. 查询该文档及子文档的所有四级标题
  3. 按更新时间排序(上新下旧)
  4. 右侧显示更新日期(可以关闭,万一觉得日期碍眼)
查段落(一)
  1. 和查标题要求一样,不过改成查段落块、表格块
    • 我不知道 JS 形式表格块能否显示,不能的话算了
  2. 不渲染图片,无论本地还是图床(显示成文本)
    • 就是类似在思源复制图片,它在剪贴板时的文本状态
  3. 查询结果数量为 10
查段落(二)倒序
  1. 查段落(一) 要求一样,不过改成倒序(上旧下新)
  • 思源笔记

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

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

    24850 引用 • 102227 回帖
  • Q&A

    提问之前请先看《提问的智慧》,好的问题比好的答案更有价值。

    9429 引用 • 42947 回帖 • 109 关注
4 操作
8V9q7V 在 2025-03-05 18:59:59 更新了该帖
8V9q7V 在 2025-03-05 17:25:42 更新了该帖
8V9q7V 在 2025-03-05 17:24:15 更新了该帖
8V9q7V 在 2025-03-05 17:22:10 更新了该帖

相关帖子

被采纳的回答
  • 不知是否能满足你需求,你试试看

    先安装 简单查询 js,可参考 [js] 简单查询,让数据从此不再难查,支持显示多字段多视图

    然后

    查询标题

    在文档中输入 {{}} 在对话框中输入以下代码

    //!js // 这里可以修改文档id,为空则自动获取当前文档的id let docId = '' // 是否显示更新时间,true显示, false不显示 const isShowUpdated = true; // 更新时间排序,desc由新到旧,asc由旧到新 const updatedOrder = 'desc'; // 是否包含子文档,true包含, false不包含 const isWithSubDoc = false; docId = docId || protyle.options.rootId; const updatedSql = isShowUpdated ? `, updated as 更新时间__date_w150_2` : ''; const subDocSql = isWithSubDoc ? `and path like '%/${docId}%'` : `and root_id = '${docId}'`; return query( `SELECT id as id__hide, content as 标题__ref_left_1 ${updatedSql} FROM blocks where 1=1 ${subDocSql} and type='h' and subtype='h4' order by updated ${updatedOrder};`, item );

    查询段落

    在文档中输入 {{}} 在对话框中输入以下代码

    //!js // 这里可以修改文档id,为空则自动获取当前文档的id let docId = '' // 是否显示更新时间,true显示, false不显示 const isShowUpdated = true; // 更新时间排序,desc由新到旧,asc由旧到新 const updatedOrder = 'desc'; // 是否包含子文档,true包含, false不包含 const isWithSubDoc = false; docId = docId || protyle.options.rootId; const updatedSql = isShowUpdated ? `, updated as 更新时间__date_w150_2` : ''; const subDocSql = isWithSubDoc ? `and path like '%/${docId}%'` : `and root_id = '${docId}'`; return query( `SELECT id as id__hide, content as 内容__ref_left_1 ${updatedSql} FROM blocks where 1=1 ${subDocSql} and (type='p' or type='t') and content != '' order by updated ${updatedOrder} limit 10;`, item );

欢迎来到这里!

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

注册 关于
请输入回帖内容 ...
  • 其他回帖
  • wilsons 1 2 评论

    字段筛选用 markdown 就好了,这是你想要的效果吗

    image.png

    代码

    查标题

    //!js // 这里可以修改文档id,为空则自动获取当前文档的id let docId = '' // 是否显示更新时间,true显示, false不显示 const isShowUpdated = true; // 更新时间排序,desc由新到旧,asc由旧到新 const updatedOrder = 'desc'; // 是否包含子文档,true包含, false不包含 const isWithSubDoc = false; docId = docId || protyle.options.rootId; const updatedSql = isShowUpdated ? `, updated as 更新时间__date_w150_2` : ''; const subDocSql = isWithSubDoc ? `and path like '%/${docId}%'` : `and root_id = '${docId}'`; return query( `SELECT id as id__hide, markdown as 标题__md_ref_left_1 ${updatedSql} FROM blocks where 1=1 ${subDocSql} and type='h' and subtype='h4' order by updated ${updatedOrder};`, item );

    查段落

    //!js // 这里可以修改文档id,为空则自动获取当前文档的id let docId = '' // 是否显示更新时间,true显示, false不显示 const isShowUpdated = true; // 更新时间排序,desc由新到旧,asc由旧到新 const updatedOrder = 'desc'; // 是否包含子文档,true包含, false不包含 const isWithSubDoc = false; docId = docId || protyle.options.rootId; const updatedSql = isShowUpdated ? `, updated as 更新时间__date_w150_2` : ''; const subDocSql = isWithSubDoc ? `and path like '%/${docId}%'` : `and root_id = '${docId}'`; return query( `SELECT id as id__hide, markdown as 内容__md_ref_left_1 ${updatedSql} FROM blocks where 1=1 ${subDocSql} and (type='p' or type='t') and content != '' order by updated ${updatedOrder} limit 10;`, item, '', ({ row, index, data, ...args }) => { row.内容 = row.内容.replace(/<img/ig, '<img width="25%" style="float: left;"'); } );
    2 回复
    1 操作
    wilsons 在 2025-03-08 13:25:23 更新了该回帖
    凌晨还在回复,请你吃个馒头了~
    8V9q7V 1
    ❤️ 非常感谢!
    wilsons
  • ???

    image.png

    image.png

    1 回复
  • 因为有引用样式导致的,去掉样式即可

    查标题

    //!js // 这里可以修改文档id,为空则自动获取当前文档的id let docId = '' // 是否显示更新时间,true显示, false不显示 const isShowUpdated = true; // 更新时间排序,desc由新到旧,asc由旧到新 const updatedOrder = 'desc'; // 是否包含子文档,true包含, false不包含 const isWithSubDoc = false; docId = docId || protyle.options.rootId; const updatedSql = isShowUpdated ? `, updated as 更新时间__date_w150_2` : ''; const subDocSql = isWithSubDoc ? `and path like '%/${docId}%'` : `and root_id = '${docId}'`; return query( `SELECT id as id__hide, markdown as 标题__md_ref_left_1 ${updatedSql} FROM blocks where 1=1 ${subDocSql} and type='h' and subtype='h4' order by updated ${updatedOrder};`, item, '', ({ row, index, data, ...args }) => { row.标题_style = (row.标题_style || '') + ';max-height:none;'; row.标题 = row.标题.replace(/<span data-type="block-ref"/ig, '<span data-type="block-ref" style="background-color: transparent;border-bottom: none;"'); row.更新时间_style = (row.更新时间_style || '') + ';max-height:none;'; } );

    查段落

    //!js // 这里可以修改文档id,为空则自动获取当前文档的id let docId = '' // 是否显示更新时间,true显示, false不显示 const isShowUpdated = true; // 更新时间排序,desc由新到旧,asc由旧到新 const updatedOrder = 'desc'; // 是否包含子文档,true包含, false不包含 const isWithSubDoc = false; docId = docId || protyle.options.rootId; const updatedSql = isShowUpdated ? `, updated as 更新时间__date_w150_2` : ''; const subDocSql = isWithSubDoc ? `and path like '%/${docId}%'` : `and root_id = '${docId}'`; return query( `SELECT id as id__hide, markdown as 内容__md_ref_left_1 ${updatedSql} FROM blocks where 1=1 ${subDocSql} and (type='p' or type='t') and content != '' order by updated ${updatedOrder} limit 10;`, item, '', ({ row, index, data, ...args }) => { row.内容_style = (row.内容_style || '') + ';max-height:none;'; row.更新时间_style = (row.更新时间_style || '') + ';max-height:none;'; row.内容 = row.内容.replace(/<img/ig, '<img width="25%" style="float: left;"'); row.内容 = row.内容.replace(/<span class="img__net">.*?<\/span>/ig, ''); row.内容 = row.内容.replace(/<span data-type="block-ref"/ig, '<span data-type="block-ref" style="background-color: transparent;border-bottom: none;"'); } );
    1 操作
    wilsons 在 2025-03-10 10:02:04 更新了该回帖
  • 查看全部回帖