Skip to content

Commit

Permalink
fix: quickcapture params issue #38
Browse files Browse the repository at this point in the history
Signed-off-by: EINDEX <[email protected]>
  • Loading branch information
EINDEX committed Aug 29, 2023
1 parent 9553bdc commit 2a5f74d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/pages/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,13 @@ const quickCapture = async (data: string) => {
await getLogseqCopliotConfig();
const now = new Date();
const resp = await logseqClient.getUserConfig();
const journalPage = format(now, resp['preferredDateFormat']);


const block = blockRending({
url: activeTab.url,
title: activeTab.title,
data,
clipNoteTemplate,
preferredDateFormat: journalPage,
preferredDateFormat: resp['preferredDateFormat'],
time: now,
});

Expand All @@ -77,6 +76,7 @@ const quickCapture = async (data: string) => {
const { name: currentPage } = await logseqClient.getCurrentPage();
await logseqClient.appendBlock(currentPage, block);
} else {
const journalPage = format(now, resp['preferredDateFormat']);
await logseqClient.appendBlock(journalPage, block);
}

Expand Down
44 changes: 44 additions & 0 deletions src/pages/background/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,50 @@ describe('renderBlock', () => {
expect(renderBlock).toEqual(`[[${expectDate}]]`);
});

test('should suit all date format in logseq', () => {
const dateFormatMap: Map<string, string> = new Map([
['do MMM yyyy', '20th Aug 2021'],
['do MMMM yyyy', '20th August 2021'],
['MMM do, yyyy', 'Aug 20th, 2021'],
['MMMM do, yyyy', 'August 20th, 2021'],
['E, dd-MM-yyyy', 'Fri, 20-08-2021'],
['E, dd.MM.yyyy', 'Fri, 20.08.2021'],
['E, MM/dd/yyyy', 'Fri, 08/20/2021'],
['E, yyyy/MM/dd', 'Fri, 2021/08/20'],
['EEE, dd-MM-yyyy', 'Fri, 20-08-2021'],
['EEE, dd.MM.yyyy', 'Fri, 20.08.2021'],
['EEE, MM/dd/yyyy', 'Fri, 08/20/2021'],
['EEE, yyyy/MM/dd', 'Fri, 2021/08/20'],
['EEEE, dd-MM-yyyy', 'Friday, 20-08-2021'],
['EEEE, dd.MM.yyyy', 'Friday, 20.08.2021'],
['EEEE, MM/dd/yyyy', 'Friday, 08/20/2021'],
['EEEE, yyyy/MM/dd', 'Friday, 2021/08/20'],
['dd-MM-yyyy', '20-08-2021'],
['MM/dd/yyyy', '08/20/2021'],
['MM-dd-yyyy', '08-20-2021'],
['MM_dd_yyyy', '08_20_2021'],
['yyyy/MM/dd', '2021/08/20'],
['yyyy-MM-dd', '2021-08-20'],
['yyyy-MM-dd EEEE', '2021-08-20 Friday'],
['yyyy_MM_dd', '2021_08_20'],
['yyyyMMdd', '20210820'],
['yyyy年MM月dd日', '2021年08月20日'],
]);

const clipNoteTemplate = '{{date}}';
const time = new Date('2021-08-19T16:30:00+0000');
Array.from(dateFormatMap.keys()).forEach((dateFormat: string) => {
const renderBlock = blockRending({
clipNoteTemplate: clipNoteTemplate,
time: time,
data: '',
preferredDateFormat: dateFormat,
});

expect(renderBlock).toEqual(`${dateFormatMap.get(dateFormat)}`);
});
});

test('should format link as markdown', () => {
const clipNoteTemplate = '[{{title}}]({{url}})';
const time = new Date('2021-08-19T16:31:00+0000');
Expand Down
1 change: 1 addition & 0 deletions src/pages/background/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export function blockRending({
preferredDateFormat: string;
time: Date;
}): string {
console.log(preferredDateFormat);
const render = engine
.parseAndRenderSync(clipNoteTemplate, {
date: format(time, preferredDateFormat),
Expand Down

0 comments on commit 2a5f74d

Please sign in to comment.