OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.43k stars 2.4k forks source link

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

Open Skrypt opened 10 months ago

Skrypt commented 10 months ago

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 commented 9 months ago

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

Skrypt commented 9 months ago

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.