Skip to content

Commit

Permalink
Add option to disable index
Browse files Browse the repository at this point in the history
  • Loading branch information
ttimasdf committed Mar 24, 2022
1 parent 65aa790 commit afa80e3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/script/module/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export var config = {
align: ':-',
},
},
withIndex: false,
fields: [ // 需渲染的 blocks 表的字段, 顺序分先后
'type', // 内容块类型,参考((20210210103523-ombf290 "类型字段"))
// 'content', // 去除了 Markdown 标记符的文本
Expand Down
32 changes: 20 additions & 12 deletions src/script/module/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,12 @@ export async function widgetBlock(data) {

if (data.config.query.regs.blocks.test(data.sql)) {
// 匹配指定正则的 SQL 查询, 是 `SELECT * FROM blocks ...` 语句
let header = []; // 表头
let align = []; // 对齐样式
header.push("| |");
align.push("| -: |");
let header = ['|']; // 表头
let align = ['|']; // 对齐样式
if (data.config.query.withIndex) {
header.push(" |");
align.push("| -: |");
}
for (let field of data.config.query.fields) {
// 根据自定义字段列表,构造表头
header.push(` ${field}${data.config.query.style.column[field]} |`);
Expand Down Expand Up @@ -174,8 +176,10 @@ export async function widgetBlock(data) {
// 解析内联属性列表(inline attribute list, IAL)
let ial = ialParser(row.ial);

let row_markdown = [];
row_markdown.push(`| ${index} |`);
let row_markdown = [`|`];
if (data.config.query.withIndex) {
row_markdown.push(`${index} |`);
}
for (let field of data.config.query.fields) {
// 根据自定义字段列表,构造表格
row_markdown.push(` ${data.config.query.handler[field](row, ial)} |`);
Expand All @@ -192,12 +196,14 @@ export async function widgetBlock(data) {
let header_row = null;
if (data.rows.length > 0) {
header_row = data.rows[0];
let header = []; // 表头
let align = []; // 对齐样式
let header = ['|']; // 表头
let align = ['|']; // 对齐样式
let renderer = {}; // 渲染器
let keys = Object.keys(header_row);
header.push(`| |`);
align.push(`| -: |`);
if (data.config.query.withIndex) {
header.push(" |");
align.push(" -: |");
}
for (var key of keys) {
header.push(` ${data.config.query.default.name(key)}${data.config.query.default.style.column} |`);
align.push(` ${data.config.query.default.style.align} |`);
Expand All @@ -212,8 +218,10 @@ export async function widgetBlock(data) {
let row = data.rows[i - 1];
// console.log(row);

let row_markdown = [];
row_markdown.push(`| ${i} |`);
let row_markdown = [`|`];
if (data.config.query.withIndex) {
row_markdown.push(`${index} |`);
}
for (var key of keys) {
if (row[key] == "" || row[key] == null || row[key] == undefined) {
row_markdown.push(` |`);
Expand Down

0 comments on commit afa80e3

Please # to comment.