if(logseq.settings.template === undefined){ // 如果插件设置项里没有template。既可以认为第一次打开插件。这里往里面写配置项
logseq.updateSettings({
template:"hello",
});
}
// cosnt { template }= logseq.settings;
// 这里不能用解构语句。因为没有babel转义js的新语法
const template = logseq.settings.template; // 从配置项中读取
console.log(logseq.settings);
console.log(logseq.settings.template);
export type SettingSchemaDesc = {
key: string
type: 'string' | 'number' | 'boolean' | 'enum' | 'object'
default: string | number | boolean | Array<any> | object | null
title: string
description: string // 支持md语法
inputAs?: 'color' | 'date' | 'datetime-local' | 'range'
enumChoices?: Array<string>
enumPicker?: 'select' | 'radio' | 'checkbox' // 默认是 select
}
const schema:Array<SettingSchemaDesc> = [
{
key:"template",
type:"string",
default:"hello",
title:"模板",
description:"插入模板",
},
{
key:"isShow",
type:"boolean",
default:true,
title:"欢迎提示",
description:"是否显示欢迎提示",
}
];
logseq.useSettingsSchema(schema)
import '@logseq/libs'
async function main () {
console.log(logseq.settings);
if(logseq.settings.template === undefined){
logseq.updateSettings({
template:"hello",
isShow:true // 这里加了一个设置项
});
}
//cosnt { template }= logseq.settings;
// 这里不能用解构语句。因为没有babel转义js新语法
const template = logseq.settings.template;
if(logseq.settings.isShow){
logseq.App.showMsg('hello, Logseqer! :)')
}
const schema:Array<SettingSchemaDesc> = [
{
key:"template",
type:"string",
default:"hello",
title:"模板",
description:"插入模板",
},
{
key:"isShow",
type:"boolean",
default:true,
title:"欢迎提示",
description:"是否显示欢迎提示",
}
];
logseq.useSettingsSchema(schema)
logseq.Editor.registerSlashCommand('statement', async () => {
await logseq.Editor.insertAtEditingCursor(
`#+BEGIN_QUOTE
${template}
#+END_QUOTE`,
);
getStatement();
})
}
logseq.ready(main).catch(console.error)