ゆるふわ振り返りページのtemplate
既存の方法(手書き)からの改善点
手書きで毎回書いていたことを自動化した
日付タグをページ上部においた
日付タグの関連ページを閲覧しやすくすることを期待している
「明日やること」を翌日のページに書くようにした
今日の振り返りページを作ると同時に、明日の振り返りページも作る
「明日やること」の欄に明日の振り返りページへのリンクを乗せることで、明日のページにちゃんとやることを書くよう促す
code:script.ts
import {
ensure, openInTheSameTab, reviewTitle,
} from "./mod.ts";
const today = new Date();
const tomorrow = addDays(today, 1);
今日から次の土曜日までのゆるふわ振り返りページを作っておく
code:script.ts
for (const date of eachDayOfInterval({
start: today,
end: nextSaturday(tomorrow),
})) {
await ensure(date, {
project: scrapbox.Project.name,
created: today,
})
}
当日のゆるふわ振り返りページを開く
code:script.ts
openInTheSameTab(scrapbox.Project.name, reviewTitle(today));
module
code:mod.ts
const format = "yyyy-MM-dd";
振り返りページ生成函数
code:mod.ts
export const reviewTitle = (date: Date) =>
${lightFormat(date, format)} 振り返り;
const template = (today: Date, created: Date) => [
"今日やること",
" ",
"",
"/icons/hr.icon",
前回:[${reviewTitle(subDays(today, 1))}],
"",
"",
今日やったこと[. [/takker/${lightFormat(today, format)}]],
" ",
"",
"今日やれなかったこと",
" ",
"",
"明日やること",
→[${reviewTitle(addDays(today, 1))}],
"",
"",
今日のn年前[. [/takker/${lightFormat(subYears(today, 1), format)}] ],
" ",
"",
#${lightFormat(created, "yyyy-MM-dd HH:mm:ss")},
];
export interface EnsureProps {
project: string;
created?: Date;
}
export async function ensure(
date: Date,
{project, created}: EnsureProps,
) {
const title = reviewTitle(date);
if (scrapbox.Project.pages.some(
(page) => page.exists && page.title === title
)) return;
created ??= date;
await patch(
project,
title,
);
}
code:nextDay.ts
/**
* @name nextDay
* @category Weekday Helpers
* @summary When is the next day of the week?
*
* @description
* When is the next day of the week? 0-6 the day of the week, 0 represents Sunday.
*
* @param {Date | number} date - the date to check
* @param {Day} day - day of the week
* @returns {Date} - the date is the next day of week
* @throws {TypeError} - 2 arguments required
*
* @example
* // When is the next Monday after Mar, 20, 2020?
* const result = nextDay(new Date(2020, 2, 20), 1)
* //=> Mon Mar 23 2020 00:00:00
*
* @example
* // When is the next Tuesday after Mar, 21, 2020?
* const result = nextDay(new Date(2020, 2, 21), 2)
* //=> Tue Mar 24 2020 00:00:00
*/
export default function nextDay(date: Date | number, day: Day): Date {
requiredArgs(2, arguments)
const map = genMap(day)
}
function genMap(daysToMove: number): number[] {
if (daysToMove === 0) {
return baseMap
} else {
const mapStart = baseMap.slice(-daysToMove)
const mapEnd = baseMap.slice(0, baseMap.length - daysToMove)
return mapStart.concat(mapEnd)
}
}
code:import_map.json
{
"imports": {
}
}
code:script.js
function x(e){if(e===null||e===!0||e===!1)return NaN;let t=Number(e);return isNaN(t)?t:t<0?Math.ceil(t):Math.floor(t)}function d(e,t){if(t.length<e)throw new TypeError(e+" argument"+(e>1?"s":"")+" required, but only "+t.length+" present")}function m(e){d(1,arguments);let t=Object.prototype.toString.call(e);return e instanceof Date||typeof e=="object"&&t==="object Date"?new Date(e.getTime()):typeof e=="number"||t==="object Number"?new Date(e):((typeof e=="string"||t==="object String")&&typeof console!="undefined"&&(console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use parseISO to parse strings. See: https://git.io/fjule"),console.warn(new Error().stack)),new Date(NaN))}function T(e,t){d(2,arguments);let n=m(e),r=x(t);return isNaN(r)?new Date(NaN):(r&&n.setDate(n.getDate()+r),n)}function F(e,t){d(2,arguments);let n=x(t);return T(e,-n)}function q(e,t){d(2,arguments);let n=m(e),r=x(t);if(isNaN(r))return new Date(NaN);if(!r)return n;let o=n.getDate(),s=new Date(n.getTime());s.setMonth(n.getMonth()+r+1,0);let i=s.getDate();return o>=i?s:(n.setFullYear(s.getFullYear(),s.getMonth(),o),n)}function K(e,t){d(2,arguments);let n=x(t);return q(e,n*12)}function Y(e,t){d(2,arguments);let n=x(t);return K(e,-n)}function v(e,t){for(var n=e<0?"-":"",r=Math.abs(e).toString();r.length<t;)r="0"+r;return n+r}var Le={y(e,t){let n=e.getUTCFullYear(),r=n>0?n:1-n;return v(t==="yy"?r%100:r,t.length)},M(e,t){let n=e.getUTCMonth();return t==="M"?String(n+1):v(n+1,2)},d(e,t){return v(e.getUTCDate(),t.length)},a(e,t){let n=e.getUTCHours()/12>=1?"pm":"am";switch(t){case"a":case"aa":return n.toUpperCase();case"aaa":return n;case"aaaaa":return n0;case"aaaa":default:return n==="am"?"a.m.":"p.m."}},h(e,t){return v(e.getUTCHours()%12||12,t.length)},H(e,t){return v(e.getUTCHours(),t.length)},m(e,t){return v(e.getUTCMinutes(),t.length)},s(e,t){return v(e.getUTCSeconds(),t.length)},S(e,t){let n=t.length,r=e.getUTCMilliseconds(),o=Math.floor(r*Math.pow(10,n-3));return v(o,t.length)}},se=Le;function z(e){let t=new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()));return t.setUTCFullYear(e.getFullYear()),e.getTime()-t.getTime()}function W(e){d(1,arguments);var t=m(e);return!isNaN(t)}function Q(e,t){d(2,arguments);let n=m(e).getTime(),r=x(t);return new Date(n+r)}function G(e,t){d(2,arguments);let n=x(t);return Q(e,-n)}var Me=/(\w)\1*|''|'(''|^')+('|$)|./g,Ce=/^'(^*?)'?$/,Ne=/''/g,Pe=/a-zA-Z/;function I(e,t){d(2,arguments);let n=m(e);if(!W(n))throw new RangeError("Invalid time value");let r=z(n),o=G(n,r),s=t.match(Me);return s?s.map(a=>{if(a==="''")return"'";let c=a0;if(c==="'")return Oe(a);let p=sec;if(p)return p(o,a);if(c.match(Pe))throw new RangeError("Format string contains an unescaped latin alphabet character "+c+"");return a}).join(""):""}function Oe(e){let t=e.match(Ce);return t?t1.replace(Ne,"'"):e}var C=e=>e.replaceAll(" ","_").toLowerCase();var R=e=>...e.map((t,n)=>t===" "?"_":!je.includes(t)||n===e.length-1&&Ue.includes(t)?encodeURIComponent(t):t).join(""),je='@$&+=:;",',Ue=':;",';function X(e,t,n){let r=document.createElement("a");r.href=/${e}/${R(t)}${typeof n!="string"?"":?body=${encodeURIComponent(n)}},document.body.append(r),r.click(),r.remove()}var $e="4.2.0";async function N(){let t=(await Be())("https://scrapbox.io",{reconnectionDelay:5e3,transports:["websocket"]});return await new Promise((n,r)=>{let o=s=>r(s);t.once("connect",()=>{t.off("disconnect",o),n()}),t.once("disconnect",o)}),t}function Be(){let e=https://cdnjs.cloudflare.com/ajax/libs/socket.io/${$e}/socket.io.min.js;if(document.querySelector(script[src="${e}"]))return Promise.resolve(window.io);let t=document.createElement("script");return t.src=e,new Promise((n,r)=>{t.onload=()=>n(window.io),t.onerror=o=>r(o),document.head.append(t)})}function P(e,t=9e4){function n(o,s){let i;return new Promise((a,c)=>{let p=u=>{clearTimeout(i),c(new Error(u))};e.emit(o,s,u=>{clearTimeout(i),e.off("disconnect",p),u.error&&c(new Error(JSON.stringify(u.error))),"data"in u?a(u?.data):a(void 0)}),i=setTimeout(()=>{e.off("disconnect",p),c(new Error(Timeout: exceeded ${t}ms))},t),e.once("disconnect",p)})}async function*r(...o){let s,i=()=>new Promise(c=>s=c),a=c=>{s?.(c)};for(let c of o)e.on(c,a);try{for(;;)yield await i()}finally{for(let c of o)e.off(c,a)}}return{request:n,response:r}}var L=e=>connect.sid=${e};function Fe(e){return e!=null}function qe(e){return Fe(e)?(e.name===void 0||typeof e.name=="string")&&typeof e.message=="string":!1}function _(e){try{let t=typeof e=="string"?JSON.parse(e):e;return qe(t)?t:!1}catch(t){if(t instanceof SyntaxError)return!1;throw t}}function M(e,t){let n=new Error;return n.name=e,n.message=t,n}async function ce(e,t){let n=https://scrapbox.io/api/projects/${e},r=await fetch(n,t?.sid?{headers:{Cookie:L(t.sid)}}:void 0);if(!r.ok){let s=_(await r.json());if(!s)throw M("UnexpectedError",Unexpected error has occuerd when fetching "${n}");return{ok:!1,value:s}}let o=await r.json();return{ok:!0,value:o}}async function ue(e){let t="https://scrapbox.io/api/users/me",n=await fetch(t,e?.sid?{headers:{Cookie:L(e.sid)}}:void 0);if(!n.ok)throw M("UnexpectedError",Unexpected error has occuerd when fetching "${t}");return await n.json()}var j;async function V(){if(j!==void 0)return j;let e=await ue();if(e.isGuest)throw new Error("this script can only be executed by Logged in users");return j=e.id,j}var de=new Map;async function U(e){let t=de.get(e);if(t!==void 0)return t;let n=await ce(e);if(!n.ok){let{name:o,message:s}=n.value;throw new Error(${o} ${s})}let{id:r}=n.value;return de.set(e,r),r}function pe(e){return e.padStart(8,"0")}function le(e){let t=Math.floor(new Date().getTime()/1e3).toString(16),n=Math.floor(16777214*Math.random()).toString(16);return${pe(t).slice(-8)}${e.slice(-6)}0000${pe(n)}}function me(e,t){let n=e.length>t.length,r=n?t:e,o=n?e:t,s=r.length+1,i=r.length+o.length+3,a=new Array(i);a.fill(-1);let c=[];function p(l,b,k){let E=Math.max(b,k),S=E-l;for(;S<r.length&&E<o.length&&rS===oE;)++S,++E;return al+s=c.length,c.push([{x:S,y:E},al+(b>k?-1:1)+s]),E}let u=new Array(i);u.fill(-1);let y=-1,g=o.length-r.length;do{++y;for(let l=-y;l<=g-1;++l)ul+s=p(l,ul-1+s+1,ul+1+s);for(let l=g+y;l>=g+1;--l)ul+s=p(l,ul-1+s+1,ul+1+s);ug+s=p(g,ug-1+s+1,ug+1+s)}while(ug+s!==o.length);let A=[],w=ag+s;for(;w!==-1;)A.push(cw0),w=cw1;return{from:e,to:t,editDistance:g+y*2,buildSES:function*(){let l=0,b=0;for(let{x:k,y:E}of Ke(A))for(;l<k||b<E;)E-k>b-l?(yield{value:ob,type:n?"deleted":"added"},++b):E-k<b-l?(yield{value:rl,type:n?"added":"deleted"},++l):(yield{value:rl,type:"common"},++l,++b)}}}function*fe(e){let t=[],n=[];function*r(){if(t.length>n.length){for(let o=0;o<n.length;o++)yield ge(to,no);for(let o=n.length;o<t.length;o++)yield to}else{for(let o=0;o<t.length;o++)yield ge(to,no);for(let o=t.length;o<n.length;o++)yield no}t=[],n=[]}for(let o of e)switch(o.type){case"added":t.push(o);break;case"deleted":n.push(o);break;case"common":yield*r(),yield o;break}yield*r()}function ge(e,t){return{value:e.value,oldValue:t.value,type:"replaced"}}function*Ke(e){for(let t=e.length-1;t>=0;t--)yield et}function*he(e,t,{userId:n}){let{buildSES:r}=me(e.map(({text:i})=>i),t),o=0,s=e0.id;for(let i of fe(r())){switch(i.type){case"added":yield{_insert:s,lines:{id:le(n),text:i.value}};continue;case"deleted":yield{_delete:s,lines:-1};break;case"replaced":yield{_update:s,lines:{text:i.value}};break}o++,s=eo?.id??"_end"}}var Ye=e=>({type:"title",text:e.rows0.text}),ze=e=>{let{rows:t,...n}=e,{indent:r=0,text:o=""}=t??{},s=o.replace(/^\s*code:/,"");return{indent:r,type:"codeBlock",fileName:s,content:n.map(i=>i.text.substring(r+1)).join(` )}},f=(e,{parseOnNested:t,parseOnQuoted:n,patterns:r})=>(o,s,i)=>{var a,c,p,u,y,g;if(!t&&s.nested)return(a=i==null?void 0:i())!==null&&a!==void 0?a:[];if(!n&&s.quoted)return(c=i==null?void 0:i())!==null&&c!==void 0?c:[];for(let A of r){let w=A.exec(o);if(w===null)continue;let l=o.substring(0,w.index),b=o.substring(w.index+((u=(p=w[0])===null||p===void 0?void 0:p.length)!==null&&u!==void 0?u:0)),k=e((y=w[0])!==null&&y!==void 0?y:"",s);return[...D(l,s),...k,...D(b,s)]}return(g=i==null?void 0:i())!==null&&g!==void 0?g:[]},h=e=>[{type:"plain",raw:e,text:e}],We=f(h,{parseOnNested:!0,parseOnQuoted:!0,patterns:[/^()(.*)()$/]}),Qe=/^>.*$/,Ge=(e,t)=>t.context==="table"?h(e,t):[{type:"quote",raw:e,nodes:D(e.substring(1),{...t,quoted:!0})}],Xe=f(Ge,{parseOnNested:!1,parseOnQuoted:!1,patterns:[Qe]}),Ve=/^\? .+$/,Je=(e,t)=>t.context==="table"?h(e,t):[{type:"helpfeel",raw:e,text:e.substring(2)}],Ze=f(Je,{parseOnNested:!1,parseOnQuoted:!1,patterns:[Ve]}),et=/\[\[https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)\]\]/i,tt=/\[\[https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}\]\]/,nt=(e,t)=>{if(t.context==="table")return h(e,t);let n=e.substring(2,e.length-2),r=/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}$/.test(n);return[{type:"strongImage",raw:e,src:r?${n}/thumb/1000:n}]},rt=f(nt,{parseOnNested:!1,parseOnQuoted:!0,patterns:[et,tt]}),ot=/\[[^[\]]*\.icon(?:\*[1-9]\d*)?\]/;function xe(e){return(t,n)=>{if(e==="strongIcon"&&n.context==="table")return h(t,n);let r=e==="icon"?t.substring(1,t.length-1):t.substring(2,t.length-2),o=r.lastIndexOf(".icon"),s=r.substring(0,o),i=s.startsWith("/")?"root":"relative",a=r.substring(o+5,r.length),c=a.startsWith("*")?parseInt(a.substring(1),10):1;return new Array(c).fill({}).map(()=>({path:s,pathType:i,type:e,raw:t}))}}var st=xe("icon"),it=f(st,{parseOnNested:!1,parseOnQuoted:!0,patterns:[ot]}),at=/\[\[[^[\]]*\.icon(?:\*\d+)?\]\]/,ct=xe("strongIcon"),ut=f(ct,{parseOnNested:!1,parseOnQuoted:!0,patterns:[at]}),dt=/\[\[(?:[^[]|\[[^[]).*?\]*\]\]/,pt=(e,t)=>t.context==="table"?h(e,t):[{type:"strong",raw:e,nodes:D(e.substring(2,e.length-2),{...t,nested:!0})}],lt=f(pt,{parseOnNested:!1,parseOnQuoted:!0,patterns:[dt]}),mt=/\[\$ .+? \]/,ft=/\[\$ [^\]]+\]/,gt=(e,t)=>t.context==="table"?h(e,t):[{type:"formula",raw:e,formula:e.substring(3,e.length-(e.endsWith(" ]")?2:1))}],ht=f(gt,{parseOnNested:!1,parseOnQuoted:!0,patterns:[mt,ft]}),xt=/\[[!"#%&'()*+,\-./{|}<>_~]+ (?:\[[^[\]]+\]|[^\]])+\]/,yt=(e,t)=>{if(t.context==="table")return h(e,t);let n=e.indexOf(" "),r=e.substring(1,n),o=e.substring(n+1,e.length-1),s=new Set(r);if(s.has("*")){let i=r.split("*").length-1;s.delete("*"),s.add(*-${Math.min(i,10)})}return[{type:"decoration",raw:e,rawDecos:r,decos:Array.from(s),nodes:D(o,{...t,nested:!0})}]},bt=f(yt,{parseOnNested:!1,parseOnQuoted:!0,patterns:[xt]}),wt=/.*?/,Et=(e,t)=>t.context==="table"?h(e,t):[{type:"code",raw:e,text:e.substring(1,e.length-1)}],vt=f(Et,{parseOnNested:!1,parseOnQuoted:!0,patterns:[wt]}),Tt=/^[$%] .+$/,kt=(e,t)=>{var n;if(t.context==="table")return h(e,t);let r=(n=e[0])!==null&&n!==void 0?n:"",o=e.substring(2);return[{type:"commandLine",raw:e,symbol:r,text:o}]},Dt=f(kt,{parseOnNested:!1,parseOnQuoted:!1,patterns:[Tt]}),It=/\[\s+\]/,Lt=(e,t)=>t.context==="table"?h(e,t):[{type:"blank",raw:e,text:e.substring(1,e.length-1)}],Mt=f(Lt,{parseOnNested:!1,parseOnQuoted:!0,patterns:[It]}),Ct=/\[https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)(?:\?[^\]\s]+)?(?:\s+https?:\/\/[^\s\]]+)?\]/i,Nt=/\[https?:\/\/[^\s\]]+\s+https?:\/\/[^\s\]]+\.(?:png|jpe?g|gif|svg)(?:\?[^\]\s]+)?\]/i,Pt=/\[https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}(?:\/raw)?(?:\s+https?:\/\/[^\s\]]+)?\]/,Ot=/\[https?:\/\/[^\s\]]+\s+https?:\/\/(?:[0-9a-z-]+\.)?gyazo\.com\/[0-9a-f]{32}(?:\/raw)?\]/,Ht=e=>/^https?:\/\/[^\s\]]+\.(png|jpe?g|gif|svg)(\?[^\]\s]+)?$/i.test(e)||At(e),At=e=>/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}(\/raw)?$/.test(e),St=(e,t)=>{if(t.context==="table")return h(e,t);let n=e.search(/\s/),r=n!==-1?e.substring(1,n):e.substring(1,e.length-1),o=n!==-1?e.substring(n,e.length-1).trimLeft():"",[s,i]=Ht(o)?[o,r]:[r,o];return[{type:"image",raw:e,src:/^https?:\/\/([0-9a-z-]\.)?gyazo\.com\/[0-9a-f]{32}$/.test(s)?${s}/thumb/1000:s,link:i}]},Rt=f(St,{parseOnNested:!0,parseOnQuoted:!0,patterns:[Ct,Nt,Pt,Ot]}),_t=/\[https?:\/\/[^\s\]]+\s+[^\]]*[^\s]\]/,jt=/\[[^[\]]*[^\s]\s+https?:\/\/[^\s\]]+\]/,Ut=/\[https?:\/\/[^\s\]]+\]/,$t=/https?:\/\/[^\s]+/,Bt=(e,t)=>{if(t.context==="table")return h(e,t);let n=e.startsWith("[")&&e.endsWith("]")?e.substring(1,e.length-1):e,r=/^https?:\/\/[^\s\]]/.test(n),o=(r?/^https?:\/\/[^\s\]]+/:/https?:\/\/[^\s\]]+$/).exec(n);if((o==null?void 0:o[0])===void 0)return[];let s=r?n.substring(o[0].length):n.substring(0,o.index-1);return[{type:"link",raw:e,pathType:"absolute",href:o[0],content:s.trim()}]},Ft=f(Bt,{parseOnNested:!0,parseOnQuoted:!0,patterns:[_t,jt,Ut,$t]}),ye=/\[([^\]]*[^\s])\s+([NS]\d+(?:\.\d+)?,[EW]\d+(?:\.\d+)?(?:,Z\d+)?)\]/,be=/\[([NS]\d+(?:\.\d+)?,[EW]\d+(?:\.\d+)?(?:,Z\d+)?)(?:\s+([^\]]*[^\s]))?\]/,qt=e=>{let[t="",n="",r=""]=e.split(","),o=parseFloat(t.replace(/^N/,"").replace(/^S/,"-")),s=parseFloat(n.replace(/^E/,"").replace(/^W/,"-")),i=/^Z\d+$/.test(r)?parseInt(r.replace(/^Z/,""),10):14;return{latitude:o,longitude:s,zoom:i}},Kt=(e,t)=>{var n;if(t.context==="table")return h(e,t);let r=(n=e.match(ye))!==null&&n!==void 0?n:e.match(be);if(r===null)return[];let o=e.startsWith("[N")||e.startsWith("[S"),[,s="",i=""]=o?r:[r[0],r[2],r[1]],{latitude:a,longitude:c,zoom:p}=qt(s),u=i!==""?https://www.google.com/maps/place/${encodeURIComponent(i)}/@${a},${c},${p}z:https://www.google.com/maps/@${a},${c},${p}z;return[{type:"googleMap",raw:e,latitude:a,longitude:c,zoom:p,place:i,url:u}]},Yt=f(Kt,{parseOnNested:!1,parseOnQuoted:!0,patterns:[ye,be]}),zt=/\[\/?[^[\]]+\]/,Wt=e=>{let t=e.substring(1,e.length-1);return[{type:"link",raw:e,pathType:t.startsWith("/")?"root":"relative",href:t,content:""}]},Qt=f(Wt,{parseOnNested:!0,parseOnQuoted:!0,patterns:[zt]}),Gt=/(?:^|\s)#\S+/,Xt=(e,t)=>{if(t.context==="table")return h(e,t);if(e.startsWith("#"))return[{type:"hashTag",raw:e,href:e.substring(1)}];let n=e.substring(0,1),r=e.substring(1);return[...h(n,t),{type:"hashTag",raw:r,href:r.substring(1)}]},Vt=f(Xt,{parseOnNested:!0,parseOnQuoted:!0,patterns:[Gt]}),Jt=(e,t,n)=>{var r;return e===""?[]:(r=n==null?void 0:n())!==null&&r!==void 0?r:[]},Zt=(...e)=>(t,n)=>e.reduceRight((r,o)=>()=>o(t,n,r),()=>We(t,n))(),D=Zt(Jt,Xe,Ze,vt,Dt,ht,Mt,bt,rt,ut,lt,Rt,Ft,it,Yt,Qt,Vt),en=e=>{let{rows:[t,...n]}=e,{indent:r=0,text:o=""}=t??{},s=o.replace(/^\s*table:/,"");return{indent:r,type:"table",fileName:s,cells:n.map(i=>i.text.substring(r+1)).map(i=>i.split(" ").map(a=>D(a,{nested:!1,quoted:!1,context:"table"})))}},tn=e=>{let{indent:t,text:n}=e.rows[0];return{indent:t,type:"line",nodes:D(n.substring(t),{nested:!1,quoted:!1,context:"line"})}},we=e=>{switch(e.type){case"title":return Ye(e);case"codeBlock":return ze(e);case"table":return en(e);case"line":return tn(e)}},Ee=e=>e.split( ).map(t=>{var n,r,o;return{indent:(o=(r=(n=/^\s+/.exec(t))===null||n===void 0?void 0:n[0])===null||r===void 0?void 0:r.length)!==null&&o!==void 0?o:0,text:t}}),nn=(e,t)=>{var n,r;return(e.type==="codeBlock"||e.type==="table")&&t.indent>((r=(n=e.rows[0])===null||n===void 0?void 0:n.indent)!==null&&r!==void 0?r:0)},ve=(e,t)=>{let n=e[e.length-1];return n!==void 0&&nn(n,t)?(n.rows.push(t),e):(e.push({type:/^\s*code:/.test(t.text)?"codeBlock":/^\s*table:/.test(t.text)?"table":"line",rows:[t]}),e)},Te=(e,t)=>{var n;if((n=t.hasTitle)!==null&&n!==void 0?n:!0){let[r,...o]=e;return r===void 0?[]:[{type:"title",rows:[r]},...o.reduce(ve,[])]}return e.reduce(ve,[])};function J(e,t,{userId:n,head:r}){let o=t.flatMap(u=>u.split(
)),s=[...he(e,o,{userId:n})];(e[0].text!==o[0]||!r.persistent)&&s.push({title:o[0]});let i=e.slice(1,6).map(u=>u.text),a=o.slice(1,6);i.join("")!==a.join("")&&s.push({descriptions:a});let[c,p]=rn(o.join(
));return(r.linksLc.length!==c.length||!r.linksLc.every(u=>c.includes(u)))&&s.push({links:c}),r.image!==p&&s.push({image:p}),s}function rn(e){let t=Ee(e),n=Te(t,{hasTitle:!0}).flatMap(i=>{switch(i.type){case"codeBlock":case"title":return[];case"line":case"table":return[we(i)]}}),r=[],o=null,s=i=>{switch(i.type){case"hashTag":r.push(C(i.href));return;case"link":{if(i.pathType!=="relative")return;r.push(C(i.href));return}case"image":case"strongImage":{o??=i.src.endsWith("/thumb/1000")?i.src.replace(/\/thumb\/1000$/,"/raw"):i.src;return}case"strong":case"quote":case"decoration":{for(let a of i.nodes)s(a);return}default:return}};for(let i of on(n))s(i);return[r,o]}function*on(e){for(let t of e)switch(t.type){case"codeBlock":case"title":continue;case"line":for(let n of t.nodes)yield n;continue;case"table":{for(let n of t.cells)for(let r of n)for(let o of r)yield o;continue}}}async function ke(e,t,n){let r=https://scrapbox.io/api/pages/${e}/${R(t)}?followRename=${n?.followRename??!0},o=await fetch(r,n?.sid?{headers:{Cookie:L(n.sid)}}:void 0);if(!o.ok){let i=_(await o.text());if(!i)throw M("UnexpectedError",Unexpected error has occuerd when fetching "${r}");return{ok:!1,value:i}}let s=await o.json();return{ok:!0,value:s}}async function O(e,t){let n=await ke(e,t);if(!n.ok)throw new Error(You have no privilege of editing "/${e}/${t}".);let{commitId:r,persistent:o,image:s,links:i,lines:a,id:c,pin:p}=n.value;return{commitId:r,pageId:c,persistent:o,image:s,linksLc:i.map(u=>C(u)),pin:p,lines:a}}async function Z(e,t,n){return t.length===0?{commitId:n.parentId}:await e("socket.io-request",{method:"commit",data:{kind:"page",...n,changes:t,cursor:null,freeze:!0}})}async function De(e,t,n){let[r,o,s]=await Promise.all([O(e,t),U(e),V()]),i=r,a=await N();try{let{request:c}=P(a);for(let p=0;p<3;p++)try{let u=n(i.lines),y=u instanceof Promise?await u:u,g=J(i.lines,y,{userId:s,head:i});await Z(c,g,{parentId:i.commitId,projectId:o,pageId:i.pageId,userId:s});break}catch{if(p===2)throw Error("Faild to retry pushing.");console.log("Faild to push a commit. Retry after pulling new commits");try{i=await O(e,t)}catch(y){throw y}}}finally{a.disconnect()}}var ee="yyyy-MM-dd",H=e=>${I(e,ee)} 振り返り,sn=(e,t)=>["今日やること"," ","","[/icons/hr.icon]",前回:${H(F(e,1))},"","振り返りの手順[. [/takker/ゆるふわ振り返りページで必ずやる手順] ]","",今日やったこと/takker/${I(e,ee)}," ","","今日やれなかったこと"," ","","明日やること", →${H(T(e,1))},"","",今日のn年前/takker/${I(Y(e,1),ee)} ," ","",#${I(t,"yyyy-MM-dd HH:mm:ss")}];async function Ie(e,{project:t,created:n}){let r=H(e);scrapbox.Project.pages.some(o=>o.exists&&o.title===r)||(n??=e,await De(t,r,()=>[r,...sn(e,n)]))}function te(e,t){d(1,arguments);let n=e||{},r=m(n.start),s=m(n.end).getTime();if(!(r.getTime()<=s))throw new RangeError("Invalid interval");let i=[],a=r;a.setHours(0,0,0,0);let c=t&&"step"in t?Number(t.step):1;if(c<1||isNaN(c))throw new RangeError("options.step` must be a number greater than 1");for(;a.getTime()<=s;)i.push(m(a)),a.setDate(a.getDate()+c),a.setHours(0,0,0,0);return i}function ne(e){return d(1,arguments),m(e).getDay()}var $=7,6,5,4,3,2,1;function re(e,t){d(2,arguments);let n=an(t);return T(m(e),nne(m(e)))}function an(e){if(e===0)return $;{let t=$.slice(-e),n=$.slice(0,$.length-e);return t.concat(n)}}function oe(e){return d(1,arguments),re(m(e),6)}var B=new Date,cn=T(B,1);for(let e of te({start:B,end:oe(cn)}))await Ie(e,{project:scrapbox.Project.name,created:B});X(scrapbox.Project.name,H(B)); 実行用scriptと実装とを分けた
typescriptにした
20:58:40 何故か↑での実行に失敗する?
mod.tsから函数を検索できていない
/june29/june29.iconさんの真似
20:08:27 空リンクの存在をページの存在と誤認識してた
20:06:36 明日のページのタイトルにしてなかった