Skip to content
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

🚧 staging environment - entry emulator #2828

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
124ccea
🎉 gdocs tables preliminary types and parsing
ikesau Oct 19, 2023
873abfc
🎉 gdocs table rendering
ikesau Oct 23, 2023
bf37712
✅ fix tests
ikesau Oct 23, 2023
8bcc792
🎉 restore Table.tsx component
ikesau Oct 23, 2023
0259578
🐛 fix list parsing
ikesau Oct 23, 2023
6daba26
🔨 remove console.log
ikesau Oct 23, 2023
fd08749
🎉 add sidebar toc for gdocs
ikesau Oct 27, 2023
cadacf5
🎉 support dateline in topic page header
ikesau Oct 27, 2023
c879bdf
✨ reduce gdoc sidebar max-width
ikesau Oct 27, 2023
32b1f63
🔨 disconnect intersection observer
ikesau Oct 27, 2023
c552de9
✨ gdocs sidebar mobile width
ikesau Oct 27, 2023
90bff71
✨ set sidebar-toc: true in migrateWpPostsToArchie
ikesau Oct 27, 2023
1ea253c
✨ fork toc logic depending on whether it's for the sidebar or sdg-toc
ikesau Oct 27, 2023
54ef71f
🐛 include sidebar-toc when generating gdoc front-matter
ikesau Oct 27, 2023
e491402
🔨 remove change to .grid class that is no longer necessary
ikesau Oct 27, 2023
96cc09b
✨ gdoc sidebar CSS
ikesau Oct 28, 2023
90d0efe
✨ correct colour for sidebar title
ikesau Oct 28, 2023
cd85188
🐛 partial fix for glitchy sidebar behaviour
ikesau Oct 28, 2023
63ec9c3
Merge branch 'gdocs-table' into entry-emulator-demo
ikesau Oct 28, 2023
dbf7b45
Merge branch 'linear-topic-page-dateline' into entry-emulator-demo
ikesau Oct 28, 2023
f034924
✨ Add sidebar entry for all charts block
ikesau Oct 28, 2023
d4ba7a0
Merge branch 'linear-topic-page-toc' into entry-emulator-demo
ikesau Oct 28, 2023
1b41a96
🐛 increase sidebar toc z index above explorer chrome
ikesau Oct 29, 2023
a1fc87a
Merge branch 'linear-topic-page-toc' into entry-emulator-demo
ikesau Oct 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions adminSiteClient/gdocsDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const checkIsLightningUpdate = (
"cover-color": true,
"cover-image": true,
"hide-citation": true,
"sidebar-toc": true,
body: true,
dateline: true,
details: true,
Expand Down
1 change: 1 addition & 0 deletions baker/SiteBaker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ export class SiteBaker {

// Bake all GDoc posts
async bakeGDocPosts() {
await db.getConnection()
if (!this.bakeSteps.has("gdocPosts")) return
const publishedGdocs = await Gdoc.getPublishedGdocs()

Expand Down
1 change: 1 addition & 0 deletions db/migrateWpPostsToArchieMl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ const migrate = async (): Promise<void> => {
// Provide an empty array to prevent the sticky nav from rendering at all
// Because if it isn't defined, it tries to automatically populate itself
"sticky-nav": isEntry ? [] : undefined,
"sidebar-toc": true,
},
relatedCharts,
published: false,
Expand Down
1 change: 1 addition & 0 deletions db/model/Gdoc/Gdoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ export class Gdoc extends BaseEntity implements OwidGdocInterface {
"simple-text",
"sticky-left",
"sticky-right",
"table",
"text"
),
},
Expand Down
31 changes: 24 additions & 7 deletions db/model/Gdoc/archieToEnriched.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,28 +121,39 @@ function generateStickyNav(
}

function generateToc(
body: OwidEnrichedGdocBlock[]
body: OwidEnrichedGdocBlock[],
// For linear topic pages, we record h1s & h2s
// For the sdg-toc, we record h2s & h3s (as it was developed before we decided to use h1s as our top level heading)
{ primary, secondary }: { primary: number; secondary: number }
): TocHeadingWithTitleSupertitle[] {
const toc: TocHeadingWithTitleSupertitle[] = []

// track h2s and h3s for the SDG table of contents
body.forEach((block) =>
traverseEnrichedBlocks(block, (child) => {
if (child.type === "heading") {
const { level, text, supertitle } = child
const titleString = spansToSimpleString(text)
const supertitleString =
supertitle && spansToSimpleString(supertitle)
if (titleString && (level === 2 || level === 3)) {
const supertitleString = supertitle
? spansToSimpleString(supertitle)
: ""
if (titleString && (level === primary || level === secondary)) {
toc.push({
title: titleString,
supertitle: supertitleString,
text: titleString,
slug: urlSlug(`${supertitleString} ${titleString}`),
isSubheading: level === 3,
isSubheading: level === secondary,
})
}
}
if (child.type === "all-charts") {
toc.push({
title: child.heading,
text: child.heading,
slug: ALL_CHARTS_ID,
isSubheading: false,
})
}
})
)

Expand Down Expand Up @@ -255,7 +266,13 @@ export const archieToEnriched = (text: string): OwidGdocContent => {
// Parse elements of the ArchieML into enrichedBlocks
parsed.body = compact(parsed.body.map(parseRawBlocksToEnrichedBlocks))

parsed.toc = generateToc(parsed.body)
// the sdg-toc was based on h2s and h3s, but linear topic pages are using h1s and h2s
// It would be nice to standardise this but it would require a migration, updating CSS, updating Gdocs, etc.
const isTocForSidebar = parsed["sidebar-toc"] === "true"
const headingLevels = isTocForSidebar
? { primary: 1, secondary: 2 }
: { primary: 2, secondary: 3 }
parsed.toc = generateToc(parsed.body, headingLevels)

const parsedRefs = parseRefs({
refs: [...(parsed.refs ?? []), ...rawInlineRefs],
Expand Down
1 change: 1 addition & 0 deletions db/model/Gdoc/archieToGdoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function* owidArticleToArchieMLStringGenerator(
}
yield "[]"
}
yield* propertyToArchieMLString("sidebar-toc", article)
// TODO: inline refs
yieldMultiBlockPropertyIfDefined("summary", article, article.summary)
yield* propertyToArchieMLString("hide-citation", article)
Expand Down
20 changes: 20 additions & 0 deletions db/model/Gdoc/enrichedToRaw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
RawBlockAlign,
RawBlockEntrySummary,
RawBlockVideo,
RawBlockTable,
} from "@ourworldindata/utils"
import { spanToHtmlString } from "./gdocUtils.js"
import { match, P } from "ts-pattern"
Expand Down Expand Up @@ -400,5 +401,24 @@ export function enrichedBlockToRawBlock(
},
}
})
.with({ type: "table" }, (b): RawBlockTable => {
return {
type: b.type,
value: {
template: b.template,
rows: b.rows.map((row) => ({
type: row.type,
value: {
cells: row.cells.map((cell) => ({
type: cell.type,
value: cell.content.map(
enrichedBlockToRawBlock
),
})),
},
})),
},
}
})
.exhaustive()
}
87 changes: 87 additions & 0 deletions db/model/Gdoc/exampleEnrichedBlocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,4 +441,91 @@ export const enrichedBlockExamples: Record<
items: [{ text: "Hello", slug: "#link-to-something" }],
parseErrors: [],
},
table: {
type: "table",
template: "header-row",
rows: [
{
type: "table-row",
cells: [
{
type: "table-cell",
content: [
{
type: "text",
value: [
{
spanType: "span-simple-text",
text: "City",
},
],
parseErrors: [],
},
{
type: "text",
value: [
{
spanType: "span-simple-text",
text: "Continent",
},
],
parseErrors: [],
},
],
},
{
type: "table-cell",
content: [
{
type: "text",
value: [
{
spanType: "span-simple-text",
text: "Wellington",
},
],
parseErrors: [],
},
{
type: "text",
value: [
{
spanType: "span-simple-text",
text: "Zealandia",
},
],
parseErrors: [],
},
],
},
{
type: "table-cell",
content: [
{
type: "text",
value: [
{
spanType: "span-simple-text",
text: "Addis Ababa",
},
],
parseErrors: [],
},
{
type: "text",
value: [
{
spanType: "span-simple-text",
text: "Africa",
},
],
parseErrors: [],
},
],
},
],
},
],
parseErrors: [],
},
}
Loading
Loading