Skip to content

Commit 55777fa

Browse files
committed
Listings Allow ‘sort: false’ to disable sorting
fixes #3296
1 parent 8d22642 commit 55777fa

File tree

7 files changed

+68
-34
lines changed

7 files changed

+68
-34
lines changed

news/changelog-1.3.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
- Improve support for `date-modified` in listings
7272
- Improve support for `yml` based listings by supporting usage of title and description from `yml`.
7373
- Allow listings in project to point directly to non-input files (such as `yml` files) to use for contents.
74+
- Allow `sort: false` to disable any sorting, allowing items to appear in their original / natural order. (#3296)
7475

7576
## Websites
7677

src/project/types/website/listing/website-listing-read.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -990,17 +990,27 @@ function computeListingSort(rawValue: unknown): ListingSort[] | undefined {
990990
}
991991
};
992992

993-
if (Array.isArray(rawValue)) {
994-
return rawValue.map(parseValue).filter((val) =>
995-
val !== undefined
996-
) as ListingSort[];
993+
if (typeof (rawValue) === "boolean") {
994+
if (rawValue) {
995+
// Apply default sorting behavior
996+
return undefined;
997+
} else {
998+
// Don't apply sorting
999+
return [];
1000+
}
9971001
} else {
998-
const sort = parseValue(rawValue);
999-
if (sort) {
1000-
return [sort];
1002+
// Apply sorting
1003+
if (Array.isArray(rawValue)) {
1004+
return rawValue.map(parseValue).filter((val) =>
1005+
val !== undefined
1006+
) as ListingSort[];
1007+
} else {
1008+
const sort = parseValue(rawValue);
1009+
if (sort) {
1010+
return [sort];
1011+
}
10011012
}
10021013
}
1003-
return undefined;
10041014
}
10051015

10061016
function defaultFields(type: ListingType, itemFields: string[]) {

src/resources/editor/tools/vs-code.mjs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9941,10 +9941,15 @@ var require_yaml_intelligence_resources = __commonJS({
99419941
description: "The files or path globs of Quarto documents or YAML files that should be included in the listing."
99429942
},
99439943
sort: {
9944-
maybeArrayOf: "string",
9944+
anyOf: [
9945+
"boolean",
9946+
{
9947+
maybeArrayOf: "string"
9948+
}
9949+
],
99459950
description: {
99469951
short: "Sort items in the listing by these fields.",
9947-
long: "Sort items in the listing by these fields. The sort key is made up of a \nfield name followed by a direction `asc` or `desc`.\n\nFor example:\n`date asc`\n"
9952+
long: "Sort items in the listing by these fields. The sort key is made up of a \nfield name followed by a direction `asc` or `desc`.\n\nFor example:\n`date asc`\n\nUse `sort:false` to use the unsorted original order of items.\n"
99489953
}
99499954
},
99509955
"max-items": {
@@ -19666,6 +19671,7 @@ var require_yaml_intelligence_resources = __commonJS({
1966619671
"The path to the locally referenced notebook.",
1966719672
"The title of the notebook when viewed.",
1966819673
"The url to use when viewing this notebook.",
19674+
"The style of document to render. Setting this to\n<code>notebook</code> will create additional notebook style\naffordances.",
1966919675
"Automatically generate the contents of a page from a list of Quarto\ndocuments or other custom data.",
1967019676
"Mermaid diagram options",
1967119677
"The mermaid built-in theme to use.",
@@ -20665,8 +20671,7 @@ var require_yaml_intelligence_resources = __commonJS({
2066520671
long: "Title of the volume of the item or container holding the item.\nAlso use for titles of periodical special issues, special sections,\nand the like."
2066620672
},
2066720673
"Disambiguating year suffix in author-date styles (e.g.&nbsp;\u201Ca\u201D in \u201CDoe,\n1999a\u201D).",
20668-
"internal-schema-hack",
20669-
"The style of document to render. Setting this to\n<code>notebook</code> will create additional notebook style\naffordances."
20674+
"internal-schema-hack"
2067020675
],
2067120676
"schema/external-schemas.yml": [
2067220677
{
@@ -20880,12 +20885,12 @@ var require_yaml_intelligence_resources = __commonJS({
2088020885
mermaid: "%%"
2088120886
},
2088220887
"handlers/mermaid/schema.yml": {
20883-
_internalId: 146672,
20888+
_internalId: 146876,
2088420889
type: "object",
2088520890
description: "be an object",
2088620891
properties: {
2088720892
"mermaid-format": {
20888-
_internalId: 146664,
20893+
_internalId: 146868,
2088920894
type: "enum",
2089020895
enum: [
2089120896
"png",
@@ -20901,7 +20906,7 @@ var require_yaml_intelligence_resources = __commonJS({
2090120906
exhaustiveCompletions: true
2090220907
},
2090320908
theme: {
20904-
_internalId: 146671,
20909+
_internalId: 146875,
2090520910
type: "anyOf",
2090620911
anyOf: [
2090720912
{

src/resources/editor/tools/yaml/web-worker.js

Lines changed: 12 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/resources/editor/tools/yaml/yaml-intelligence-resources.json

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2917,10 +2917,15 @@
29172917
"description": "The files or path globs of Quarto documents or YAML files that should be included in the listing."
29182918
},
29192919
"sort": {
2920-
"maybeArrayOf": "string",
2920+
"anyOf": [
2921+
"boolean",
2922+
{
2923+
"maybeArrayOf": "string"
2924+
}
2925+
],
29212926
"description": {
29222927
"short": "Sort items in the listing by these fields.",
2923-
"long": "Sort items in the listing by these fields. The sort key is made up of a \nfield name followed by a direction `asc` or `desc`.\n\nFor example:\n`date asc`\n"
2928+
"long": "Sort items in the listing by these fields. The sort key is made up of a \nfield name followed by a direction `asc` or `desc`.\n\nFor example:\n`date asc`\n\nUse `sort:false` to use the unsorted original order of items.\n"
29242929
}
29252930
},
29262931
"max-items": {
@@ -12642,6 +12647,7 @@
1264212647
"The path to the locally referenced notebook.",
1264312648
"The title of the notebook when viewed.",
1264412649
"The url to use when viewing this notebook.",
12650+
"The style of document to render. Setting this to\n<code>notebook</code> will create additional notebook style\naffordances.",
1264512651
"Automatically generate the contents of a page from a list of Quarto\ndocuments or other custom data.",
1264612652
"Mermaid diagram options",
1264712653
"The mermaid built-in theme to use.",
@@ -13641,8 +13647,7 @@
1364113647
"long": "Title of the volume of the item or container holding the item.\nAlso use for titles of periodical special issues, special sections,\nand the like."
1364213648
},
1364313649
"Disambiguating year suffix in author-date styles (e.g.&nbsp;“a” in “Doe,\n1999a”).",
13644-
"internal-schema-hack",
13645-
"The style of document to render. Setting this to\n<code>notebook</code> will create additional notebook style\naffordances."
13650+
"internal-schema-hack"
1364613651
],
1364713652
"schema/external-schemas.yml": [
1364813653
{
@@ -13856,12 +13861,12 @@
1385613861
"mermaid": "%%"
1385713862
},
1385813863
"handlers/mermaid/schema.yml": {
13859-
"_internalId": 146672,
13864+
"_internalId": 146876,
1386013865
"type": "object",
1386113866
"description": "be an object",
1386213867
"properties": {
1386313868
"mermaid-format": {
13864-
"_internalId": 146664,
13869+
"_internalId": 146868,
1386513870
"type": "enum",
1386613871
"enum": [
1386713872
"png",
@@ -13877,7 +13882,7 @@
1387713882
"exhaustiveCompletions": true
1387813883
},
1387913884
"theme": {
13880-
"_internalId": 146671,
13885+
"_internalId": 146875,
1388113886
"type": "anyOf",
1388213887
"anyOf": [
1388313888
{

src/resources/schema/definitions.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,9 @@
12481248
- ref: website-listing-contents-object
12491249
description: "The files or path globs of Quarto documents or YAML files that should be included in the listing."
12501250
sort:
1251-
maybeArrayOf: string
1251+
anyOf:
1252+
- boolean
1253+
- maybeArrayOf: string
12521254
description:
12531255
short: "Sort items in the listing by these fields."
12541256
long: |
@@ -1257,6 +1259,8 @@
12571259
12581260
For example:
12591261
`date asc`
1262+
1263+
Use `sort:false` to use the unsorted original order of items.
12601264
max-items:
12611265
number:
12621266
description: The maximum number of items to include in this listing.

src/resources/types/schema-types.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -808,13 +808,17 @@ place the contents into a `div` with this id. If no such `div` is defined on the
808808
page, a `div` with this id will be created and appended to the end of the page.
809809
810810
In no `id` is provided for a listing, Quarto will synthesize one when rendering the page. */;
811-
sort?: MaybeArrayOf<
812-
string
813-
> /* Sort items in the listing by these fields. The sort key is made up of a
811+
sort?:
812+
| boolean
813+
| MaybeArrayOf<
814+
string
815+
> /* Sort items in the listing by these fields. The sort key is made up of a
814816
field name followed by a direction `asc` or `desc`.
815817
816818
For example:
817-
`date asc` */;
819+
`date asc`
820+
821+
Use `sort:false` to use the unsorted original order of items. */;
818822
type?:
819823
| "default"
820824
| "table"

0 commit comments

Comments
 (0)