diff --git a/src/client/publication.test.ts b/src/client/publication.test.ts index 5b43634..d67efa0 100644 --- a/src/client/publication.test.ts +++ b/src/client/publication.test.ts @@ -16,8 +16,8 @@ import { getFrontMatter } from './publication' //}) test('Front matter of a simple page', () => { - expect(() => getFrontMatter({}, 'page-1')).not.toThrow() - expect(getFrontMatter({}, 'page-1')).toEqual(dedent` + expect(() => getFrontMatter({}, 'page-1', '')).not.toThrow() + expect(getFrontMatter({}, 'page-1', '')).toEqual(dedent` --- permalink: "/page-1/index.html" \n---\n`) @@ -27,11 +27,12 @@ test('Front matter of a collection page', () => { const settings = { eleventyPageData: 'directus.posts', } - expect(() => getFrontMatter(settings, 'page-1')).not.toThrow() - expect(getFrontMatter(settings, 'page-1')).toEqual(dedent` + expect(() => getFrontMatter(settings, 'page-1', 'collectionTest')).not.toThrow() + expect(getFrontMatter(settings, 'page-1', 'collectionTest')).toEqual(dedent` --- pagination: data: directus.posts + collection: "collectionTest" \n---\n`) }) @@ -42,8 +43,8 @@ test('Permalink', () => { eleventyPageData, eleventyPermalink, } - expect(() => getFrontMatter(settings, 'page-1')).not.toThrow() - expect(getFrontMatter(settings, 'page-1')).toEqual(dedent` + expect(() => getFrontMatter(settings, 'page-1', '')).not.toThrow() + expect(getFrontMatter(settings, 'page-1', '')).toEqual(dedent` --- pagination: data: ${eleventyPageData} @@ -57,11 +58,11 @@ test('With languages', () => { silexLanguagesList: 'fr,en', silexLanguagesDefault: 'en', } - expect(() => getFrontMatter(settings, 'page-1', 'fr')).not.toThrow() - expect(getFrontMatter(settings, 'page-1', 'fr')).toEqual(dedent` + expect(() => getFrontMatter(settings, 'page-1', '', 'fr')).not.toThrow() + expect(getFrontMatter(settings, 'page-1', '', 'fr')).toEqual(dedent` --- pagination: data: directus.posts - lang: fr + lang: "fr" \n---\n`) }) diff --git a/src/client/publication.ts b/src/client/publication.ts index 03a58d3..f4e8d71 100644 --- a/src/client/publication.ts +++ b/src/client/publication.ts @@ -118,7 +118,7 @@ export function getPermalink(settings: Silex11tyPluginWebsiteSettings, slug: str /** * Get the front matter for a given page */ -export function getFrontMatter(settings: Silex11tyPluginWebsiteSettings, slug: string, lang: string = ''): string { +export function getFrontMatter(settings: Silex11tyPluginWebsiteSettings, slug: string, collection, lang = ''): string { const permalink = getPermalink(settings, slug) return dedent`--- ${settings?.eleventyPageData ? `pagination: @@ -127,7 +127,8 @@ export function getFrontMatter(settings: Silex11tyPluginWebsiteSettings, slug: s ${settings.eleventyPageReverse ? 'reverse: true' : ''} ` : ''} ${permalink ? `permalink: "${permalink}"` : ''} - ${lang ? `lang: ${lang}` : ''} + ${lang ? `lang: "${lang}"` : ''} + ${collection ? `collection: "${collection}"` : ''} ${settings?.eleventyNavigationKey ? `eleventyNavigation: key: ${settings.eleventyNavigationKey} ${settings.eleventyNavigationTitle ? `title: ${settings.eleventyNavigationTitle}` : ''} @@ -203,7 +204,7 @@ export function transformFiles(editor: DataSourceEditor, options: EleventyPlugin if(languages && languages.length > 0) { const pages: ClientSideFileWithContent[] = languages.flatMap(lang => { // Change the HTML - const frontMatter = getFrontMatter(settings, slug, lang) + const frontMatter = getFrontMatter(settings, slug, page.getName(), lang) const bodyStates = getBodyStates(page) const pageFile = { type: ClientSideFileType.HTML, @@ -230,7 +231,7 @@ export function transformFiles(editor: DataSourceEditor, options: EleventyPlugin data.files.push(...newPages) } else { // Change the HTML - const frontMatter = getFrontMatter(settings, slug) + const frontMatter = getFrontMatter(settings, slug, page.getName()) const bodyStates = getBodyStates(page) // Update the page before it is published