Skip to content

Commit a27ce98

Browse files
committed
add shadowRoot and fallback text
1 parent 3ce25db commit a27ce98

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

modules/timeutil/datetime.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func DateTime(format string, datetime any, extraAttrs ...string) template.HTML {
5757
switch format {
5858
case "short", "long": // date only, render using <gitea-locale-date>
5959
attrs = append(attrs, `month="`+format+`"`, `day="numeric"`)
60-
return template.HTML(fmt.Sprintf(`<gitea-locale-date %s date="%s"></gitea-locale-date>`, strings.Join(attrs, " "), datetimeEscaped))
60+
return template.HTML(fmt.Sprintf(`<gitea-locale-date %s date="%s">%s</gitea-locale-date>`, strings.Join(attrs, " "), datetimeEscaped, textEscaped))
6161
case "full": // full date including time
6262
attrs = append(attrs, `format="datetime"`, `month="short"`, `day="numeric"`, `hour="numeric"`, `minute="numeric"`, `second="numeric"`)
6363
return template.HTML(fmt.Sprintf(`<relative-time %s datetime="%s">%s</relative-time>`, strings.Join(attrs, " "), datetimeEscaped, textEscaped))

web_src/js/webcomponents/GiteaLocaleDate.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ window.customElements.define('gitea-locale-date', class extends HTMLElement {
1616
// Ref: https://stackoverflow.com/a/14569783/808699
1717
const correctedDate = new Date(date.getTime() - date.getTimezoneOffset() * -60000);
1818

19-
this.textContent = correctedDate.toLocaleString(lang ?? [], {
19+
if (!this.shadowRoot) this.attachShadow({mode: 'open'});
20+
this.shadowRoot.textContent = correctedDate.toLocaleString(lang ?? [], {
2021
...(year && {year}),
2122
...(month && {month}),
2223
...(weekday && {weekday}),

0 commit comments

Comments
 (0)