Add text to today's daily note in FocusNote as a new bullet point
此技能将用户提供的文本作为新项目符号添加到 FocusNote 中今天的每日笔记。
当用户要求将文本添加到每日笔记时,请执行以下步骤:
javascript
const fs = require(fs);
const path = require(path);
const os = require(os);
// 从 FocusNote 的配置文件中读取文档路径
const focusnoteConfigPath = path.join(
os.homedir(),
.lucia,
documents-path.txt,
);
const documentsPath = fs.readFileSync(focusnoteConfigPath, utf-8).trim();
javascript
const today = new Date();
const year = today.getFullYear();
const month = String(today.getMonth() + 1).padStart(2, 0);
const day = String(today.getDate()).padStart(2, 0);
const todayDocName = ${year}-${month}-${day};
javascript
const dailyNotePath = path.join(documentsPath, notes, todayDocName);
const structurePath = path.join(dailyNotePath, _structure.json);
const metadataPath = path.join(dailyNotePath, _metadata.json);
const nodesDir = path.join(dailyNotePath, .nodes);
javascript
if (!fs.existsSync(dailyNotePath)) {
// 创建目录结构
fs.mkdirSync(dailyNotePath, { recursive: true });
fs.mkdirSync(nodesDir, { recursive: true });
// 创建元数据
const metadata = {
name: todayDocName,
createdAt: Date.now(),
updatedAt: Date.now(),
};
fs.writeFileSync(metadataPath, JSON.stringify(metadata, null, 2));
// 创建空结构
const structure = {
rootNodeIds: [],
deletedNodeIds: [],
nodes: {},
};
fs.writeFileSync(structurePath, JSON.stringify(structure, null, 2));
}
javascript
const { v4: uuidv4 } = require(uuid); // npm install uuid
// 生成唯一节点 ID
const nodeId = uuidv4();
const timestamp = Date.now();
// 创建 Lexical 项目符号结构
const lexicalContent = {
root: {
children: [
{
children: [
{
children: [
{
detail: 0,
format: 0,
mode: normal,
style: ,
text: userText, // 用户提供的文本
type: text,
version: 1,
},
],
direction: ltr,
format: ,
indent: 0,
type: listitem,
version: 1,
value: 1,
},
],
direction: ltr,
format: ,
indent: 0,
type: list,
version: 1,
listType: bullet,
start: 1,
tag: ul,
},
],
direction: ltr,
format: ,
indent: 0,
type: root,
version: 1,
},
};
// 创建节点对象
const newNode = {
id: nodeId,
content: JSON.stringify(lexicalContent),
isFolded: false,
isTodo: false,
isDone: false,
isInProgress: false,
isBlurred: false,
backgroundColor: null,
createdAt: timestamp,
updatedAt: timestamp,
};
javascript
// 按节点 ID 的前 2 个字符分片
const shard = nodeId.substring(0, 2);
const shardDir = path.join(nodesDir, shard);
if (!fs.existsSync(shardDir)) {
fs.mkdirSync(shardDir, { recursive: true });
}
const nodeFilePath = path.join(shardDir, node-${nodeId}.json);
fs.writeFileSync(nodeFilePath, JSON.stringify(newNode, null, 2));
javascript
// 读取当前结构
const structure = JSON.parse(fs.readFileSync(structurePath, utf-8));
// 将节点添加到结构
structure.rootNodeIds.push(nodeId);
structure.nodes[nodeId] = {
parentId: null,
orderIndex: structure.rootNodeIds.length - 1,
childIds: [],
};
// 更新时间戳
structure.updatedAt = timestamp;
// 保存更新后的结构
fs.writeFileSync(structurePath, JSON.stringify(structure, null, 2));
以下是一个完整的 Node.js 脚本供您使用:
javascript
#!/usr/bin/env node
const fs = require(fs);
const path = require(path);
const os = require(os);
const { v4: uuidv4 } = require(uuid);
function addToDailyNote(userText) {
try {
// 步骤 1:读取文档路径
const focusnoteConfigPath = path.join(
os.homedir(),
.lucia,
documents-path.txt,
);
if (!fs.existsSync(focusnoteConfigPath)) {
throw new Error(
未找到 FocusNote 配置文件。请确保 FocusNote 正在运行。,
);
}
const documentsPath = fs.readFileSync(focusnoteConfigPath, utf-8).trim();
// 步骤 2:生成今天的日期
const today = new Date();
const year = today.getFullYear();
const month = String(today.getMonth() + 1).padStart(2, 0);
const day = String(today.getDate()).padStart(2, 0);
const todayDocName = ${year}-${month}-${day};
// 步骤 3:设置路径
const dailyNotePath = path.join(documentsPath, notes, todayDocName);
const structurePath = path.join(dailyNotePath, _structure.json);
const metadataPath = path.join(dailyNotePath, _metadata.json);
const nodesDir = path.join(dailyNotePath, .nodes);
// 步骤 4:如果需要则创建每日笔记
if (!fs.existsSync(dailyNotePath)) {
fs.mkdirSync(dailyNotePath, { recursive: true });
fs.mkdirSync(nodesDir, { recursive: true });
const metadata = {
name: todayDocName,
createdAt: Date.now(),
updatedAt: Date.now(),
};
fs.writeFileSync(metadataPath, JSON.stringify(metadata, null, 2));
const structure = {
rootNodeIds: [],
deletedNodeIds: [],
nodes: {},
};
fs.writeFileSync(structurePath, JSON.stringify(structure, null, 2));
}
// 步骤 5:创建新项目符号节点
const nodeId = uuidv4();
const timestamp = Date.now();
const lexicalContent = {
root: {
children: [
{
children: [
{
children: [
{
detail: 0,
format: 0,
mode: normal,
style: ,
text: userText,
type: text,
version: 1,
},
],
direction: ltr,
format: ,
indent: 0,
type: listitem,
version: 1,
value: 1,
},
],
direction: ltr,
format: ,
indent: 0,
type: list,
version: 1,
listType: bullet,
start: 1,
tag: ul,
},
],
direction: ltr,
format: ,
indent: 0,
type: root,
version: 1,
},
};
const newNode = {
id: nodeId,
content: JSON.stringify(lexicalContent),
isFolded: false,
isTodo: false,
isDone: false,
isInProgress: false,
isBlurred: false,
backgroundColor: null,
createdAt: timestamp,
updatedAt: timestamp,
};
// 步骤 6:保存节点文件
const shard = nodeId.substring(0, 2);
const shardDir = path.join(nodesDir, shard);
if (!fs.existsSync
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 focusnoteapp-1776420039 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 focusnoteapp-1776420039 技能
skillhub install focusnoteapp-1776420039
文件大小: 3.46 KB | 发布时间: 2026-4-17 20:06