From a0784ed5d20a397b2a33fd3ee67f3cb31a6006a1 Mon Sep 17 00:00:00 2001 From: Ike Saunders Date: Fri, 27 Oct 2023 21:48:19 +0000 Subject: [PATCH 01/17] =?UTF-8?q?=F0=9F=8E=89=20add=20sidebar=20toc=20for?= =?UTF-8?q?=20gdocs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adminSiteClient/gdocsDeploy.ts | 1 + db/model/Gdoc/archieToEnriched.ts | 5 ++- .../@ourworldindata/utils/src/owidTypes.ts | 1 + site/css/grid.scss | 1 + site/gdocs/OwidGdoc.tsx | 8 ++++ site/gdocs/centered-article.scss | 40 +++++++++++++++++++ 6 files changed, 54 insertions(+), 2 deletions(-) diff --git a/adminSiteClient/gdocsDeploy.ts b/adminSiteClient/gdocsDeploy.ts index 990703d748a..5c21b68e21e 100644 --- a/adminSiteClient/gdocsDeploy.ts +++ b/adminSiteClient/gdocsDeploy.ts @@ -60,6 +60,7 @@ export const checkIsLightningUpdate = ( "cover-color": true, "cover-image": true, "hide-citation": true, + "sidebar-toc": true, body: true, dateline: true, details: true, diff --git a/db/model/Gdoc/archieToEnriched.ts b/db/model/Gdoc/archieToEnriched.ts index e9cd4ce04c4..009aecfcfe6 100644 --- a/db/model/Gdoc/archieToEnriched.ts +++ b/db/model/Gdoc/archieToEnriched.ts @@ -131,8 +131,9 @@ function generateToc( if (child.type === "heading") { const { level, text, supertitle } = child const titleString = spansToSimpleString(text) - const supertitleString = - supertitle && spansToSimpleString(supertitle) + const supertitleString = supertitle + ? spansToSimpleString(supertitle) + : "" if (titleString && (level === 2 || level === 3)) { toc.push({ title: titleString, diff --git a/packages/@ourworldindata/utils/src/owidTypes.ts b/packages/@ourworldindata/utils/src/owidTypes.ts index ffc0dc249c1..32feba1f6cc 100644 --- a/packages/@ourworldindata/utils/src/owidTypes.ts +++ b/packages/@ourworldindata/utils/src/owidTypes.ts @@ -1414,6 +1414,7 @@ export interface OwidGdocContent { "featured-image"?: string "atom-title"?: string "atom-excerpt"?: string + "sidebar-toc"?: boolean "cover-color"?: | "sdg-color-1" | "sdg-color-2" diff --git a/site/css/grid.scss b/site/css/grid.scss index 98c90e484c6..a8227b71ced 100644 --- a/site/css/grid.scss +++ b/site/css/grid.scss @@ -56,6 +56,7 @@ $grid-responsive: (lg, md, sm); gap: 0 var(--grid-gap); grid-template-columns: repeat(12, 1fr); grid-auto-rows: min-content; + align-items: start; } // Use this when you want a full-page-width grid container diff --git a/site/gdocs/OwidGdoc.tsx b/site/gdocs/OwidGdoc.tsx index 8687373f8ad..4f7e51cfd02 100644 --- a/site/gdocs/OwidGdoc.tsx +++ b/site/gdocs/OwidGdoc.tsx @@ -21,6 +21,7 @@ import { DebugProvider } from "./DebugContext.js" import { OwidGdocHeader } from "./OwidGdocHeader.js" import StickyNav from "../blocks/StickyNav.js" import { getShortPageCitation } from "./utils.js" +import { TableOfContents } from "../TableOfContents.js" export const AttachmentsContext = createContext<{ linkedCharts: Record linkedDocuments: Record @@ -70,6 +71,7 @@ export function OwidGdoc({ publishedAt ) const citationText = `${shortPageCitation} Published online at OurWorldInData.org. Retrieved from: '${`${BAKED_BASE_URL}/${slug}`}' [Online Resource]` + const hasSidebarToc = content["sidebar-toc"] const bibtex = `@article{owid-${slug.replace(/\//g, "-")}, author = {${formatAuthors({ @@ -119,6 +121,12 @@ export function OwidGdoc({ publishedAt={publishedAt} breadcrumbs={breadcrumbs ?? undefined} /> + {hasSidebarToc && content.toc ? ( + + ) : null} {content.type === "topic-page" && stickyNavLinks?.length ? (