Skip to content

Commit b685f6b

Browse files
committed
Preserve legacy front matter visibility keys
1 parent f321204 commit b685f6b

4 files changed

Lines changed: 64 additions & 7 deletions

File tree

docs/content.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,12 @@ extra:
141141
- **aliases** — old URLs for this entry. YiiPress writes redirect pages from each alias to the entry permalink, or to `redirect_to` when the entry is itself a redirect. Aliases are site-root paths, must be unique across aliases and generated page permalinks, and are not added to feeds, listings, or sitemap
142142
- **layout** — template layout name (default: collection-specific or `entry`)
143143
- **theme** — theme name for this entry; overrides the site-level default (see [Templates](templates.md))
144+
- **show_title** — set to `false` to suppress the generated entry `<h1>` while retaining the title for metadata and navigation. The legacy `showTitle` key remains supported; `show_title` wins when both are present
144145
- **weight** — integer for custom sorting in non-blog collections (lower = first)
145146
- **language** — language code for multilingual content (e.g., `en`, `ru`)
146147
- **redirect_to** — URL to redirect to; generates a redirect HTML page (with `<meta http-equiv="refresh">`, JS `window.location.replace()`, and `<link rel="canonical">`) instead of rendering content. Redirect entries are excluded from feeds, sitemaps, listings, archives, and taxonomy pages. Root-relative targets such as `/new-url/` are YiiPress site-root paths; when `base_url` includes a deployment path, YiiPress prefixes that path in the generated redirect target. Absolute URLs are emitted unchanged
147148
- **previous**, **next** — per-entry pager overrides. Omit a direction to inherit its link from sidebar navigation when `navigation_pager` is enabled for the collection, set it to `false` to hide that direction, or provide both `text` and `link` for a custom link. Custom links also work when collection navigation paging is disabled. Relative and root-relative internal links and absolute HTTP(S) links are accepted; unsafe URL schemes fail the build. Root-relative links are rendered relative to the output page, so they work when `base_url` contains a deployment subdirectory
148-
- **edit_link** — set to `false` to hide the edit-page action for this entry. When omitted or `true`, the entry inherits the site-wide `edit_page` configuration. This does not affect the report-issue action
149+
- **edit_link** — set to `false` to hide the edit-page action for this entry. When omitted or `true`, the entry inherits the site-wide `edit_page` configuration. The legacy `editLink` key remains supported; `edit_link` wins when both are present. This does not affect the report-issue action
149150
- **last_updated** — set to `true` or `false` to override last-updated output for this entry. When omitted, the entry inherits the site-wide `last_updated` setting. Disabled entries do not read the source modification time
150151
- **extra** — arbitrary key-value pairs accessible in templates
151152

src/Build/EntryRenderer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ private function cacheContext(
126126
?CrossReferenceResolver $crossRefResolver,
127127
?array $navigationPager,
128128
): string {
129+
$lastUpdated = $this->isLastUpdatedEnabled($siteConfig, $entry);
130+
129131
return hash('xxh128', serialize([
130132
'siteConfig' => $siteConfig,
131133
'permalink' => $permalink,
@@ -135,7 +137,7 @@ private function cacheContext(
135137
'crossReferences' => $crossRefResolver?->signature() ?? '',
136138
'related' => $this->relatedIndex?->signature() ?? '',
137139
'translations' => $this->translationIndex?->signature() ?? '',
138-
'lastUpdated' => $lastUpdated = $this->isLastUpdatedEnabled($siteConfig, $entry),
140+
'lastUpdated' => $lastUpdated,
139141
'lastUpdatedMtime' => $lastUpdated ? filemtime($entry->sourceFilePath()) : null,
140142
]));
141143
}

src/Content/Parser/EntryParser.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function parse(string $filePath, string $collectionName, string $language
104104
bodyLength: $result['bodyLength'],
105105
image: (string) ($fields['image'] ?? ''),
106106
translationKey: (string) ($fields['translation_key'] ?? ''),
107-
showTitle: (bool) ($fields['show_title'] ?? true),
107+
showTitle: (bool) ($fields['show_title'] ?? $fields['showTitle'] ?? true),
108108
aliases: isset($fields['aliases']) && is_array($fields['aliases'])
109109
? array_values(array_map(strval(...), $fields['aliases']))
110110
: [],
@@ -120,22 +120,29 @@ public function parse(string $filePath, string $collectionName, string $language
120120
*/
121121
private function parseEditLink(array $fields, string $filePath): ?bool
122122
{
123-
return $this->parseBooleanOverride($fields, 'edit_link', $filePath);
123+
return $this->parseBooleanOverride($fields, 'edit_link', $filePath, 'editLink');
124124
}
125125

126126
/**
127127
* @param array<string, mixed> $fields
128128
*/
129-
private function parseBooleanOverride(array $fields, string $name, string $filePath): ?bool
130-
{
129+
private function parseBooleanOverride(
130+
array $fields,
131+
string $name,
132+
string $filePath,
133+
?string $legacyName = null,
134+
): ?bool {
135+
if (!array_key_exists($name, $fields) && $legacyName !== null && array_key_exists($legacyName, $fields)) {
136+
$fields[$name] = $fields[$legacyName];
137+
}
131138
if (!array_key_exists($name, $fields) || $fields[$name] === null) {
132139
return null;
133140
}
134141
if (!is_bool($fields[$name])) {
135142
throw new InvalidContentConfigException(
136143
"Invalid \"$name\" visibility override in front matter: $filePath",
137144
$filePath,
138-
"Omit \"$name\" to inherit it, or set it to true or false.",
145+
"Omit \"$name\" or set it to null to inherit it, or set it to true or false.",
139146
);
140147
}
141148

tests/Unit/Content/Parser/EntryParserTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,34 @@ public function testEditLinkVisibilityIsInheritedWhenOmitted(): void
122122
}
123123
}
124124

125+
public function testLegacyEditLinkVisibilityRemainsSupported(): void
126+
{
127+
$file = tempnam(sys_get_temp_dir(), 'yiipress-entry-edit-link-legacy-');
128+
file_put_contents($file, "---\ntitle: Generated\neditLink: false\n---\n\nBody.\n");
129+
130+
try {
131+
$entry = $this->parser->parse($file, 'docs');
132+
133+
assertFalse($entry->editLink);
134+
} finally {
135+
unlink($file);
136+
}
137+
}
138+
139+
public function testSnakeCaseEditLinkTakesPrecedenceOverLegacyKey(): void
140+
{
141+
$file = tempnam(sys_get_temp_dir(), 'yiipress-entry-edit-link-precedence-');
142+
file_put_contents($file, "---\ntitle: Generated\neditLink: false\nedit_link: true\n---\n\nBody.\n");
143+
144+
try {
145+
$entry = $this->parser->parse($file, 'docs');
146+
147+
assertTrue($entry->editLink);
148+
} finally {
149+
unlink($file);
150+
}
151+
}
152+
125153
public function testParsesLastUpdatedVisibilityOverride(): void
126154
{
127155
$file = tempnam(sys_get_temp_dir(), 'yiipress-entry-last-updated-');
@@ -345,4 +373,23 @@ public function testParsesTopLevelShowTitle(): void
345373
unlink($filePath);
346374
}
347375
}
376+
377+
public function testLegacyShowTitleRemainsSupportedWithSnakeCasePrecedence(): void
378+
{
379+
$legacyFile = tempnam(sys_get_temp_dir(), 'yiipress-entry-show-title-legacy-');
380+
$precedenceFile = tempnam(sys_get_temp_dir(), 'yiipress-entry-show-title-precedence-');
381+
file_put_contents($legacyFile, "---\ntitle: Legacy\nshowTitle: false\n---\n\nBody.\n");
382+
file_put_contents(
383+
$precedenceFile,
384+
"---\ntitle: Precedence\nshowTitle: false\nshow_title: true\n---\n\nBody.\n",
385+
);
386+
387+
try {
388+
assertFalse($this->parser->parse($legacyFile, 'docs')->showTitle);
389+
assertTrue($this->parser->parse($precedenceFile, 'docs')->showTitle);
390+
} finally {
391+
unlink($legacyFile);
392+
unlink($precedenceFile);
393+
}
394+
}
348395
}

0 commit comments

Comments
 (0)