返回顶部
f

focusnote-add-to-daily-note添加到每日笔记

Add text to today's daily note in FocusNote as a new bullet point

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
935
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

focusnote-add-to-daily-note

FocusNote:添加到每日笔记

此技能将用户提供的文本作为新项目符号添加到 FocusNote 中今天的每日笔记。

工作原理

  1. 1. 从 ~/.lucia/documents-path.txt 读取 FocusNote 文档路径
  2. 以 YYYY-MM-DD 格式生成今天的日期
  3. 定位或创建今天的每日笔记
  4. 将用户文本作为新项目符号添加
  5. 更新文档的 JSON 结构文件

前提条件

  • - FocusNote 应用必须正在运行(启动时会创建 ~/.lucia/documents-path.txt)
  • 已安装 Node.js 用于运行辅助脚本

实现

当用户要求将文本添加到每日笔记时,请执行以下步骤:

步骤 1:读取文档路径

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();

步骤 2:生成今天的日期

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};

步骤 3:定位每日笔记文件夹

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);

步骤 4:如果每日笔记不存在则创建

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));
}

步骤 5:创建新项目符号节点

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,
};

步骤 6:将节点保存到分片目录

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));

步骤 7:更新结构文件

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

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 focusnoteapp-1776420039 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 focusnoteapp-1776420039 技能

通过命令行安装

skillhub install focusnoteapp-1776420039

下载

⬇ 下载 focusnote-add-to-daily-note v1.0.0(免费)

文件大小: 3.46 KB | 发布时间: 2026-4-17 20:06

v1.0.0 最新 2026-4-17 20:06
FocusNote: Add to Daily Note skill, initial release.

- Adds user-provided text as a new bullet point to today's daily note in FocusNote.
- Automatically creates today's daily note if it doesn't exist.
- Ensures notes are stored and structured in FocusNote's native directory and JSON format.
- Requires Node.js and a running FocusNote app for use.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部