Compare commits

..
5 changed files with 61 additions and 32 deletions

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"@jackyzha0/quartz": patch
---
A `locale` that Quartz has no translation for (such as `sv-SE`, `da-DK` or `es-MX`) no longer crashes the build. Quartz uses a translation of the same language (`es-MX` uses `es-ES`), else English, and prints one warning; dates still use the configured locale.
-5
View File
@@ -1,5 +0,0 @@
---
"@jackyzha0/quartz": patch
---
Some fixes in this release change how existing pages look, mostly to match Obsidian: Bases sorting (natural text order, empty values last, mixed types), Bases `not:` filters and `== null`, Bases group headings, canvas edges, and folders with an unlisted `index.md`. See [Upgrading from 5.3.0 to 5.3.1](https://quartz.jzhao.xyz/getting-started/upgrading#upgrading-from-530-to-531).
-26
View File
@@ -28,32 +28,6 @@ npx quartz plugin install --latest
See the [[upgrade|CLI reference for upgrade]] for more details on available flags.
## Upgrading from 5.3.0 to 5.3.1
5.3.1 is a patch release: fixes from a test audit of Quartz and its plugins, many checked against Obsidian. Upgrade as usual:
```bash
npx quartz upgrade
npx quartz plugin install --latest
```
### Changes you may notice
Most of these make a page look the way Obsidian shows it, so an existing site can look different after the upgrade.
- **[[Bases]] sorting**: text sorts naturally ("Chapter 2" before "Chapter 10") and ignores case, also for the default order by file name. Empty values come last in both directions, including descending sorts. A column that mixes types sorts numbers, dates and durations by value and everything else as text. Group order follows the same rules.
- **[[Bases]] filters and formulas**, as in Obsidian:
- `not:` leaves out a note that matches _any_ of its conditions (it left out only notes matching all of them).
- `status == null` matches notes without `status`, and `status != null` no longer keeps them.
- `"5" == 5` and `1 == true` are true, two strings compare as text (`"10" > "9"` is false), and an empty list counts as false.
- A formula can use a formula defined after it. `x / 0` shows ∞. `sum()`, `mean()`, `min()` and `max()` skip text and booleans, and are empty without numbers. `number("abc")` is an error.
- **[[Bases]] group headings** show their value as a cell does: dates in the local format (not an ISO timestamp, sometimes of the previous day), durations as "4 days", links as the note's name, booleans as a checkbox.
- **[[CanvasPage|Canvas]] edges** leave and enter each card through the side they name, with Obsidian's curve, and the arrow points into that side. An edge without sides joins the sides that face each other (it joined the cards' centres).
- **Folder pages**: a folder whose own `index.md` is unlisted shows that note, with the folder listing below it. A generated folder page used to replace it.
- **Tag links under a base path**: inline `#tag` links from notes two or more folders deep stay on the site. On a site served under a sub-path, such as a GitHub Pages project site, they went to `/tags/…` and returned 404.
- **Locales without a translation** (such as `sv-SE`) no longer crash the build: Quartz uses a translation of the same language, else English, and prints a warning. Dates still use your locale.
- **`npx quartz plugin install --latest`** no longer fails because a _disabled_ plugin can't be updated (for example an old `quartz-themes` entry). It prints a warning with the command to remove the entry.
## Upgrading from 5.2 to 5.3
Quartz 5.3 needs **Node.js 22.22 or later**. Then upgrade as usual:
+28
View File
@@ -0,0 +1,28 @@
import test, { describe } from "node:test"
import assert from "node:assert"
import { i18n, resolveTranslationLocale } from "./index"
describe("i18n locale fallback", () => {
test("a locale with a translation uses it, whatever its case", (t) => {
t.mock.method(console, "warn", () => {})
assert.strictEqual(resolveTranslationLocale("de-DE"), "de-DE")
assert.strictEqual(resolveTranslationLocale("de-de"), "de-DE")
assert.strictEqual(resolveTranslationLocale(undefined), "en-US")
})
test("a locale without one uses the same language, else English, and warns once", (t) => {
const warn = t.mock.method(console, "warn", () => {})
assert.strictEqual(resolveTranslationLocale("es-MX"), "es-ES")
assert.strictEqual(resolveTranslationLocale("es-MX"), "es-ES")
assert.strictEqual(resolveTranslationLocale("sv-SE"), "en-US")
assert.strictEqual(resolveTranslationLocale("nb"), "nb-NO")
assert.strictEqual(warn.mock.callCount(), 3)
assert.match(String(warn.mock.calls[0]!.arguments[0]), /no translation for locale "es-MX"/)
})
// used to throw: TRANSLATIONS["sv-SE"] was undefined
test("i18n() of a locale without a translation returns one", (t) => {
t.mock.method(console, "warn", () => {})
assert.strictEqual(i18n("da-DK").pages.error.title, i18n("en-US").pages.error.title)
})
})
+28 -1
View File
@@ -85,6 +85,33 @@ export const TRANSLATIONS = {
} as const
export const defaultTranslation = "en-US"
export const i18n = (locale: ValidLocale): Translation => TRANSLATIONS[locale ?? defaultTranslation]
const warnedLocales = new Set<string>()
/**
* The translation to use for `locale`: its own, else one of the same language (`es-MX` uses
* `es-ES`), else English. A locale without a translation used to crash the build
* (`TRANSLATIONS[locale]` is undefined); dates and numbers still use the configured locale.
*/
export function resolveTranslationLocale(locale: string | undefined): ValidLocale {
if (!locale) return defaultTranslation
const keys = Object.keys(TRANSLATIONS) as ValidLocale[]
const exact = keys.find((key) => key.toLowerCase() === locale.toLowerCase())
if (exact) return exact
const language = locale.split("-")[0]!.toLowerCase()
const chosen =
keys.find((key) => key.split("-")[0]!.toLowerCase() === language) ?? defaultTranslation
if (!warnedLocales.has(locale)) {
warnedLocales.add(locale)
console.warn(
`Quartz has no translation for locale "${locale}"; its text uses ${chosen}. ` +
`Dates still use ${locale}. Translations: https://quartz.jzhao.xyz/features/i18n`,
)
}
return chosen
}
export const i18n = (locale: ValidLocale | string | undefined): Translation =>
TRANSLATIONS[resolveTranslationLocale(locale)]
export type ValidLocale = keyof typeof TRANSLATIONS
export type ValidCallout = keyof CalloutTranslation