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

Entry Emulator - hide sticky nav on linear topic pages #2785

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 @@ -1343,7 +1343,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