Skip to content

Commit 9699fd6

Browse files
committed
Add relative time component for Markdown
1 parent 073d12e commit 9699fd6

8 files changed

Lines changed: 61 additions & 5 deletions

File tree

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
test/e2e/__screenshots__/** filter=lfs diff=lfs merge=lfs -text
2+
.github/* linguist-vendored=false
3+
.astro/** linguist-vendored

_TODO.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,6 @@ Google Calendar, Apple Calendar, Yahoo Calender, Microsoft 365, Outlook, and T
229229

230230
[Relative Time](https://github.com/BryceRussell/astro-github-elements/tree/main/packages/time#readme)
231231

232-
### Display text in a circular layout
233-
234-
[TextCircle](https://github.com/LoStisWorld/astro-textcircle#astro-textcircle)
235-
236232
## Markdown
237233

238234
## Code Block and Highlighting

package-lock.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"@astrojs/sitemap": "^3.6.0",
6969
"@astrojs/vercel": "^9.0.2",
7070
"@axe-core/playwright": "^4.11.0",
71+
"@github/relative-time-element": "^5.0.0",
7172
"@glidejs/glide": "^3.7.1",
7273
"@googlemaps/extended-component-library": "^0.6.14",
7374
"@nanostores/lit": "^0.2.3",

src/components/Time/client/__tests__/index.spec.ts

Whitespace-only changes.

src/components/Time/index.astro

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
type Common = {
3+
format: 'datetime'|'relative'|'duration';
4+
tense?: 'auto'|'past'|'future';
5+
precision?: 'year'|'month'|'day'|'hour'|'minute'|'second';
6+
threshold?: string;
7+
prefix?: string;
8+
formatStyle?: 'long'|'short'|'narrow';
9+
second?: 'numeric'|'2-digit';
10+
minute?: 'numeric'|'2-digit';
11+
hour?: 'numeric'|'2-digit';
12+
weekday?: 'short'|'long'|'narrow';
13+
day?: 'numeric'|'2-digit';
14+
month?: 'numeric'|'2-digit'|'short'|'long'|'narrow';
15+
year?: 'numeric'|'2-digit';
16+
timeZoneName?: 'long'|'short'|'shortOffset'|'longOffset' |'shortGeneric'|'longGeneric';
17+
}
18+
19+
export interface Props extends Common {
20+
datetime?: Date | string
21+
now?: boolean
22+
}
23+
24+
const { now, datetime, formatStyle, timeZoneName, ...attrs } = Astro.props as Props
25+
const resolvedDatetime = datetime ?? (now ? new Date() : undefined)
26+
---
27+
28+
<script>
29+
import '@github/relative-time-element'
30+
</script>
31+
32+
<relative-time
33+
datetime={resolvedDatetime instanceof Date ? resolvedDatetime.toISOString() : resolvedDatetime}
34+
{...{
35+
...attrs,
36+
'format-style':formatStyle,
37+
'time-zone-name':timeZoneName,
38+
}}
39+
>
40+
<slot />
41+
</relative-time>

src/content/articles/demo/index.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,14 @@ Display customer feedback and testimonials:
225225

226226
<Testimonials count={3} />
227227

228+
### Time Component
229+
230+
```markdown
231+
Let's go to the disco <Time datetime="2026-01-01T00:00:00.000Z" />.
232+
```
233+
234+
Let's go to the disco <Time datetime="2026-01-01T00:00:00.000Z" />.
235+
228236
## GFM
229237

230238
### Footnote

src/layouts/MarkdownLayout.astro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ import Icon from '@components/Icon/index.astro'
2424
import MastodonModal from '@components/Social/Mastodon/index.astro'
2525
import Newsletter from '@components/CallToAction/Newsletter/index.astro'
2626
import Shares from '@components/Social/Shares/index.astro'
27+
import Time from '@components/Time/index.astro'
2728
import Testimonials from '@components/Testimonials/index.astro'
2829
2930
/** Export components for use in MDX */
30-
const Components = { Avatar, Callout, Carousel, Contact, Embed, Featured, Highlighter, Icon, Image, MastodonModal, Newsletter, Picture, Shares, Testimonials }
31+
const Components = { Avatar, Callout, Carousel, Contact, Embed, Featured, Highlighter, Icon, Image, MastodonModal, Newsletter, Picture, Shares, Testimonials, Time }
3132
3233
export interface Props {
3334
/** Author name */

0 commit comments

Comments
 (0)