Skip to content

Commit d028210

Browse files
fix: ordenar Explorer usando prefixo numerico em name
1 parent 3c13866 commit d028210

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

quartz.layout.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { PageLayout, SharedLayout } from "./quartz/cfg"
22
import * as Component from "./quartz/components"
33

4-
// função auxiliar para extrair o prefixo numérico "01-", "02-", etc.
5-
// se não tiver prefixo numérico, volta +∞ (fica depois dos numerados)
4+
// Função auxiliar para extrair o prefixo numérico "01-", "02-", etc.
5+
// Usa `name`, que é o último segmento do slug (ex.: "01-finquant").
66
const getNumericPrefix = (node: any): number => {
7-
const slug: string = node.slug ?? ""
8-
const root = slug.split("/")[0] ?? ""
9-
const match = root.match(/^(\d+)-/)
7+
const key: string = node.name ?? ""
8+
const match = key.match(/^(\d+)-/)
109
return match ? parseInt(match[1], 10) : Number.POSITIVE_INFINITY
1110
}
1211

@@ -52,21 +51,22 @@ export const defaultContentPageLayout: PageLayout = {
5251
const aPrefix = getNumericPrefix(a)
5352
const bPrefix = getNumericPrefix(b)
5453

55-
// 1) pastas vs arquivos (padrão do Quartz: pastas primeiro)
56-
if ((!a.isFolder && !b.isFolder) || (a.isFolder && b.isFolder)) {
57-
// 2) se tiver prefixos numéricos diferentes, usa eles
54+
// Folders x files (padrão do Quartz: pastas primeiro)
55+
if ((!a.file && !b.file) || (a.file && b.file)) {
56+
// Se ambos são da mesma “categoria”, usa o prefixo numérico se existir
5857
if (aPrefix !== bPrefix) {
5958
return aPrefix - bPrefix
6059
}
6160

62-
// 3) se empatar, cai na ordem alfabética (com comparação "natural")
61+
// Empate → ordem alfabética natural
6362
return a.displayName.localeCompare(b.displayName, undefined, {
6463
numeric: true,
6564
sensitivity: "base",
6665
})
6766
}
6867

69-
if (!a.isFolder && b.isFolder) {
68+
// a.file = true significa que é arquivo
69+
if (a.file && !b.file) {
7070
return 1
7171
} else {
7272
return -1
@@ -101,7 +101,7 @@ export const defaultListPageLayout: PageLayout = {
101101
const aPrefix = getNumericPrefix(a)
102102
const bPrefix = getNumericPrefix(b)
103103

104-
if ((!a.isFolder && !b.isFolder) || (a.isFolder && b.isFolder)) {
104+
if ((!a.file && !b.file) || (a.file && b.file)) {
105105
if (aPrefix !== bPrefix) {
106106
return aPrefix - bPrefix
107107
}
@@ -112,7 +112,7 @@ export const defaultListPageLayout: PageLayout = {
112112
})
113113
}
114114

115-
if (!a.isFolder && b.isFolder) {
115+
if (a.file && !b.file) {
116116
return 1
117117
} else {
118118
return -1

0 commit comments

Comments
 (0)