From b2830ac9e336bc022bf326c67d253012ef7d5a23 Mon Sep 17 00:00:00 2001 From: Matthieu Bergel Date: Wed, 6 Mar 2024 17:17:36 +0000 Subject: [PATCH 1/2] refactor(baker): allow bake dirs for all gdoc types --- baker/SiteBaker.tsx | 12 ++++-------- .../@ourworldindata/components/src/GdocsUtils.ts | 16 ++++++++++++---- packages/@ourworldindata/components/src/index.ts | 1 + 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/baker/SiteBaker.tsx b/baker/SiteBaker.tsx index 9df491204be..b21f0add55d 100644 --- a/baker/SiteBaker.tsx +++ b/baker/SiteBaker.tsx @@ -51,7 +51,6 @@ import { OwidGdocErrorMessageType, ImageMetadata, OwidGdoc, - OwidGdocType, DATA_INSIGHTS_INDEX_PAGE_SIZE, OwidGdocMinimalPostInterface, excludeUndefined, @@ -104,6 +103,7 @@ import { getVariableOfDatapageIfApplicable, } from "../db/model/Variable.js" import { Knex } from "knex" +import { getBakePath } from "@ourworldindata/components" type PrefetchedAttachments = { linkedDocuments: Record @@ -238,13 +238,9 @@ export class SiteBaker { } // Bake an individual post/page - private async bakeOwidGdoc(post: OwidGdoc) { - const html = renderGdoc(post) - const dir = - post.content.type === OwidGdocType.DataInsight - ? "data-insights/" - : "" - const outPath = path.join(this.bakedSiteDir, `${dir}${post.slug}.html`) + private async bakeOwidGdoc(gdoc: OwidGdoc) { + const html = renderGdoc(gdoc) + const outPath = `${getBakePath(this.bakedSiteDir, gdoc)}.html` await fs.mkdirp(path.dirname(outPath)) await this.stageWrite(outPath, html) } diff --git a/packages/@ourworldindata/components/src/GdocsUtils.ts b/packages/@ourworldindata/components/src/GdocsUtils.ts index 8ac3763ed37..81b199faf25 100644 --- a/packages/@ourworldindata/components/src/GdocsUtils.ts +++ b/packages/@ourworldindata/components/src/GdocsUtils.ts @@ -45,13 +45,13 @@ export function convertHeadingTextToId(headingText: Span[]): string { return urlSlug(spansToUnformattedPlainText(headingText)) } -export function getCanonicalUrl(baseUrl: string, gdoc: OwidGdoc): string { +function _getPrefixedPath(prefix: string, gdoc: OwidGdoc): string { return match(gdoc) .with( { content: { type: OwidGdocType.Homepage }, }, - () => baseUrl + () => prefix ) .with( { @@ -64,13 +64,13 @@ export function getCanonicalUrl(baseUrl: string, gdoc: OwidGdoc): string { ), }, }, - () => `${baseUrl}/${gdoc.slug}` + () => `${prefix}/${gdoc.slug}` ) .with( { content: { type: OwidGdocType.DataInsight }, }, - () => `${baseUrl}/data-insights/${gdoc.slug}` + () => `${prefix}/data-insights/${gdoc.slug}` ) .with( { @@ -81,6 +81,14 @@ export function getCanonicalUrl(baseUrl: string, gdoc: OwidGdoc): string { .exhaustive() } +export const getBakePath = (bakedSiteDir: string, gdoc: OwidGdoc): string => { + return _getPrefixedPath(bakedSiteDir, gdoc) +} + +export const getCanonicalUrl = (baseUrl: string, gdoc: OwidGdoc): string => { + return _getPrefixedPath(baseUrl, gdoc) +} + export function getPageTitle(gdoc: OwidGdoc) { return match(gdoc) .with( diff --git a/packages/@ourworldindata/components/src/index.ts b/packages/@ourworldindata/components/src/index.ts index a83038eaceb..fc95473f911 100644 --- a/packages/@ourworldindata/components/src/index.ts +++ b/packages/@ourworldindata/components/src/index.ts @@ -14,6 +14,7 @@ export { getUrlTarget, checkIsInternalLink, convertHeadingTextToId, + getBakePath, getCanonicalUrl, getPageTitle, } from "./GdocsUtils.js" From 65a4b83696435e8821ceb22a7a5ea4aa30c591ac Mon Sep 17 00:00:00 2001 From: Matthieu Bergel Date: Wed, 6 Mar 2024 14:05:17 +0000 Subject: [PATCH 2/2] fix(r&w): tablet styles for first featured article --- site/gdocs/components/ResearchAndWriting.scss | 20 ++++++++++++++ site/gdocs/components/ResearchAndWriting.tsx | 27 ++++++++----------- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/site/gdocs/components/ResearchAndWriting.scss b/site/gdocs/components/ResearchAndWriting.scss index 412d2787058..a9603f7c77f 100644 --- a/site/gdocs/components/ResearchAndWriting.scss +++ b/site/gdocs/components/ResearchAndWriting.scss @@ -68,16 +68,36 @@ $rw-margin-bottom-grid-cell: 4px; } .research-and-writing-link__title { + @include h3-bold; margin-top: 0; margin-bottom: $rw-margin-bottom-grid-cell; } +.research-and-writing-link__title--large { + @include md-up { + @include h2-bold; + // Resetting the margins to the base style, as they are overridden by the mixin + margin-top: 0; + margin-bottom: $rw-margin-bottom-grid-cell; + } +} + .research-and-writing-link__description { + @include body-3-medium; color: $blue-90; margin-bottom: $rw-margin-bottom-grid-cell; margin-top: 0; } +.research-and-writing-link__description--large { + @include md-up { + @include body-2-regular; + // Resetting the margins to the base style, as they are overridden by the mixin + margin-bottom: $rw-margin-bottom-grid-cell; + margin-top: 0; + } +} + .research-and-writing-link__authors { color: $blue-60; margin-bottom: $rw-margin-bottom-grid-cell; diff --git a/site/gdocs/components/ResearchAndWriting.tsx b/site/gdocs/components/ResearchAndWriting.tsx index a288b5a5831..e09d850d16d 100644 --- a/site/gdocs/components/ResearchAndWriting.tsx +++ b/site/gdocs/components/ResearchAndWriting.tsx @@ -49,17 +49,6 @@ function ResearchAndWritingLink( filename = linkedDocument["featured-image"] || filename } - const heading = React.createElement( - isSmall ? "h3" : "h2", - { - className: cx( - "research-and-writing-link__title", - isSmall ? "h3-bold" : "h2-bold" - ), - }, - title - ) - return ( ) : null} - {heading} +

+ {title} +

{subtitle && !shouldHideSubtitle ? (

{subtitle}