From 3d408dfde3f45ccf9cadfe8d1bca534ebe909cae Mon Sep 17 00:00:00 2001 From: Bryan Weber Date: Wed, 22 Jan 2025 11:14:59 -0500 Subject: [PATCH 1/3] typo: fix numberted -> numbered in TOCTreeOptions --- packages/myst-cli/src/init/jupyter-book/toc.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/myst-cli/src/init/jupyter-book/toc.ts b/packages/myst-cli/src/init/jupyter-book/toc.ts index f02ae79f9..499b5b862 100644 --- a/packages/myst-cli/src/init/jupyter-book/toc.ts +++ b/packages/myst-cli/src/init/jupyter-book/toc.ts @@ -10,7 +10,7 @@ const TOCTreeOptions = z caption: z.string(), hidden: z.boolean(), maxdepth: z.number(), - numberted: z.boolean(), + numbered: z.boolean(), reversed: z.boolean(), titlesonly: z.boolean(), }) From 62b7d5d9ec8c35a38f97a0f52a5d70d5d903ac14 Mon Sep 17 00:00:00 2001 From: Bryan Weber Date: Wed, 22 Jan 2025 11:16:18 -0500 Subject: [PATCH 2/3] fix: allow options key in toc with parts In JB 1, including the top-level options key with parts has no effect. However, it doesn't throw an error in JB 1, so we prefer to remove it and warn rather than erroring. --- packages/myst-cli/src/init/jupyter-book/toc.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/myst-cli/src/init/jupyter-book/toc.ts b/packages/myst-cli/src/init/jupyter-book/toc.ts index 499b5b862..8a11810c2 100644 --- a/packages/myst-cli/src/init/jupyter-book/toc.ts +++ b/packages/myst-cli/src/init/jupyter-book/toc.ts @@ -149,6 +149,7 @@ const BookShorthandInnerSubtree: z.ZodType = z.ob const BookHasOuterSubtrees = z.object({ parts: BookOuterSubtree.array(), + options: TOCTreeOptions.optional(), }); const BookHasInnerSubtrees = z.object({ @@ -281,7 +282,7 @@ function convertNoFormat(session: ISession, dir: string, data: z.infer): z.infer { +function convertBookToNoFormat(data: z.infer, session: ISession): z.infer { const convertEntry = (item: z.infer): z.infer => { // Drop subtrees and sections // eslint-disable-next-line prefer-const, @typescript-eslint/no-unused-vars @@ -324,6 +325,12 @@ function convertBookToNoFormat(data: z.infer): z.infer | z.infer, ): z.infer | z.infer => { if ('parts' in item) { + if ('options' in item) { + session.log.warn( + 'The "options" key in your _toc.yml has no effect and will be ignored.' + ) + delete item.options; + } const { parts, ...rest } = item; return { ...rest, subtrees: parts.map(convertOuterSubtree) }; } else { @@ -402,7 +409,7 @@ export function upgradeTOC(session: ISession, data: SphinxExternalTOC): MySTEntr switch (data.format) { case 'jb-book': { - dataNoFormat = convertBookToNoFormat(data); + dataNoFormat = convertBookToNoFormat(data, session); } break; case 'jb-article': From 49001557394286a55d1fca5eff7b112a33a6d111 Mon Sep 17 00:00:00 2001 From: Bryan Weber Date: Wed, 22 Jan 2025 18:42:57 -0500 Subject: [PATCH 3/3] Linting --- packages/myst-cli/src/init/jupyter-book/toc.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/myst-cli/src/init/jupyter-book/toc.ts b/packages/myst-cli/src/init/jupyter-book/toc.ts index 8a11810c2..243e33c98 100644 --- a/packages/myst-cli/src/init/jupyter-book/toc.ts +++ b/packages/myst-cli/src/init/jupyter-book/toc.ts @@ -282,7 +282,10 @@ function convertNoFormat(session: ISession, dir: string, data: z.infer, session: ISession): z.infer { +function convertBookToNoFormat( + data: z.infer, + session: ISession, +): z.infer { const convertEntry = (item: z.infer): z.infer => { // Drop subtrees and sections // eslint-disable-next-line prefer-const, @typescript-eslint/no-unused-vars @@ -326,9 +329,7 @@ function convertBookToNoFormat(data: z.infer, session: ISession) ): z.infer | z.infer => { if ('parts' in item) { if ('options' in item) { - session.log.warn( - 'The "options" key in your _toc.yml has no effect and will be ignored.' - ) + session.log.warn('The "options" key in your _toc.yml has no effect and will be ignored.'); delete item.options; } const { parts, ...rest } = item;