diff --git a/src/browser/components/group-nav.gts b/src/browser/components/group-nav.gts index ea521fe9..fe3a2c75 100644 --- a/src/browser/components/group-nav.gts +++ b/src/browser/components/group-nav.gts @@ -2,6 +2,7 @@ import Component from '@glimmer/component'; import { service } from '@ember/service'; import { docsManager } from '../services/docs.ts'; +import { HOME_GROUP } from '../utils.ts'; import type RouterService from '@ember/routing/router-service'; @@ -65,8 +66,11 @@ export class GroupNav extends Component<{ get groups() { return this.#docs.availableGroups.map((groupName) => { - if (groupName === 'root') { - return { text: this.homeName, value: '/', href: this.rootURL }; + // The co-located pages are a group, but they live in the root URL + // space rather than under their name, so the link is the app's root + // and `@homeName` names it. + if (groupName === HOME_GROUP) { + return { text: this.homeName, value: HOME_GROUP, href: this.rootURL }; } return { @@ -79,13 +83,11 @@ export class GroupNav extends Component<{ }); } - isActive = (subPath: string) => { - if (subPath === '/') return false; - + isActive = (groupName: string) => { // The group is derived from the URL by the docs service (rootURL-aware), // rather than comparing the group name against currentURL directly // (which always failed: 'Docs' never prefixes '/Docs/...'). - return this.#docs.selectedGroup === subPath; + return this.#docs.selectedGroup === groupName; }; get activeClass() { diff --git a/src/browser/utils.ts b/src/browser/utils.ts index a8690e94..bac6a733 100644 --- a/src/browser/utils.ts +++ b/src/browser/utils.ts @@ -4,6 +4,14 @@ import { getOwner } from '@ember/owner'; import type { Page, PageTree } from '../types.ts'; import type Owner from '@ember/owner'; +/** + * The co-located pages' group (app/templates, src/templates), as the build + * names it (`displayName` in build/plugins/setup.js's `homeSource`). Its + * pages live in the root URL space rather than under the group's name, so + * its nav link is the app's root. + */ +export const HOME_GROUP = 'Home'; + export function isPageTree(x: Page | PageTree): x is PageTree { return 'pages' in x; } diff --git a/test-apps/markdown-only/tests/application-test.ts b/test-apps/markdown-only/tests/application-test.ts index fdaadf5e..a273d165 100644 --- a/test-apps/markdown-only/tests/application-test.ts +++ b/test-apps/markdown-only/tests/application-test.ts @@ -29,28 +29,24 @@ module("All Links", function (hooks) { return new Promise((resolve) => setTimeout(resolve, 250)); }); + // The co-located pages' link is the app root now, rather than `/Home` + // where nothing is served — so the crawl no longer visits `/Home`, and + // the root sends it on to the first group. assert.verifySteps([ - "/Home", "/Docs", "/my-folder-name/bar.md", "/my-folder-name/foo.md", - "/Home", - "/my-folder-name/bar.md", - "/Home", + "/Docs", "/Docs/sub-folder/ember-primitives.md", "/Docs/sub-folder/ember-resources.md", - "/Home", - "/my-folder-name/foo.md", "/Docs", "/my-folder-name/foo.md", "/my-folder-name/bar.md", "/Docs", - "/Home", - "/Home", "/Docs/sub-folder/ember-resources.md", - "/Docs", "/Docs/sub-folder/ember-primitives.md", - "/Home", + "/Docs", + "/Docs", ]); }); }); diff --git a/test-apps/multiple-docs-routes/app/templates/application.gts b/test-apps/multiple-docs-routes/app/templates/application.gts index b8894424..c2052ded 100644 --- a/test-apps/multiple-docs-routes/app/templates/application.gts +++ b/test-apps/multiple-docs-routes/app/templates/application.gts @@ -38,7 +38,7 @@ const SideNav: TOC<{ Element: HTMLElement }> =