Skip to content

render empty toc if needed #331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 6, 2023
Merged

render empty toc if needed #331

merged 1 commit into from
Dec 6, 2023

Conversation

mbostock
Copy link
Member

@mbostock mbostock commented Dec 6, 2023

Fixes #330.

@mbostock mbostock requested a review from Fil December 6, 2023 06:58
@mbostock mbostock enabled auto-merge (squash) December 6, 2023 07:01
@@ -69,6 +69,10 @@
</ol>
</nav>
<script>{/* redacted init script */}</script>
<aside id="observablehq-toc" data-selector="#observablehq-main h1:not(:first-of-type), #observablehq-main h2:not(h1 + h2)">
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we could set toc: false on all these tests? not so much for this PR but so that all these tests don't depend on the way the toc is rendered in the future?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you want me to add a config file for all the tests? Kinda related to #312. Maybe I can hack the test somehow to make it the default at least for tests. 🤔

Copy link
Contributor

@Fil Fil Dec 6, 2023

Choose a reason for hiding this comment

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

Some tests need it though. We could enumerate them here:

export async function normalizeConfig(spec: any, root: string): Promise<Config> {
-  let {title, pages = await readPages(root), pager = true, toc = true} = spec;
+  let {title, pages = await readPages(root), pager = true, toc = !root.startsWith("test/input/") || root === "test/input/build/config" || root === "test/input/build/subtitle" || … } = spec;

but maybe it's better to do nothing.

Copy link
Member Author

Choose a reason for hiding this comment

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

I wouldn’t want to bake test-specific logic into non-test code, too.

Copy link
Member Author

Choose a reason for hiding this comment

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

In general our method of snapshot testing means widescale changes when the generated HTML changes. I opted out of that for the client init script since it’s minified and impossible to review, but I don’t think we actually need to suppress the TOC output in these test snapshots — it’s truthful to what we want to test here.

Copy link
Contributor

@Fil Fil Dec 6, 2023

Choose a reason for hiding this comment

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

I don't think it's worth the effort to create test-specific configs, but it's good to know that it is a possibility if this gets annoying.

Copy link
Member Author

Choose a reason for hiding this comment

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

(For example, if we change whether the TOC is visible by default, or have some more advanced heuristic to decide whether to show it, it’s nice to see that reflected in the snapshots to reaffirm what is changing.)

@mbostock mbostock merged commit 8bdd4cd into main Dec 6, 2023
@mbostock mbostock deleted the mbostock/empty-toc branch December 6, 2023 15:00
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.

When some pages don’t have the TOC, the central column shifts when navigating between pages
2 participants