custom-new-page-settings
code:script.js
import {isolate as isolate_, cutIndent} from '../custom-new-page/script.js';
import {parse, create} from '../takker-scheduler-2%2Ftask/script.js';
import {lightFormat} from '../date-fns.min.js/script.js';
export const isolate = () =>
// タイトル行と同じ行を削る
isolate_({
leftText: ({texts, index, project, title}) => makeTaskLine(texts) ?? (() => {
const link = texts0.replace(/[\\]/g, '').trim(); return ${texts[0].replace(/^(\s*).*$/, '$1')}[${link}];
})(),
newPages: ({texts, index, project, title}) => makeTaskPage(texts, index) ?? [{
project,
title: texts0.replace(/[\\]/g, '').trim(), bodies: [
...cutIndent(texts.slice(1)),
from [${title}],
],
}],});
code:script.js
function makeTaskLine(texts) {
if (texts.length < 2) return undefined; // 箇条書きが無い時は何もしない
const task = parse({text: texts0}); if (!task) return undefined;// task lineでなければundefinedを返す
const {content, record, date, ...rest} = task;
return create({content: [${makeTaskTitle(content, record, date)}], record, date, ...rest});
}
function makeTaskPage(texts, index) {
const task = parse({text: texts0}); if (!task) return undefined;// task lineでなければundefinedを返す
const {content, record, date} = task;
const permalink = [${scrapbox.Page.title}#${scrapbox.Page.lines[index].id}];
switch (content) {
case 'あさごはん':
case 'ひるごはん':
case 'よるごはん':
const temp = makeFoodLogPage(task, texts.slice(1), permalink);
return temp;
default:
const title = makeTaskTitle(content, record, date);
return [
// task page
{
project: scrapbox.Project.name,
title,
...cutIndent(texts.slice(1)),
from ${permalink},
lightFormat(record?.start ?? date, '#yyyy-MM-dd HH:mm:ss'),
],
},
// log page
{
project: scrapbox.Project.name,
title: Log | ${commonTaskName(content)},
bodies: [[${title}]],
},
];
}
}
function makeFoodLogPage({content, record}, comments, permalink) {
const foodTypeTag = (() => {
switch(content) {
case 'あさごはん':
return '#log-breakfast';
case 'ひるごはん':
return '#log-lunch';
case 'よるごはん':
return '#log-dinner';
}
})();
return [{
project: scrapbox.Project.name,
title: makeTaskTitle(content, record),
bodies: [
...cutIndent(comments),
from ${permalink},
foodTypeTag,
'#log-eatenfood',
lightFormat(record?.start ?? date, '#yyyy-MM-dd HH:mm:ss'),
],
},];
}
function makeTaskTitle(content, record, date) {
const title = commonTaskName(content);
switch(content) {
case 'あさごはん':
case 'ひるごはん':
case 'よるごはん':
return ${lightFormat(record?.start ?? date, 'yyyy-MM-dd')} ${title};
default:
return ${title} ${lightFormat(record?.start ?? date, 'yyyy-MM-dd')};
}
}
function commonTaskName(content) {
return content.trim()
}