Note Refactor
アトミックノート
Obsidian
プラグイン: Note Refactor
▼範囲選択して実行
Note link template
code:txt
▼ {{title}} より
{{date:YYYY-MM-DD}} {{date:hh:mm}}
{{new_note_content}}
Refoctored note template
code:txt
{{date:YYYY-MM-DD}} {{date:hh:mm}} {{new_note_title}}
1Writer
▼何も選択せずに実行
Note link template
[[YYMMDD hhmm]]
Refoctored note template
[[タイトル]] より
▼範囲選択して実行
Note link template
[[YYYY-MM-DD]] hh:mm [[タイトル(1行目のテキスト)]]
Refoctored note template
code:txt
タイトル より
YYYY-MM-DD hh:mm
選択範囲(タイトル含む)
code:アトミックノート.js
// 日付フォーマット用の関数
function formatDate(date) {
const yy = String(date.getFullYear()).slice(-2); // 2桁の年を取得
const MM = String(date.getMonth() + 1).padStart(2, '0');
const dd = String(date.getDate()).padStart(2, '0');
const hh = String(date.getHours()).padStart(2, '0');
const mm = String(date.getMinutes()).padStart(2, '0');
return ${yy}${MM}${dd} ${hh}${mm};
}
// 日付フォーマット用の関数
function formatDateLink(date) {
const yyyy = String(date.getFullYear()); // 4桁の年を取得
const MM = String(date.getMonth() + 1).padStart(2, '0');
const dd = String(date.getDate()).padStart(2, '0');
const hh = String(date.getHours()).padStart(2, '0');
const mm = String(date.getMinutes()).padStart(2, '0');
return [[${yyyy}-${MM}-${dd}]] ${hh}:${mm};
}
// 現在の日時を取得してフォーマット
const now = new Date();
const formattedDate = formatDate(now);
const formattedDateLink = formatDateLink(now)
// 選択範囲を取得
const selectedText = editor.getSelectedText();
const selectedRange = editor.getSelectedRange(); // start, end
const originalFolderPath = editor.getFolderPath(); // 元のノートのフォルダパスを取得
const originalFileName = editor.getFileName(); // 元のノートのファイル名を取得
const originalTitle = originalFileName.replace(/\.md$/, '');
// タスク名の取得
// 現在の行の範囲を取得
let range = editor.getSelectedLineRange();
// 現在の行のテキストを取得
let lineText = editor.getTextInRange(range0, range1);
// 正規表現で行頭のシンボルや時刻部分を削除
let taskName = lineText.replace(/^✅🔲🔁⏰➡️?\s*(\d{2}:\d{2}(?:-\d{2}:\d{2})?)?(\s*\(\d{1,2}:\d{2}\))?\s*�?\s*/g, '').trim();
// テキストをタスク名で置き換え
editor.replaceTextInRange(range.start, range.end, taskName);
let header=▼ [[${originalTitle}]] より\n${formattedDateLink}\n
let footer = ;
if (selectedText.length > 0) {
// 選択範囲がある場合、既存の処理
const lines = selectedText.split('\n');
const title = lines0.trim();
const newFilePath = ${originalFolderPath}/${title}.md;
const contentToAppend = encodeURIComponent(header + selectedText + footer);
const appendURL = onewriter://x-callback-url/append?path=${encodeURIComponent(newFilePath)}&text=${contentToAppend};
app.openURL(appendURL);
// 元のノートにリンクを挿入
const originalNotePath = ${originalFolderPath}/${originalFileName};
editor.openFile(originalNotePath, 'edit', function() {
const link = ${formattedDateLink} [[${title}]];
editor.replaceTextInRange(selectedRange0, selectedRange1, link);
const newCursorPosition = selectedRange0 + link.length;
editor.setSelectedRange(newCursorPosition);
});
} else {
// 選択範囲がない場合
const newFilePath = ${originalFolderPath}/${formattedDate};
// カーソル行の末尾にリンクを挿入
const link = [[${formattedDate}]];
const lineRange = editor.getSelectedLineRange();
editor.replaceTextInRange(lineRange1, lineRange1, link);
// カーソル位置をリンクの文末に設定
const newCursorPosition = lineRange1 + link.length;
editor.setSelectedRange(newCursorPosition);
//header=---\ntc: ${taskName}\n---\n
const content = header + footer;
// 新しいノートを作成
editor.newFile(content,${formattedDate}, function(){editor.setSelectedRange(0)});
}