From 9699fd62a1d2e8fc70f55de0459503db4d2cefad Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Sun, 21 Dec 2025 15:48:55 +0300 Subject: [PATCH 1/2] Add relative time component for Markdown --- .gitattributes | 2 + _TODO.md | 4 -- package-lock.json | 7 ++++ package.json | 1 + .../Time/client/__tests__/index.spec.ts | 0 src/components/Time/index.astro | 41 +++++++++++++++++++ src/content/articles/demo/index.mdx | 8 ++++ src/layouts/MarkdownLayout.astro | 3 +- 8 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 src/components/Time/client/__tests__/index.spec.ts create mode 100644 src/components/Time/index.astro diff --git a/.gitattributes b/.gitattributes index 177ef83c2..419f04c70 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,3 @@ test/e2e/__screenshots__/** filter=lfs diff=lfs merge=lfs -text +.github/* linguist-vendored=false +.astro/** linguist-vendored diff --git a/_TODO.md b/_TODO.md index 17fba6b94..23cbe1e1c 100644 --- a/_TODO.md +++ b/_TODO.md @@ -229,10 +229,6 @@ Google Calendar, Apple Calendar, Yahoo Calender, Microsoft 365, Outlook, and T [Relative Time](https://github.com/BryceRussell/astro-github-elements/tree/main/packages/time#readme) -### Display text in a circular layout - -[TextCircle](https://github.com/LoStisWorld/astro-textcircle#astro-textcircle) - ## Markdown ## Code Block and Highlighting diff --git a/package-lock.json b/package-lock.json index 98bd28975..8ba171933 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,6 +18,7 @@ "@astrojs/sitemap": "^3.6.0", "@astrojs/vercel": "^9.0.2", "@axe-core/playwright": "^4.11.0", + "@github/relative-time-element": "^5.0.0", "@glidejs/glide": "^3.7.1", "@googlemaps/extended-component-library": "^0.6.14", "@nanostores/lit": "^0.2.3", @@ -4031,6 +4032,12 @@ "node": ">=6" } }, + "node_modules/@github/relative-time-element": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@github/relative-time-element/-/relative-time-element-5.0.0.tgz", + "integrity": "sha512-L/2r0DNR/rMbmHWcsdmhtOiy2gESoGOhItNFD4zJ3nZfHl79Dx3N18Vfx/pYr2lruMOdk1cJZb4wEumm+Dxm1w==", + "license": "MIT" + }, "node_modules/@glidejs/glide": { "version": "3.7.1", "resolved": "https://registry.npmjs.org/@glidejs/glide/-/glide-3.7.1.tgz", diff --git a/package.json b/package.json index 4a2ee7773..618c42410 100644 --- a/package.json +++ b/package.json @@ -68,6 +68,7 @@ "@astrojs/sitemap": "^3.6.0", "@astrojs/vercel": "^9.0.2", "@axe-core/playwright": "^4.11.0", + "@github/relative-time-element": "^5.0.0", "@glidejs/glide": "^3.7.1", "@googlemaps/extended-component-library": "^0.6.14", "@nanostores/lit": "^0.2.3", diff --git a/src/components/Time/client/__tests__/index.spec.ts b/src/components/Time/client/__tests__/index.spec.ts new file mode 100644 index 000000000..e69de29bb diff --git a/src/components/Time/index.astro b/src/components/Time/index.astro new file mode 100644 index 000000000..a95774d23 --- /dev/null +++ b/src/components/Time/index.astro @@ -0,0 +1,41 @@ +--- +type Common = { + format: 'datetime'|'relative'|'duration'; + tense?: 'auto'|'past'|'future'; + precision?: 'year'|'month'|'day'|'hour'|'minute'|'second'; + threshold?: string; + prefix?: string; + formatStyle?: 'long'|'short'|'narrow'; + second?: 'numeric'|'2-digit'; + minute?: 'numeric'|'2-digit'; + hour?: 'numeric'|'2-digit'; + weekday?: 'short'|'long'|'narrow'; + day?: 'numeric'|'2-digit'; + month?: 'numeric'|'2-digit'|'short'|'long'|'narrow'; + year?: 'numeric'|'2-digit'; + timeZoneName?: 'long'|'short'|'shortOffset'|'longOffset' |'shortGeneric'|'longGeneric'; +} + +export interface Props extends Common { + datetime?: Date | string + now?: boolean +} + +const { now, datetime, formatStyle, timeZoneName, ...attrs } = Astro.props as Props +const resolvedDatetime = datetime ?? (now ? new Date() : undefined) +--- + + + + + + \ No newline at end of file diff --git a/src/content/articles/demo/index.mdx b/src/content/articles/demo/index.mdx index 2525a1fcb..c535ffbe2 100644 --- a/src/content/articles/demo/index.mdx +++ b/src/content/articles/demo/index.mdx @@ -225,6 +225,14 @@ Display customer feedback and testimonials: +### Time Component + +```markdown +Let's go to the disco