Skip to content

fix: use structure.readme as index.html when README.md also exists - #535

Merged
azu merged 1 commit into
honkit:masterfrom
b84330808:fix/structure-readme-index
Oct 21, 2026
Merged

azu merged 1 commit into
honkit:masterfrom
b84330808:fix/structure-readme-index

Conversation

@b84330808

Copy link
Copy Markdown
Contributor

Fixes #287

Summary

When structure.readme points to a different file (e.g. README.other.md) and a README.md page also exists in the same directory (for example because SUMMARY.md still links to it, as the honkit init template does), both pages are written to index.html. Which one ends up there depends on which page is written last, so the result can change between builds, and both sidebar entries link to ./.

The cause is fileToOutput(): it sends every file named README.* to its directory's index.html, in addition to the configured book readme.

Changes

  • fileToOutput() now treats a README.* file as its directory's index only when the book readme doesn't already use that directory's index.html. Otherwise the page is written to README.html like any other page.
  • Default books are unaffected: README.md is the book readme, and sub/README.md still becomes sub/index.html (so the fileToOutput tests in feat: add prettyUrls option for clean directory URLs #499 still hold).
  • Added a website generator test for this case.

Breaking Changes

None for default setups. In the setup above, README.md is now emitted as README.html (and links to it resolve there) instead of overwriting the configured readme's index.html.

The JSON generator has a similar collision on README.json. I left it out of this PR because json/onFinish.ts relies on that file name.

Test Plan

  • The new test in src/output/__tests__/website.ts fails without the change (no README.html is generated) and passes with it, along with the rest of npx jest src in packages/honkit.
  • Built a small book with README.md, README.other.md, book.json ("structure": { "readme": "README.other.md" }) and * [Introduction](README.md) in SUMMARY.md. index.html now always has the README.other.md content and README.html has the README.md content.

I used Claude Code to write this change.

fileToOutput() mapped every file named README to its directory's
index.html, in addition to the configured book readme. When
`structure.readme` points to another file in the same directory and a
README.md page also exists (e.g. it is linked from SUMMARY.md), both
pages were written to the same index.html and whichever was written
last won.

Keep README files as their directory's index only when the book readme
does not already use that directory's index.html. Otherwise the README
page is written to README.html like any other page.

Fixes #287

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

Comment on lines +22 to +26
const isDirectoryReadme =
path.basename(filePath, path.extname(filePath)) == "README" &&
!(fileReadme.exists() && path.dirname(filePath) == path.dirname(fileReadme.getPath()));

if (
path.basename(filePath, path.extname(filePath)) == "README" ||
(fileReadme.exists() && filePath == fileReadme.getPath())
) {
if (isBookReadme || isDirectoryReadme) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Sibling README pages share one output

When a custom introduction shares a directory with README.md and README.markdown, isDirectoryReadme maps both pages to README.html. One article overwrites the other, so both sidebar links open the same content.

Learn more

HonKit generates one HTML file per page in the summary. Both .md and .markdown are supported page extensions (EXTENSIONS_MARKDOWN), and generatePages writes their output concurrently. With a custom introduction in their directory, the new branch sends both sibling README files through fileToOutput to README.html. Both pages remain separate in the summary but share one physical output file.

Example: Set structure.readme to intro.md, and list README.md and README.markdown with different content in SUMMARY.md. Both sidebar links target README.html; only whichever page wrote last is visible.

Recommended fix: Detect output-path collisions among prepared pages and assign distinct paths or reject conflicting source names before writing. Ensure URL generation uses the same mapping, and cover multiple supported README extensions in a website generation test.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two files that only differ in extension (foo.md and foo.markdown) already map to the same .html anywhere in a book, and before this change both READMEs went to index.html together with the custom readme. So this isn't new, and having both README.md and README.markdown in the same folder seems rare enough that I'd keep it out of this PR.

@azu azu added the Type: Bug Bug or Bug fixes label Oct 21, 2026

@azu azu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@azu
azu merged commit 7071708 into honkit:master Oct 21, 2026
17 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 21, 2026
azu added a commit that referenced this pull request Oct 21, 2026
<!-- Release notes generated using configuration in .github/release.yml
at master -->

## What's Changed
### Bug Fixes
* fix: use structure.readme as index.html when README.md also exists by
@b84330808 in #535

## New Contributors
* @b84330808 made their first contribution in
#535

**Full Changelog**:
v6.2.2...v6.2.3

Co-authored-by: azu <[email protected]>
@github-actions github-actions Bot mentioned this pull request Oct 23, 2026
azu added a commit that referenced this pull request Oct 23, 2026
<!-- Release notes generated using configuration in .github/release.yml
at master -->

## What's Changed
### Bug Fixes
* fix: use structure.readme as index.html when README.md also exists by
@b84330808 in #535
### CI
* fix: remove --scripts-prepend-node-path flag for npm 12 by @azu in
#537

## New Contributors
* @b84330808 made their first contribution in
#535

**Full Changelog**:
v6.2.2...v6.2.4

Co-authored-by: azu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug Bug or Bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

structure.readme configuration is ignored when README.md exists

2 participants