Skip to content

Commit

Permalink
fix: unconstrain line width when dumping metadata to yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
brotheroftux committed Sep 18, 2024
1 parent 2c4a8b3 commit d936302
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 54 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion src/services/metadata/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
32 changes: 16 additions & 16 deletions tests/e2e/__snapshots__/include-toc.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -31,15 +31,15 @@ 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.
"
`;

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.
Expand All @@ -49,15 +49,15 @@ 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.
"
`;

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.
Expand All @@ -67,15 +67,15 @@ 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.
"
`;

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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
"
Expand All @@ -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
Expand All @@ -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
"
Expand Down
12 changes: 6 additions & 6 deletions tests/e2e/__snapshots__/load-custom-resources.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
`;
Expand Down
24 changes: 12 additions & 12 deletions tests/e2e/__snapshots__/metadata.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"
Expand All @@ -34,26 +34,24 @@ 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.
"
`;

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: ''
---
"
`;

0 comments on commit d936302

Please sign in to comment.