From 7530a00dca64ed6e584153b354fdf0aa1d5b5208 Mon Sep 17 00:00:00 2001 From: Oscar Otero Date: Sat, 2 Dec 2023 14:05:33 +0100 Subject: [PATCH] updated multilanguage test --- MIGRATION.md | 1 + core/file.ts | 9 +- plugins/multilanguage.ts | 6 +- .../__snapshots__/multilanguage.test.ts.snap | 179 +++++++++++++++++- tests/assets/multilanguage/types/article.md | 8 + .../assets/multilanguage/types/article_gl.md | 8 + tests/assets/multilanguage/types/post.md | 8 + tests/assets/multilanguage/types/post_gl.md | 8 + 8 files changed, 220 insertions(+), 7 deletions(-) create mode 100644 tests/assets/multilanguage/types/article.md create mode 100644 tests/assets/multilanguage/types/article_gl.md create mode 100644 tests/assets/multilanguage/types/post.md create mode 100644 tests/assets/multilanguage/types/post_gl.md diff --git a/MIGRATION.md b/MIGRATION.md index 9e6663e1..cd34bf9d 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -189,6 +189,7 @@ - Apply the default language to all pages without defined language. - Removed the ability to insert translations in the middle of the data object. +- The uniqueness of a page is defined by the combination of id + type. ## `sass` Plugin diff --git a/core/file.ts b/core/file.ts index 9c7d3a3e..4ca63000 100644 --- a/core/file.ts +++ b/core/file.ts @@ -171,7 +171,7 @@ export interface RawData { /** The date creation of the page */ date?: Date | string | number; - /** To configure the render order of a page */ + /** To configure the rendering order of a page */ renderOrder?: number; /** The raw content of a page */ @@ -187,7 +187,7 @@ export interface RawData { mergedKeys?: Record; /** Whether render this page on demand or not */ - ondemand?: boolean; + onDemand?: boolean; // deno-lint-ignore no-explicit-any [index: string]: any; @@ -198,7 +198,10 @@ export interface Data extends RawData { /** The language of the page */ lang?: string; - /** The id of the page (used to join different pages as versions of the same content) */ + /** The type of the page (used to group pages in collections) */ + type?: string; + + /** The id of the page (used to identify a page in a collection) */ id?: string | number; /** List of tags assigned to a page or folder */ diff --git a/plugins/multilanguage.ts b/plugins/multilanguage.ts index 08f8be55..e4437a1c 100644 --- a/plugins/multilanguage.ts +++ b/plugins/multilanguage.ts @@ -112,13 +112,15 @@ export default function multilanguage(userOptions: Options) { } // Create the alternates object if it doesn't exist - const { id } = data; + const { id, type } = data; if (data.alternates || id === undefined) { continue; } const alternates: Data[] = []; - const alternatePages = allPages.filter((page) => page.data.id == id); + const alternatePages = allPages.filter((page) => + page.data.id == id && page.data.type === type + ); options.languages.forEach((lang) => { const page = alternatePages.find((page) => page.data.lang === lang); diff --git a/tests/__snapshots__/multilanguage.test.ts.snap b/tests/__snapshots__/multilanguage.test.ts.snap index 28e3fd75..9f362e2e 100644 --- a/tests/__snapshots__/multilanguage.test.ts.snap +++ b/tests/__snapshots__/multilanguage.test.ts.snap @@ -108,6 +108,11 @@ snapshot[`multilanguage plugin 1`] = ` "/pages/page1_en.md", "/pages/page1_gl.md", "/pagination.page.js", + "/types", + "/types/article.md", + "/types/article_gl.md", + "/types/post.md", + "/types/post_gl.md", ], } `; @@ -408,6 +413,10 @@ snapshot[`multilanguage plugin 3`] = `
  • page-gl
  • +
  • article 1
  • + +
  • post 1
  • + ', data: { alternates: "Array(2)", @@ -437,7 +446,7 @@ snapshot[`multilanguage plugin 3`] = ` "previous", "next", ], - results: "Array(2)", + results: "Array(4)", search: [], tags: "Array(0)", url: "/gl/page-1/", @@ -467,6 +476,8 @@ snapshot[`multilanguage plugin 3`] = `
  • page-en
  • +
  • post 1
  • + ', data: { alternates: "Array(2)", @@ -496,7 +507,7 @@ snapshot[`multilanguage plugin 3`] = ` "previous", "next", ], - results: "Array(3)", + results: "Array(4)", search: [], tags: "Array(0)", url: "/en/page-1/", @@ -508,5 +519,169 @@ snapshot[`multilanguage plugin 3`] = ` remote: undefined, }, }, + { + content: \` + + +

    Questo è l'articolo 1

    +\`, + data: { + alternates: "Array(2)", + basename: "article", + children: "

    Questo è l'articolo 1

    +", + content: "Questo è l'articolo 1 +", + date: [], + id: 1, + lang: "it", + mergedKeys: [ + "tags", + "en", + "fr", + "it", + "gl", + ], + page: [ + "src", + "data", + ], + paginate: "paginate", + search: [], + tags: "Array(0)", + title: "article 1", + type: "article", + url: "/it/types/article/", + }, + src: { + asset: false, + ext: ".md", + path: "/types/article", + remote: undefined, + }, + }, + { + content: ' + + +

    Este é o artigo 1

    +', + data: { + alternates: "Array(2)", + basename: "article_gl", + children: "

    Este é o artigo 1

    +", + content: "Este é o artigo 1 +", + date: [], + id: 1, + lang: "gl", + mergedKeys: [ + "tags", + "en", + "fr", + "it", + "gl", + ], + page: [ + "src", + "data", + ], + paginate: "paginate", + search: [], + tags: "Array(0)", + title: "article 1", + type: "article", + url: "/gl/types/article_gl/", + }, + src: { + asset: false, + ext: ".md", + path: "/types/article_gl", + remote: undefined, + }, + }, + { + content: ' + + +

    This is the post 1

    +', + data: { + alternates: "Array(2)", + basename: "post", + children: "

    This is the post 1

    +", + content: "This is the post 1 +", + date: [], + id: 1, + lang: "en", + mergedKeys: [ + "tags", + "en", + "fr", + "it", + "gl", + ], + page: [ + "src", + "data", + ], + paginate: "paginate", + search: [], + tags: "Array(0)", + title: "post 1", + type: "post", + url: "/en/types/post/", + }, + src: { + asset: false, + ext: ".md", + path: "/types/post", + remote: undefined, + }, + }, + { + content: ' + + +

    Este é o post 1

    +', + data: { + alternates: "Array(2)", + basename: "post_gl", + children: "

    Este é o post 1

    +", + content: "Este é o post 1 +", + date: [], + id: 1, + lang: "gl", + mergedKeys: [ + "tags", + "en", + "fr", + "it", + "gl", + ], + page: [ + "src", + "data", + ], + paginate: "paginate", + search: [], + tags: "Array(0)", + title: "post 1", + type: "post", + url: "/gl/types/post_gl/", + }, + src: { + asset: false, + ext: ".md", + path: "/types/post_gl", + remote: undefined, + }, + }, ] `; diff --git a/tests/assets/multilanguage/types/article.md b/tests/assets/multilanguage/types/article.md new file mode 100644 index 00000000..594c4200 --- /dev/null +++ b/tests/assets/multilanguage/types/article.md @@ -0,0 +1,8 @@ +--- +lang: it +type: article +id: 1 +title: article 1 +--- + +Questo è l'articolo 1 diff --git a/tests/assets/multilanguage/types/article_gl.md b/tests/assets/multilanguage/types/article_gl.md new file mode 100644 index 00000000..04697b8a --- /dev/null +++ b/tests/assets/multilanguage/types/article_gl.md @@ -0,0 +1,8 @@ +--- +lang: gl +type: article +id: 1 +title: article 1 +--- + +Este é o artigo 1 diff --git a/tests/assets/multilanguage/types/post.md b/tests/assets/multilanguage/types/post.md new file mode 100644 index 00000000..dd6c6a51 --- /dev/null +++ b/tests/assets/multilanguage/types/post.md @@ -0,0 +1,8 @@ +--- +lang: en +type: post +id: 1 +title: post 1 +--- + +This is the post 1 diff --git a/tests/assets/multilanguage/types/post_gl.md b/tests/assets/multilanguage/types/post_gl.md new file mode 100644 index 00000000..c411af2c --- /dev/null +++ b/tests/assets/multilanguage/types/post_gl.md @@ -0,0 +1,8 @@ +--- +lang: gl +type: post +id: 1 +title: post 1 +--- + +Este é o post 1