Problem/Motivation
When exporting content with drush content-first:export, the generated Markdown front matter uses nested YAML for structured metadata. For example, metatag values are exported as:
---
meta:
title: My page title
description: Lorem ipsum
---
Tools like Obsidian do not support nested YAML properties in front matter. They only read flat key/value pairs, so the nested structure is either ignored or causes unexpected behaviour.
Proposed resolution
Add a --flatten-properties boolean option to content-first:export. When set, all nested front-matter properties are flattened into a single level using - as the key separator. Any depth of nesting is handled recursively.
Before (drush cf:export):
---
meta:
title: My page title
description: Lorem ipsum
og:
image: /sites/default/files/hero.jpg
---
After (drush cf:export --flatten-properties):
---
meta-title: My page title
meta-description: Lorem ipsum
meta-og-image: /sites/default/files/hero.jpg
---
Implementation
RenderedContent::getMarkdown() gains an optional bool $flattenProperties = FALSE parameter, threaded through to attributesToMarkdown().
A new protected flattenAttributes(array $data, string $prefix, string $separator): array method handles the recursive flattening.
ContentFirstCommands::export() gains the --flatten-properties option and passes the flag to getMarkdown().
Backward compatible: the default value is FALSE, so existing behaviour is unchanged.
New Drush option:
--flatten-properties Flatten nested front-matter properties using a dash
separator. Tools like Obsidian do not support nested
YAML keys, so "meta: {title: foo}" becomes
"meta-title: foo". Applies to all levels of nesting.
API changes
RenderedContent::getMarkdown() accepts a new optional bool $flattenProperties = FALSE parameter. Callers that do not pass the argument are unaffected.
Issue fork content_first-3588713
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
gedur commentedComment #5
gedur commented