diff --git a/MIGRATION.md b/MIGRATION.md index 54a89978..20899d6a 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -124,3 +124,7 @@ - New option `pageSubExtension`. - Changed `extensions` option type to `string[]`. + +## `multilanguage` Plugin + +- Apply the default language to all pages without defined language. diff --git a/plugins/multilanguage.ts b/plugins/multilanguage.ts index c9f31e85..61316166 100644 --- a/plugins/multilanguage.ts +++ b/plugins/multilanguage.ts @@ -1,5 +1,5 @@ import { Page } from "../core/filesystem.ts"; -import { isPlainObject, merge } from "../core/utils.ts"; +import { isPlainObject, log, merge } from "../core/utils.ts"; import { posix } from "../deps/path.ts"; import { getUrl } from "../core/source.ts"; @@ -34,6 +34,22 @@ export default function multilanguage(userOptions?: Partial): Plugin { const { data } = page; const languages = data.lang as string | string[] | undefined; + // If the "lang" variable is not defined, use the default language + if (languages === undefined) { + data.lang = options.defaultLanguage; + return; + } + + // If the "lang" variable is a string, check if it's a valid language + if (typeof languages === "string") { + if (!options.languages.includes(languages)) { + log.warning( + `[multilanguage plugin] The language "${languages}" in the page ${page.sourcePath} is not defined in the "languages" option.`, + ); + } + return; + } + // The "lang" variable of the pages must be an array if (!Array.isArray(languages)) { return;