custom-new-page-2-settings
2022-02-19
17:44:05 バグ修正
↓のinterface差し替えに不備があった
2022-02-17
code:script.js
import { cutIndent } from '../custom-new-page-2/script.js';
import { parse, toString, isTask } from "../takker99%2Ftakker-scheduler/deps.ts";
import { caret, getText } from "../scrapbox-userscript-std/mod.ts";
import { lightFormat } from '../date-fns.min.js/script.js';
const foodType = {
'あさごはん': '#log-breakfast',
'ひるごはん': '#log-lunch',
'よるごはん': '#log-dinner',
};
export const settings = [
{
judge: (lines) => lines.length >= 2 && isTask(lines0), // 箇条書きが無い時は何もしない leftText: (_, {index}) => {
const { title, base, record, ...rest } = parse(getText(index) ?? "");
return toString({title: [${makeTaskTitle(title, base, record)}], base, record, ...rest});
},
newPages: (lines, {index, project}) => {
const { title, base, record } = parse(getText(index) ?? "");
const permalink = [${scrapbox.Page.title}#${scrapbox.Page.lines[index].id}];
const newTitle = makeTaskTitle(title, base, record);
return [
{
project, title: newTitle,
body: [
...(/[\\]/.test(title) ? title : []), // タスク名にリンクが入っていたときはそれを使う ...cutIndent(lines.slice(1)),
from ${permalink},
...((title in foodType) ? [foodTypetitle, '#log-eatenfood'] : []), lightFormat(record?.start ?? base, '#yyyy-MM-dd HH:mm:ss'),
].join('\n'),
},
];
},
},
{
judge: () => true,
const link = line.replace(/[\\]/g, '').trim(); return ${line.match(/^(\s*)/)[0]}[${link}];
},
newPages: (lines, {project, title}) => [{
project,
title: lines0.replace(/[\\]/g, '').trim(), body: [
...cutIndent(lines.slice(1)),
from [${title}],
].join('\n'),
}],
},
];
code:script.js
function makeTaskTitle(title, base, record) {
return (title in foodType) ?
${lightFormat(record?.start ?? base, 'yyyy-MM-dd')} ${title} :
${title.replace(/[\[\]]/g, '').trim()} ${lightFormat(record?.start ?? baseDate, 'yyyy-MM-dd')};
}