Skip to content

fix(title): collapse double separators from empty placeholders - #4

Open
phlppschrr wants to merge 1 commit into
PeterKnightDigital:mainfrom
phlppschrr:fix/double-title-separator-empty-pageNum
Open

fix(title): collapse double separators from empty placeholders#4
phlppschrr wants to merge 1 commit into
PeterKnightDigital:mainfrom
phlppschrr:fix/double-title-separator-empty-pageNum

Conversation

@phlppschrr

Copy link
Copy Markdown

Problem

The module's title-format documentation (config field "Title format") promises that {title}{separator}{pageNum}{separator}{site_name} falls back to Title | Site on the first page. It doesn't: {pageNum} expands to an empty string on page 1, and ___formatTitle() only strips separators at the start/end — so page 1 renders Title | | Site.

No format string can express the documented behavior: any format that yields Title | Page 2 | Site on page 2+ necessarily leaves a double separator on page 1.

Fix

Collapse runs of two+ separators (separated only by whitespace) into a single separator before the existing leading/trailing strip:

$qs = preg_quote($sep, '/');
$out = preg_replace('/' . $qs . '(?:\s*' . $qs . ')+/u', $sep, $out);

A single separator between real values is never touched, so titles containing the separator (History | Overview) are unaffected.

{pageNum} expands to an empty string on page 1, so formats like
{title}{separator}{pageNum}{separator}{site_name} render a double
separator ('Title |  | Site') instead of the documented fallback
'Title | Site'. Collapse runs of two+ separators (whitespace between)
into a single separator before stripping leading/trailing ones.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant