-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Move 404 to bottom of templates list #48697
Comments
This adds additional complexity to the code just for the one off example of the 404, eg. sortedTemplates.sort( ( a, b ) => a.slug.localeCompare( b.slug ) ); Has to become something like: const sortedTemplatesAlpha = templates
? [ ...templates.filter( ( t ) => ! /^\d/.test( t.title.rendered ) ) ]
: [];
const sortedTemplatesNumber = templates
? [ ...templates.filter( ( t ) => /^\d/.test( t.title.rendered ) ) ]
: [];
sortedTemplatesAlpha.sort( ( a, b ) =>
a.title.rendered.localeCompare( b.title.rendered )
);
sortedTemplatesNumber.sort( ( a, b ) =>
a.title.rendered.localeCompare( b.title.rendered )
);
const sortedTemplates = [
...sortedTemplatesAlpha,
...sortedTemplatesNumber,
]; or function sortTemplates( a, b ) {
const aStartsWithNumber = /^\d/.test( a.title.rendered );
const bStartsWithNumber = /^\d/.test( b.title.rendered );
if ( aStartsWithNumber && bStartsWithNumber ) {
return a.title.rendered.localeCompare( b.title.rendered );
}
if ( aStartsWithNumber ) {
return 1;
}
if ( bStartsWithNumber ) {
return -1;
}
return a.title.rendered.localeCompare( b.title.rendered );
} There may be a simpler approach that I am overlooking, but given that some users may have templates with numbers in the title that they prefer sorted to the top I don't think it is worth implementing this just for the sake of pushing the 404 template to the bottom of the list. |
@youknowriad the use of Can you see any issues with switching the sort from |
@glendaviesnz no, this should be fine. |
I have added a PR to match the sort order to the visible template names and I suggest we close this issue as I don't think it is worth adding the extra sorting complexity just to make 404 go to the bottom. |
Adding for visibility the discussion on renaming the template titles. This could make changing the code obsolete: #47551 |
Going to close this one. Renaming the templates as suggested in #47551 would be a better approach than adding a more complex sort just for this one edge case. |
#48473 updated template lists to sort by slug/name. This is generally an improvement with the exception of one small detail: the 404 template now appears at the top of the list:
While technically correct, it's a bit strange to see this particular template at the top of the list given its relative importance. Until we get to more comprehensive grouping (#48651) it might be good to force templates with numerical names to appear at the bottom of the list.
The text was updated successfully, but these errors were encountered: