Add a {time} template helper, reuse timestamp code from Quick Note as a niceTime (#555)
niceTime helper
This commit is contained in:
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() {
|
||||
return {
|
||||
@ -15,6 +15,7 @@ export function handlebarHelpers() {
|
||||
substring: (s: string, from: number, to: number, elipsis = "") =>
|
||||
s.length > to - from ? s.substring(from, to) + elipsis : s,
|
||||
|
||||
time: () => niceTime(new Date()),
|
||||
today: () => niceDate(new Date()),
|
||||
tomorrow: () => {
|
||||
const tomorrow = new Date();
|
||||
|
@ -9,3 +9,10 @@ export function niceDate(d: Date): string {
|
||||
|
||||
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 { extractFrontmatter } from "$sb/lib/frontmatter.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 { cleanPageRef } from "$sb/lib/resolve.ts";
|
||||
import { PageMeta } from "$sb/types.ts";
|
||||
@ -170,9 +170,8 @@ export async function quickNoteCommand() {
|
||||
const { quickNotePrefix } = await readSettings({
|
||||
quickNotePrefix: "📥 ",
|
||||
});
|
||||
const isoDate = new Date().toISOString();
|
||||
let [date, time] = isoDate.split("T");
|
||||
time = time.split(".")[0];
|
||||
const date = niceDate(new Date());
|
||||
const time = niceTime(new Date());
|
||||
const pageName = `${quickNotePrefix}${date} ${time}`;
|
||||
await editor.navigate(pageName);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user