Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datetime and TimeSpan shapes should return a <time /> tag optionally #15071

Open
Skrypt opened this issue Jan 11, 2024 · 2 comments
Open

Datetime and TimeSpan shapes should return a <time /> tag optionally #15071

Skrypt opened this issue Jan 11, 2024 · 2 comments
Milestone

Comments

@Skrypt
Copy link
Contributor

Skrypt commented Jan 11, 2024

The Datetime and TimeSpan shapes are currently rendering as strings but in an HTML context we should try to render it wrapped with a <time /> tag.

We should probably allow to use a W3C accepted HTML element to make this easier for everyone. It should use <time /> tag in which we can pass/render a datetime or a timespan. At least make it an option to render as a HTML element or a date text but in the end the first should be used more often.

Examples:

For a Datetime shape

Liquid:

{% assign format = "MMMM dd, yyyy" | t %}
{{ "Posted by" | t }} <a href="#">{{ Model.ContentItem.Owner }}</a> {{ "DateTime" | shape_new: utc: Model.ContentItem.CreatedUtc, format: format | time_tag: "on {0}" | t: format }}

Razor:

var format = @T["MMMM dd, yyyy"];
@T["Posted by"] <a href="#">@Model.ContentItem.Owner</a><datetime utc="@Model.ContentItem.CreatedUtc" format="format" >

Should render optionally as :

Posted by <a href="#">Admin</a><time datetime="2019-04-30">on Tue, Apr 30, 2019</time>

For a timeSpan

Liquid:

{{ "TimeSpan" | shape_new: utc: Model.ContentItem.CreatedUtc }}

Razor:

<timespan utc="@Model.ContentItem.CreatedUtc" >

Should render optionally as :

<time datetime="PT15H10M">15 hours and 10 minutes ago</time>

It should render a <time> tag optionally only and it should be backward compatible with what we currently have. Meaning that by default it should not render a time tag.

@sebastienros
Copy link
Member

Looks complicated just to save writing a tag directly. From your examples I couldn't figure out if these were actual html tags or tag helpers in razor. I would assume people would also be confused.

Or maybe create new shapes that render specific tags, like TimeShape

@sebastienros sebastienros added this to the backlog milestone Feb 8, 2024
@Skrypt
Copy link
Contributor Author

Skrypt commented Feb 8, 2024

Yeah, somehow DateTime and TimeSpan are distinct in C# but maybe it is not in HTML. So a TimeShapes that would render a <time></time> tag but that would take a TimeSpan or DateTime as parameter.

The other idea was to simply add a param to the actual taghelpers and add an alternate render.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants