diff --git a/package.json b/package.json index 3ea3868..8edb16a 100644 --- a/package.json +++ b/package.json @@ -25,8 +25,8 @@ }, "dependencies": { "@logseq/libs": "^0.0.10", + "date-fns": "^2.29.3", "diff-match-patch": "^1.0.5", - "logseq-dateutils": "^0.0.22", "luxon": "^3.0.1", "markdown-escape": "^1.1.0", "mustache": "^4.2.0" diff --git a/src/index.ts b/src/index.ts index a597f0c..e32f36d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,6 @@ import { LSPluginBaseInfo, SettingSchemaDesc, } from '@logseq/libs/dist/LSPlugin' -import { getDateForPage } from 'logseq-dateutils' import { Article, compareHighlightsInFile, @@ -16,6 +15,7 @@ import { PageType, parseDateTime, DATE_FORMAT, + formatDate, } from './util' import { DateTime } from 'luxon' import { render } from 'mustache' @@ -165,7 +165,7 @@ const fetchOmnivore = async (inBackground = false) => { for (const article of articles) { const siteName = article.siteName || siteNameFromUrl(article.originalArticleUrl) - const dateSaved = getDateForPage( + const dateSaved = formatDate( new Date(article.savedAt), preferredDateFormat ) @@ -207,7 +207,7 @@ const fetchOmnivore = async (inBackground = false) => { text: it.quote, labels: it.labels, highlightUrl: `https://omnivore.app/me/${article.slug}#${it.id}`, - dateHighlighted: getDateForPage( + dateHighlighted: formatDate( new Date(it.updatedAt), preferredDateFormat ), diff --git a/src/util.ts b/src/util.ts index abbca0a..31f65bc 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,6 +1,7 @@ import { diff_match_patch } from 'diff-match-patch' import { DateTime } from 'luxon' import escape from 'markdown-escape' +import { format } from 'date-fns' export const DATE_FORMAT_W_OUT_SECONDS = "yyyy-MM-dd'T'HH:mm" export const DATE_FORMAT = `${DATE_FORMAT_W_OUT_SECONDS}:ss` @@ -196,3 +197,7 @@ export const parseDateTime = (str: string): DateTime => { } return DateTime.fromFormat(str, DATE_FORMAT_W_OUT_SECONDS) } + +export const formatDate = (date: Date, preferredDateFormat: string): string => { + return `[[${format(date, preferredDateFormat)}]]` +} diff --git a/yarn.lock b/yarn.lock index e590e1d..96a67bf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1970,6 +1970,11 @@ csstype@3.1.0: resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.0.tgz#4ddcac3718d787cf9df0d1b7d15033925c8f29f2" integrity sha512-uX1KG+x9h5hIJsaKR9xHUeUraxf8IODOwq9JLNPq6BwB04a/xgpq3rcx47l5BZu5zBPlgD342tdke3Hom/nJRA== +date-fns@^2.29.3: + version "2.29.3" + resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.29.3.tgz#27402d2fc67eb442b511b70bbdf98e6411cd68a8" + integrity sha512-dDCnyH2WnnKusqvZZ6+jA1O51Ibt8ZMRNkDZdyAyK4YfbDwa/cEmuztzG5pk6hqlp9aSBPYcjOlktquahGwGeA== + dateformat@^3.0.0: version "3.0.3" resolved "https://registry.npmjs.org/dateformat/-/dateformat-3.0.3.tgz" @@ -3375,11 +3380,6 @@ log-symbols@4.1.0: chalk "^4.1.0" is-unicode-supported "^0.1.0" -logseq-dateutils@^0.0.22: - version "0.0.22" - resolved "https://registry.npmjs.org/logseq-dateutils/-/logseq-dateutils-0.0.22.tgz" - integrity sha512-6cJq2eVQONG2dloNDg+US4j+QYwo0XXzcq5x9m9/pQAmobAwnaN6PD/4iY4sOAkuPzapZBs3FffFFEy+R1f5fA== - loupe@^2.3.1: version "2.3.6" resolved "https://registry.yarnpkg.com/loupe/-/loupe-2.3.6.tgz#76e4af498103c532d1ecc9be102036a21f787b53"