Skip to content

Commit

Permalink
add shadowRoot and fallback text
Browse files Browse the repository at this point in the history
  • Loading branch information
silverwind committed Mar 11, 2024
1 parent 3ce25db commit a27ce98
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion modules/timeutil/datetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func DateTime(format string, datetime any, extraAttrs ...string) template.HTML {
switch format {
case "short", "long": // date only, render using <gitea-locale-date>
attrs = append(attrs, `month="`+format+`"`, `day="numeric"`)
return template.HTML(fmt.Sprintf(`<gitea-locale-date %s date="%s"></gitea-locale-date>`, strings.Join(attrs, " "), datetimeEscaped))
return template.HTML(fmt.Sprintf(`<gitea-locale-date %s date="%s">%s</gitea-locale-date>`, strings.Join(attrs, " "), datetimeEscaped, textEscaped))
case "full": // full date including time
attrs = append(attrs, `format="datetime"`, `month="short"`, `day="numeric"`, `hour="numeric"`, `minute="numeric"`, `second="numeric"`)
return template.HTML(fmt.Sprintf(`<relative-time %s datetime="%s">%s</relative-time>`, strings.Join(attrs, " "), datetimeEscaped, textEscaped))
Expand Down
3 changes: 2 additions & 1 deletion web_src/js/webcomponents/GiteaLocaleDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ window.customElements.define('gitea-locale-date', class extends HTMLElement {
// Ref: https://stackoverflow.com/a/14569783/808699
const correctedDate = new Date(date.getTime() - date.getTimezoneOffset() * -60000);

this.textContent = correctedDate.toLocaleString(lang ?? [], {
if (!this.shadowRoot) this.attachShadow({mode: 'open'});
this.shadowRoot.textContent = correctedDate.toLocaleString(lang ?? [], {
...(year && {year}),
...(month && {month}),
...(weekday && {weekday}),
Expand Down

0 comments on commit a27ce98

Please sign in to comment.