Skip to content

Commit

Permalink
🎉 hide sticky nav on linear topic pages
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesau committed Oct 17, 2023
1 parent db8f0c3 commit fdb65a9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions db/migrateWpPostsToArchieMl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ const migrate = async (): Promise<void> => {
type: isEntry
? OwidGdocType.TopicPage
: OwidGdocType.Article,
// 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,
},
relatedCharts,
published: false,
Expand Down
2 changes: 2 additions & 0 deletions db/model/Gdoc/archieToEnriched.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ function generateStickyNav(
): OwidGdocStickyNavItem[] | undefined {
if (content.type !== OwidGdocType.TopicPage) return
// If a sticky nav has been explicitly defined, use that.
// We are using this for linear topic pages, as a way to have a document using the topic page template
// but without a sticky nav
if (content["sticky-nav"]) return content["sticky-nav"]
// These are the default headings that we'll try to find and create sticky nav headings for
// Even if the id for the heading is "key-insights-on-poverty", we can just do substring matches
Expand Down
8 changes: 8 additions & 0 deletions db/model/Gdoc/archieToGdoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ function* owidArticleToArchieMLStringGenerator(
yield* propertyToArchieMLString("dateline", article)
yield* propertyToArchieMLString("excerpt", article)
yield* propertyToArchieMLString("type", article)
if (article["sticky-nav"]) {
yield "[.sticky-nav]"
for (const item of article["sticky-nav"]) {
yield* propertyToArchieMLString("target", item)
yield* propertyToArchieMLString("text", item)
}
yield "[]"
}
// TODO: inline refs
yieldMultiBlockPropertyIfDefined("summary", article, article.summary)
yield* propertyToArchieMLString("hide-citation", article)
Expand Down
2 changes: 1 addition & 1 deletion packages/@ourworldindata/utils/src/owidTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,7 @@ export interface OwidGdocContent {
| "sdg-color-16"
| "sdg-color-17"
| "amber"
"sticky-nav"?: []
"sticky-nav"?: OwidGdocStickyNavItem[]
details?: DetailDictionary
// TODO: having both the unparsed and parsed variant on the same type is pretty crude
// Consider moving faqs into body or splitting the types and creating
Expand Down
2 changes: 1 addition & 1 deletion site/gdocs/OwidGdoc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export function OwidGdoc({
publishedAt={publishedAt}
breadcrumbs={breadcrumbs ?? undefined}
/>
{content.type === "topic-page" && stickyNavLinks ? (
{content.type === "topic-page" && stickyNavLinks?.length ? (
<nav className="sticky-nav sticky-nav--dark span-cols-14 grid grid-cols-12-full-width">
<StickyNav
links={stickyNavLinks}
Expand Down

0 comments on commit fdb65a9

Please sign in to comment.