Repository navigation
Fix manifest generator dropping handbook hierarchy - #442
Conversation
- Include pages in sub-directories (e.g. version/) when generating the manifest - Preserve existing title, slug, parent and order values instead of overwriting them - Keep existing page order; append new pages and remove deleted ones - Strip CRLF/BOM when reading page titles so Windows checkouts don't add "\r" - Add error handling for invalid JSON and unreadable/unwritable files - Remove unused Mustache_Engine and Utils imports - Fix doubled /handbook/handbook/ links in get-involved.md - Document generator behaviour in CONTRIBUTING.md
added change
…headings ## What Fixes `wp hosting-handbook gen-all` so regenerating the manifest no longer drops the handbook hierarchy. ## Why The generator rebuilt `bin/handbook-manifest.json` from scratch using only top-level `.md` files, so running it (as CONTRIBUTING.md instructs) removed the `version/` pages and every `parent`/`order` value. On Windows checkouts it also added a trailing `\r` to every title. ## Changes - Include pages in sub-directories (e.g. `version/`) - Keep existing `slug`, `parent` and `order` values; titles are still refreshed from each page's `# Heading`, as before - Keep existing page order; append new pages and remove deleted ones - Strip CRLF/BOM when reading titles - Error on invalid manifest JSON, unreadable/unwritable files and duplicate keys - Remove unused `Mustache_Engine` and `WP_CLI\Utils` imports - Use canonical URLs in get-involved.md (the old `/handbook/handbook/` links worked only via redirect) - Document generator behaviour in CONTRIBUTING.md ## Testing - Running the generator on this branch reproduces the committed manifest; titles, slugs and `markdown_source` match the original generator's output - Tested with LF and CRLF checkouts, new/removed pages, a new `version/` page, invalid JSON and duplicate keys - `php -l` passes --- AI Assisted
|
Tested this branch locally (PHP 8.3, generator called through a small harness that stubs
Suggestions, none of them blocking:
AI Assisted: Claude was used to run the tests and draft this review. |
…final newline Default order for new pages, warn on empty titles and new pages, add final newline
This comment was marked as outdated.
This comment was marked as outdated.
Handle JSON encode failure; warn on missing parents and removed pages
mindctrl
left a comment
There was a problem hiding this comment.
Looks good to me.
It would be good to update the PR description to clarify the changes related to JSON error handling, and when it triggers warnings.
- Error on invalid manifest JSON, JSON encoding failures (e.g. invalid UTF-8 in a heading), unreadable/unwritable files and duplicate keys. Previously, an encoding failure overwrote the manifest with an empty file.
- Warn when:
- a page has no `# Heading` (empty title)
- pages are added, listing their slug, parent and order for review
- pages are removed because their files no longer exist
- a page's `parent` is not in the manifest (e.g. a sub-directory without an `index.md`), which would break the import
Also worth noting it will no longer overwrite the manifest file with invalid JSON due to the above changes.
An unreadable bin/handbook-manifest.json was reported as "not valid JSON", which pointed at the wrong cause. Check file_get_contents() for failure and report "Unable to read" instead, and include json_last_error_msg() in the invalid JSON error.
mindctrl
left a comment
There was a problem hiding this comment.
This looks like a good improvement. I tried to break it, and the only thing I found with the current iteration is a small edge case where a folder exists and files are there but the files cannot be read for some reason, so they are removed from the manifest because they "no longer exist". I don't think that's worth addressing here.
Halt with error on unreadable handbook directories
WhatFixes WhyThe generator rebuilt Changes
Testing
|
ekamran
left a comment
There was a problem hiding this comment.
Thanks @sonali195, this is a big improvement. I ran the generator on main and on this branch against the current manifest, plus new, renamed, deleted and moved pages, new folders, CRLF and BOM, bad UTF-8, bad JSON, duplicate keys and unreadable files. Everything matches the description.
One ordering case should be fixed before merge, inline below. Happy to approve once that is in.
List directory index.md first to ensure parent pages precede children
ekamran
left a comment
There was a problem hiding this comment.
Thanks @sonali195. Re-tested the latest push. The index-first change fixes the importer ordering case, including the hand-set parent case, and the current repo output remains byte-identical. The CONTRIBUTING wording now matches the generated slug behavior. I also reran the edge-case battery and cross-PHP checks.
One non-blocking follow-up: a README.md inside a sub-directory would still be picked up as a handbook page, while the root README is ignored. There is no such file today, so I would not block this PR on it.
Approving.
|
Thanks for the thorough review and testing, @Reviewer! That's a great catch on sub-directory README.md files. Since there are none in the repository today and this PR is approved, I'll let this land and open a quick follow-up PR to handle IGNORED_FILES in sub-directories as well |
|
@sonali195 the AI assistance disclosure was removed from the PR description. Could you add that back before we merge? |
|
"Added the AI assistance disclosure back to the PR description. Thanks!" |
What
Fixes
wp hosting-handbook gen-allso regenerating the manifest no longer drops the handbook hierarchy.Why
The generator rebuilt
bin/handbook-manifest.jsonfrom scratch using only top-level.mdfiles, so running it (as CONTRIBUTING.md instructs) removed theversion/pages and everyparent/ordervalue. On Windows checkouts it also added a trailing\rto every title.Changes
version/)slug,parentandordervalues; titles are still refreshed from each page's# Heading, as beforeorderand remove deleted ones# Heading(empty title)parentis not in the manifest (e.g. a sub-directory without anindex.md), which would break the importMustache_EngineandWP_CLI\Utilsimports/handbook/handbook/links worked only via redirect)Testing
slug,parentandordervalues andmarkdown_sourcelinks unchanged; titles match the original generator's output (without the\r)version/page, invalid JSON and duplicate keysphp -lpassesAI Assistance Disclosure
AI assistance was used in the preparation of this pull request. All changes, code, and documentation were manually reviewed, verified, and tested.