Add a {time} template helper, reuse timestamp code from Quick Note as a niceTime (#555)
niceTime helperpull/561/head
parent
e0b6fbed3e
commit
0e2a802bbd
|
@ -1,4 +1,4 @@
|
||||||
import { niceDate } from "$sb/lib/dates.ts";
|
import { niceDate, niceTime } from "$sb/lib/dates.ts";
|
||||||
|
|
||||||
export function handlebarHelpers() {
|
export function handlebarHelpers() {
|
||||||
return {
|
return {
|
||||||
|
@ -15,6 +15,7 @@ export function handlebarHelpers() {
|
||||||
substring: (s: string, from: number, to: number, elipsis = "") =>
|
substring: (s: string, from: number, to: number, elipsis = "") =>
|
||||||
s.length > to - from ? s.substring(from, to) + elipsis : s,
|
s.length > to - from ? s.substring(from, to) + elipsis : s,
|
||||||
|
|
||||||
|
time: () => niceTime(new Date()),
|
||||||
today: () => niceDate(new Date()),
|
today: () => niceDate(new Date()),
|
||||||
tomorrow: () => {
|
tomorrow: () => {
|
||||||
const tomorrow = new Date();
|
const tomorrow = new Date();
|
||||||
|
|
|
@ -9,3 +9,10 @@ export function niceDate(d: Date): string {
|
||||||
|
|
||||||
return d.getFullYear() + "-" + pad(d.getMonth() + 1) + "-" + pad(d.getDate());
|
return d.getFullYear() + "-" + pad(d.getMonth() + 1) + "-" + pad(d.getDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function niceTime(d: Date): string {
|
||||||
|
const isoDate = d.toISOString();
|
||||||
|
let [date, time] = isoDate.split("T");
|
||||||
|
// hh:mm:ss
|
||||||
|
return time.split(".")[0];
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { editor, handlebars, markdown, space } from "$sb/syscalls.ts";
|
import { editor, handlebars, markdown, space } from "$sb/syscalls.ts";
|
||||||
import { extractFrontmatter } from "$sb/lib/frontmatter.ts";
|
import { extractFrontmatter } from "$sb/lib/frontmatter.ts";
|
||||||
import { renderToText } from "$sb/lib/tree.ts";
|
import { renderToText } from "$sb/lib/tree.ts";
|
||||||
import { niceDate } from "$sb/lib/dates.ts";
|
import { niceDate, niceTime } from "$sb/lib/dates.ts";
|
||||||
import { readSettings } from "$sb/lib/settings_page.ts";
|
import { readSettings } from "$sb/lib/settings_page.ts";
|
||||||
import { cleanPageRef } from "$sb/lib/resolve.ts";
|
import { cleanPageRef } from "$sb/lib/resolve.ts";
|
||||||
import { PageMeta } from "$sb/types.ts";
|
import { PageMeta } from "$sb/types.ts";
|
||||||
|
@ -170,9 +170,8 @@ export async function quickNoteCommand() {
|
||||||
const { quickNotePrefix } = await readSettings({
|
const { quickNotePrefix } = await readSettings({
|
||||||
quickNotePrefix: "📥 ",
|
quickNotePrefix: "📥 ",
|
||||||
});
|
});
|
||||||
const isoDate = new Date().toISOString();
|
const date = niceDate(new Date());
|
||||||
let [date, time] = isoDate.split("T");
|
const time = niceTime(new Date());
|
||||||
time = time.split(".")[0];
|
|
||||||
const pageName = `${quickNotePrefix}${date} ${time}`;
|
const pageName = `${quickNotePrefix}${date} ${time}`;
|
||||||
await editor.navigate(pageName);
|
await editor.navigate(pageName);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue