2.2.20250722 卡片盒笔记法编码体系

#知识管理能力 #卡片盒笔记法 #数字花园 #编码 #方法论

基本信息

简介::基于[[卡片盒笔记法]],建立卡片之间的连接,当然可以使用[[MOC]],也可以使用编码

卢曼的卡片盒,使用的是实体:通过主题箱子和编码系统进行组织,如果这套系统移植到数字化系统上,那就是:索引+卡片盒+编码

  • 索引是moc
  • 卡片盒是标签,双链
  • 编码:用0-9进行分类+英文单词

image.png|600

编码体系

  • 第一位是大类
  • 第二位是大类的分支
  • 第三位是排序位,使用数字

案例:1.1.1

利用的原理

编码体系

/* setTitleFromFilename.js */
async function setTitleFromFilename() {
  const file = app.workspace.getActiveFile();
  if (!file) return;

  /* ===== 排除指定文件 ===== */
  if (['Inbox', '待办记录.components'].includes(file.basename)) return;

  /* ========== 1. 读取并标准化标签 ========== */
  const cache = app.MetadataCache.getFileCache(file);
  const rawTags = cache?.frontmatter?.tags ?? cache?.frontmatter?.tag ?? [];
  const tags = Array.isArray(rawTags)
    ? rawTags.map(t => String(t).toLowerCase())
    : [String(rawTags).toLowerCase()];

  /* ========== 2. 标签 → 前缀 映射表(按优先级排序) ========== */
  const tagRules = [
    { match: ['记录'],        prefix: '1.0' },
    { match: ['酷口家数字花园'],        prefix: '0.0' },
    { match: ['行业'],        prefix: '1.0' },
    { match: ['企业'],        prefix: '1.1' },
    { match: ['动漫','电影','电视剧','书名'],        prefix: '1.3' },
    { match: ['职业'],        prefix: '1.4' },
    { match: ['能力'],        prefix: '1.5' },
    { match: ['思维模型'],    prefix: '2.1' },
    { match: ['技术'],        prefix: '2.2' },
    { match: ['方法论'],      prefix: '2.2' },
    { match: ['概念笔记'],      prefix: '2.3' },
    { match: ['人物', '角色'], prefix: '3.1' },
    { match: ['门派'],        prefix: '3.2' },
    { match: ['大学'],        prefix: '3.3' },
    { match: ['作家','演员'],        prefix: '3.0' },
    { match: ['城市', '地名'], prefix: '4.1' },
    { match: ['河流'], prefix: '4.2' },
    { match: ['山脉'], prefix: '4.3' },
    { match: ['app','法宝'],         prefix: '5.1' },
    { match: ['插件'],        prefix: '5.2' },
    { match: ['灵兽'],         prefix: '5.2' },
    { match: ['功法'],        prefix: '5.3' },
    { match: ['大事记'],        prefix: '6.0' },
    { match: ['攻略'],        prefix: '6.1' },
    { match: ['事件'],        prefix: '6.2' },
    { match: ['灾难'],        prefix: '6.3' },
    { match: ['项目'],        prefix: '6.4' },
    { match: ['清单'],        prefix: '7.1' },
    { match: ['上线记录'],        prefix: '8.0' },
    { match: ['参考资料','书名'], prefix: '9.1' },
    { match: ['自媒体'],      prefix: '9.2' },
    { match: ['剪藏记录'],      prefix: '9.3' },
    { match: ['书单'],      prefix: '9.4' }


  ];

  /* ========== 3. 根据标签确定前缀(命中即停) ========== */
  let prefixBase = '8.1';
  for (const rule of tagRules) {
    if (rule.match.some(k => tags.includes(k))) {
      prefixBase = rule.prefix;
      break;
    }
  }

  /* ========== 4. 拼完整前缀:基础 + 年月日 ========== */
  const today = new Date();
  const y = today.getFullYear();
  const m = String(today.getMonth() + 1).padStart(2, '0');
  const d = String(today.getDate()).padStart(2, '0');
  const datePart = `${y}${m}${d}`;
  const datePrefix = `${prefixBase}.${datePart}`;


/* ========== 5. 处理 title ========== */
const currentTitle = String(cache?.frontmatter?.title ?? '').trim();
const shouldPrefix = prefixBase;                   // 不含日期
const shouldFull   = `${prefixBase}.${datePart}`;  // 含今天日期

const parts = currentTitle.match(/^([\d.]+)\s*(.*)$/);
const oldPrefixRaw = parts ? parts[1] : '';
const body         = parts ? parts[2] : (currentTitle || file.basename);

// 只取前两段,忽略第三段及以后
const pureOld = oldPrefixRaw.replace(/\.\d{8}$/, '').split('.').slice(0, 2).join('.');
let newTitle = '';

if (pureOld !== shouldPrefix) {
  // 规则1:标签不一致 → 重拼
  newTitle = `${shouldFull} ${body.trim()}`;
} else if (/^\d$/.test(pureOld)) {
  // 规则2:单数字且一致 → 重拼
  newTitle = `${shouldFull} ${body.trim()}`;
} else {
  // 规则3:X.X.X 且一致 → 仅补空格
  newTitle = `${oldPrefixRaw} ${body.trim()}`;
}

if (newTitle !== currentTitle) {
  await app.fileManager.processFrontMatter(file, fm => fm.title = newTitle);
  new Notice(`✅ 已更新:${newTitle}`);
}

/* ========== 6. 写回 frontmatter ========== */
  await app.fileManager.processFrontMatter(file, fm => {
    fm.title = newTitle;   // 保持原有 title
    fm.标题  = newTitle;   // 新增:同步到「标题」属性
  });
  new Notice(`✅ 标题:${newTitle}`);


/* ========== 7. 根据 postId 生成 weqoocuurl ========== */
const postId = cache?.frontmatter?.postId;
const existingUrl = cache?.frontmatter?.weqoocuurl;

if (postId && !existingUrl) {  // 仅当 postId 存在且 weqoocuurl 为空/未定义时写入
  const weqoocuurl = `https://weqoocu.com/${postId}.html `;
  await app.fileManager.processFrontMatter(file, fm => {
    fm.weqoocuurl = weqoocuurl;
  });
  new Notice(`✅ weqoocuurl 已写入`);
}
  
  
  
}

module.exports = setTitleFromFilename;



跟多的编码,请参考:[[编码]]的探索过程

滚动至顶部
酷口家数字花园 粤ICP备17140089号-1