From d936302b49f3b3608b69899596571be8386eca01 Mon Sep 17 00:00:00 2001 From: Daniel Kuznetsov Date: Tue, 17 Sep 2024 22:19:54 +0300 Subject: [PATCH] fix: unconstrain line width when dumping metadata to yaml --- package-lock.json | 2 +- package.json | 2 +- src/services/metadata/parse.ts | 4 ++- .../__snapshots__/include-toc.test.ts.snap | 32 +++++++++---------- .../load-custom-resources.spec.ts.snap | 12 +++---- tests/e2e/__snapshots__/metadata.spec.ts.snap | 24 +++++++------- .../liquidInFrontMatter.test.ts.snap | 32 +++++++++---------- 7 files changed, 54 insertions(+), 54 deletions(-) diff --git a/package-lock.json b/package-lock.json index c1f2a6cf..28633520 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,7 +27,7 @@ "@diplodoc/mermaid-extension": "^1.2.1", "@diplodoc/openapi-extension": "^2.3.2", "@diplodoc/prettier-config": "^2.0.0", - "@diplodoc/transform": "^4.31.1", + "@diplodoc/transform": "^4.31.2", "@diplodoc/tsconfig": "^1.0.2", "@octokit/core": "4.2.4", "@types/async": "^3.2.15", diff --git a/package.json b/package.json index cff12416..48362e32 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "@diplodoc/mermaid-extension": "^1.2.1", "@diplodoc/openapi-extension": "^2.3.2", "@diplodoc/prettier-config": "^2.0.0", - "@diplodoc/transform": "^4.31.1", + "@diplodoc/transform": "^4.31.2", "@diplodoc/tsconfig": "^1.0.2", "@octokit/core": "4.2.4", "@types/async": "^3.2.15", diff --git a/src/services/metadata/parse.ts b/src/services/metadata/parse.ts index 0c90d417..27a64ac0 100644 --- a/src/services/metadata/parse.ts +++ b/src/services/metadata/parse.ts @@ -103,7 +103,9 @@ export const parseExistingMetadata = ( }; export const serializeMetadata = (objectMetadata: FileMetadata) => { - const dumped = unescapeLiquidSubstitutionSyntax(dump(objectMetadata, {forceQuotes: true})); + const dumped = unescapeLiquidSubstitutionSyntax( + dump(objectMetadata, {forceQuotes: true, lineWidth: -1}).trim(), + ); // This empty object check is a bit naive // The other option would be to check if all own fields are `undefined`, diff --git a/tests/e2e/__snapshots__/include-toc.test.ts.snap b/tests/e2e/__snapshots__/include-toc.test.ts.snap index 986277f4..4397cef6 100644 --- a/tests/e2e/__snapshots__/include-toc.test.ts.snap +++ b/tests/e2e/__snapshots__/include-toc.test.ts.snap @@ -4,14 +4,14 @@ exports[`Include toc Nested toc inclusions with mixed including modes 1`] = `"[" exports[`Include toc Nested toc inclusions with mixed including modes 2`] = ` "--- -sourcePath: product1/core/_includes/inc.md +sourcePath: 'product1/core/_includes/inc.md' --- This is the core include." `; exports[`Include toc Nested toc inclusions with mixed including modes 3`] = ` "--- -sourcePath: product1/core/article1.md +sourcePath: 'product1/core/article1.md' --- This is the core content of Article 1. @@ -31,7 +31,7 @@ deepBase: 1 exports[`Include toc Nested toc inclusions with mixed including modes 5`] = ` "--- -sourcePath: product2/core/_includes/inc.md +sourcePath: 'product2/core/_includes/inc.md' --- This is the core include. " @@ -39,7 +39,7 @@ This is the core include. exports[`Include toc Nested toc inclusions with mixed including modes 6`] = ` "--- -sourcePath: product2/overlay1/product/article1.md +sourcePath: 'product2/overlay1/product/article1.md' --- This is the overlay content of Article 1 for product 2. @@ -49,7 +49,7 @@ This is the overlay content of Article 1 for product 2. exports[`Include toc Nested toc inclusions with mixed including modes 7`] = ` "--- -sourcePath: product2/core/_includes/inc.md +sourcePath: 'product2/core/_includes/inc.md' --- This is the core include. " @@ -57,7 +57,7 @@ This is the core include. exports[`Include toc Nested toc inclusions with mixed including modes 8`] = ` "--- -sourcePath: product2/overlay2/product/article1.md +sourcePath: 'product2/overlay2/product/article1.md' --- This is the overlay number #2 of Article 1 content for product 2. @@ -67,7 +67,7 @@ This is the overlay number #2 of Article 1 content for product 2. exports[`Include toc Nested toc inclusions with mixed including modes 9`] = ` "--- -sourcePath: product2/core/_includes/inc.md +sourcePath: 'product2/core/_includes/inc.md' --- This is the core include. " @@ -75,7 +75,7 @@ This is the core include. exports[`Include toc Nested toc inclusions with mixed including modes 10`] = ` "--- -sourcePath: product2/core/article1.md +sourcePath: 'product2/core/article1.md' --- This is the core content of Article 1. @@ -160,9 +160,9 @@ exports[`Include toc Toc is included inline, not as a new section 3`] = ` exports[`Include toc Toc is included inline, not as a new section 4`] = ` "--- -title: File A -description: YFM description -sourcePath: folder/fileA.md +title: 'File A' +description: 'YFM description' +sourcePath: 'folder/fileA.md' --- # File A @@ -176,7 +176,7 @@ Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, wh exports[`Include toc Toc is included inline, not as a new section 5`] = ` "--- -sourcePath: folder/fileB.md +sourcePath: 'folder/fileB.md' --- # File B @@ -192,7 +192,7 @@ Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, wh exports[`Include toc Toc is included inline, not as a new section 6`] = ` "--- -sourcePath: folder/folder/fileC.md +sourcePath: 'folder/folder/fileC.md' --- # File C " @@ -205,8 +205,8 @@ exports[`Include toc Toc is included inline, not as a new section 7`] = ` exports[`Include toc Toc is included inline, not as a new section 8`] = ` "--- -title: File A -description: YFM description +title: 'File A' +description: 'YFM description' --- # File A @@ -233,7 +233,7 @@ Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, wh exports[`Include toc Toc is included inline, not as a new section 10`] = ` "--- -sourcePath: folder/folder/fileC.md +sourcePath: 'folder/folder/fileC.md' --- # File C " diff --git a/tests/e2e/__snapshots__/load-custom-resources.spec.ts.snap b/tests/e2e/__snapshots__/load-custom-resources.spec.ts.snap index 2cd2818b..a1b2e3da 100644 --- a/tests/e2e/__snapshots__/load-custom-resources.spec.ts.snap +++ b/tests/e2e/__snapshots__/load-custom-resources.spec.ts.snap @@ -474,12 +474,12 @@ links: exports[`Allow load custom resources md2md with custom resources 4`] = ` "--- metadata: - - name: yfm - content: builder + - name: 'yfm' + content: 'builder' style: - - _assets/style/test.css + - '_assets/style/test.css' script: - - _assets/script/test1.js + - '_assets/script/test1.js' --- Lorem @@ -489,9 +489,9 @@ Lorem exports[`Allow load custom resources md2md with custom resources 5`] = ` "--- style: - - _assets/style/test.css + - '_assets/style/test.css' script: - - _assets/script/test1.js + - '_assets/script/test1.js' --- Lorem" `; diff --git a/tests/e2e/__snapshots__/metadata.spec.ts.snap b/tests/e2e/__snapshots__/metadata.spec.ts.snap index 22e5d45f..524d985c 100644 --- a/tests/e2e/__snapshots__/metadata.spec.ts.snap +++ b/tests/e2e/__snapshots__/metadata.spec.ts.snap @@ -207,12 +207,12 @@ links: exports[`Allow load custom resources md2md with metadata 3`] = ` "--- metadata: - - name: yfm - content: builder in page - - name: test-yfm - content: inline test - - name: yfm-config - content: config test + - name: 'yfm' + content: 'builder in page' + - name: 'test-yfm' + content: 'inline test' + - name: 'yfm-config' + content: 'config test' --- Lorem" @@ -221,12 +221,12 @@ Lorem" exports[`Allow load custom resources md2md with metadata 4`] = ` "--- metadata: - - name: yfm - value: builder in config - - name: test-yfm - content: inline test - - name: yfm-config - content: config test + - name: 'yfm' + value: 'builder in config' + - name: 'test-yfm' + content: 'inline test' + - name: 'yfm-config' + content: 'config test' --- Lorem" diff --git a/tests/integrations/services/__snapshots__/liquidInFrontMatter.test.ts.snap b/tests/integrations/services/__snapshots__/liquidInFrontMatter.test.ts.snap index db08d0ac..1c678a5c 100644 --- a/tests/integrations/services/__snapshots__/liquidInFrontMatter.test.ts.snap +++ b/tests/integrations/services/__snapshots__/liquidInFrontMatter.test.ts.snap @@ -11,10 +11,10 @@ exports[`Front matter (metadata) transformations do not break when a property ke exports[`Front matter (metadata) transformations do not break when a property key contains Liquid-style variable substitutions 2`] = ` "--- -prop-{{key-name}}: This one has a substitution in a key name. -{{key-name}}-prop: This one's key starts with a substitution. -{{key-name}}: This one's key only consists of a substitution. -{{ key-name }}: This one's key employs a different whitespace style in a substitution. +prop-{{key-name}}: 'This one has a substitution in a key name.' +{{key-name}}-prop: 'This one''s key starts with a substitution.' +{{key-name}}: 'This one''s key only consists of a substitution.' +{{ key-name }}: 'This one''s key employs a different whitespace style in a substitution.' --- Blah. " @@ -34,15 +34,13 @@ exports[`Front matter (metadata) transformations do not break when a property va exports[`Front matter (metadata) transformations do not break when a property value contains Liquid-style variable substitutions 2`] = ` "--- -prop1: This is a metadata property with a {{substitution}} in it. -prop2: This one contains {{multiple}} {{substitutions}}. -prop3: This one has {{substitutions}} of {{ different }} {{ styles}}. -prop4: >- - This one has a {{substitution}} as well, but the string literal is - single-quoted. -prop5: This one has no quotes at {{all}}. -prop6: {{this}} starts with a substitution. -prop7: {{this}} one is a multiline {{property}}. +prop1: 'This is a metadata property with a {{substitution}} in it.' +prop2: 'This one contains {{multiple}} {{substitutions}}.' +prop3: 'This one has {{substitutions}} of {{ different }} {{ styles}}.' +prop4: 'This one has a {{substitution}} as well, but the string literal is single-quoted.' +prop5: 'This one has no quotes at {{all}}.' +prop6: '{{this}} starts with a substitution.' +prop7: '{{this}} one is a multiline {{property}}.' --- Blah. " @@ -50,10 +48,10 @@ Blah. exports[`Front matter (metadata) transformations emit valid metadata when a variable is substituted with an ampty string 1`] = ` "--- -prop1: -prop2: -prop3: -prop4: +prop1: '' +prop2: '' +prop3: '' +prop4: '' --- " `;