Zuoqiu-Yingyi / widget-query

一个将思源笔记数据库查询结果以表格样式渲染的挂件 | A widget that renders the query results of the Siyuan Notes database in tabular style.
GNU Affero General Public License v3.0
55 stars 7 forks source link

能否把不符合正则的表达式,字段也渲染下。另外使用select created markedown 返回的结果顺序不是按照写的顺序来的。 #6

Closed Danielypzhang closed 2 years ago

Danielypzhang commented 2 years ago

自己改了config js, 实现渲染 default: { handler: (row, key) => { switch (key) { case 'markdown':

                        switch (config.query.limit) {
                            case 'len':
                                return markdown2span(cutString(ReplaceSpace(row.markdown, config.query.space), config.query.maxlen));
                            case 'row':
                                return markdown2span(ReplaceCRLF(cutString(row.markdown, undefined, config.query.maxrow), config.query.CRLF));
                            default:
                                return markdown2span(row.markdown);
                            };

                    case 'created':

                        return timestampFormat(row.created);

                    case 'updated':
                        return timestampFormat(row.updated);
                    case 'type':
                        return `((${row.id} "${config.query.map.blocktype[row.type]}"))`;
                    case 'hpath':
                        return `((${row.root_id} "${row.hpath}"))`;
                    case 'id':
                        return `((${row.id} "${row.id}"))`;
                    case 'parent_id':
                        if (isEmptyString(row.parent_id)) return '';
                        else return `((${row.parent_id} "${row.parent_id}"))`;
                    case 'root_id':
                        return `((${row.root_id} "${row.root_id}"))`;

                    case 'hash':
                        return `\`${row.hash}\``;

                    case 'box':
                        return `\`${row.box}\``;

                    case 'path':
                        return `\`${row.path}\``;

                    case 'name':
                        return markdown2span(row.name);

                    case 'alias':
                        return markdown2span(row.alias);

                    case 'memo':
                        return markdown2span(row.memo);

                    case 'length':
                        return row.length;

                    case 'subtype':
                        return config.query.map.subtype[row.subtype];

                    case 'ial':
                        let ial = ialParser(row.ial);
                        let ial_markdown = [];
                        for (let key of Object.keys(ial)) {
                            switch (key) {
                                case 'id':
                                case 'updated':
                                    continue;
                                case 'icon':
                                    ial_markdown.push(`\`${key}\`\: :${ial[key].replace(/\.\w+$/, '')}:`);
                                    break;
                                default:
                                    ial_markdown.push(`\`${key}\`\: \`${ial[key]}\``);
                                    break;
                            }
                        }
                        return ial_markdown.join(config.query.CRLF);

                    case 'sort':
                        return row.sort;

                    default:
                        return `\`${row[key]}\``;

                    }// 其他查询结果默认处理方法, row 是查询结果的一条记录, key 是字段名

                    },
Zuoqiu-Yingyi commented 2 years ago

@Danielypzhang