Repository navigation
GRO-740 Add category layout (to support eventual "Getting started" migration) #1369
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7c10b66
GRO-740 make layout dynamic
bpander 0a776d7
GRO-740 add category layout
bpander 8c09975
GRO-740 style image
bpander f3d9926
GRO-740 hide mobile "On this page" toggle if the menu is empty
bpander a43bf54
GRO-740 simplify and fix category urls
bpander 5eb3bd8
GRO-740 hide mobile toc-toggle with js because simpler but also becau…
bpander 8da7d66
GRO-740 performance improvements
bpander 1d6e4a2
GRO-740 simplify how layout is chosen
bpander 2ef90cb
GRO-740 cleanup: getCategoryUrl doesn't recurse indefinitely since th…
bpander 96220c2
GRO-740 filter out external links from category landing pages
bpander File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| --- | ||
| import ReadTime from "./ReadTime.astro"; | ||
|
|
||
| export type PageEntry = { | ||
| url: string; | ||
| title: string; | ||
| summary: string; | ||
| readTime?: number; | ||
| }; | ||
|
|
||
| type Props = { | ||
| pages: PageEntry[]; | ||
| }; | ||
|
|
||
| const { pages } = Astro.props; | ||
| --- | ||
|
|
||
| {pages?.map((pageEntry) => ( | ||
| <a href={pageEntry.url} class="learn__category__link"> | ||
| <h4>{pageEntry.title}</h4> | ||
| <p>{pageEntry.summary}</p> | ||
| {!!pageEntry.readTime && <ReadTime minutes={pageEntry.readTime} />} | ||
| </a> | ||
| ))} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| --- | ||
| interface Props { | ||
| title: string; | ||
| summary?: string; | ||
| category_image?: string; | ||
| } | ||
|
|
||
| const { title, summary, category_image: image } = Astro.props; | ||
| --- | ||
|
|
||
| <header class:list={["category-header", image && "has-image"]}> | ||
| <h1>{title}</h1> | ||
| {summary && <div class="learn__summary">{summary}</div>} | ||
| {image && <img src={image} alt="" class="category-header__image no-zoom" />} | ||
| </header> | ||
|
|
||
| <style> | ||
| .category-header { | ||
| position: relative; | ||
| } | ||
|
|
||
| .category-header .category-header__image { | ||
| box-shadow: none; | ||
| display: block; | ||
| margin: 0 auto; | ||
| width: 50%; | ||
| } | ||
|
|
||
| @media screen and (min-width: 992px) { | ||
| .category-header.has-image { | ||
| padding-bottom: 96px; | ||
| } | ||
|
|
||
| .learn__summary { | ||
| width: 75%; | ||
| } | ||
|
|
||
| .category-header .category-header__image { | ||
| bottom: 0; | ||
| position: absolute; | ||
| right: -200px; | ||
| width: clamp(270px, 30vw, 420px); | ||
| z-index: -1; | ||
| } | ||
| } | ||
| </style> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| --- | ||
| import Clock from "@/icons/clock.svg"; | ||
|
|
||
| interface Props { | ||
| minutes: number; | ||
| } | ||
|
|
||
| const { minutes } = Astro.props; | ||
| --- | ||
|
|
||
| <p> | ||
| <Clock /> | ||
| {minutes} min read | ||
| </p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| --- | ||
| import CategoryCards, { | ||
| type PageEntry, | ||
| } from "@/components/categories/CategoryCards.astro"; | ||
| import CategoryHeader from "@/components/categories/CategoryHeader.astro"; | ||
| import type { DocPage } from "@/lib/docs/constructDocMetadata"; | ||
| import { findNavNode, getNavForVersion, type NavNode } from "@/lib/docs/nav"; | ||
| import { docIdFromUrl } from "@/lib/docs/resolveDoc"; | ||
| import { getEntry } from "astro:content"; | ||
| import NewDocsLayout from "./NewDocsLayout.astro"; | ||
|
|
||
| type Props = { | ||
| page: DocPage; | ||
| dirname: string; | ||
| }; | ||
|
|
||
| const { page, dirname } = Astro.props; | ||
|
|
||
| function getReadTime(body?: string, minimum = 0): number | undefined { | ||
| if (!body) return undefined; | ||
|
|
||
| // Match Jekyll's `number_of_words` filter, which counts whitespace-separated | ||
| // tokens in the unrendered collection content. | ||
| const words = body.trim().split(/\s+/).filter(Boolean).length; | ||
| return Math.max(minimum, Math.floor(words / 238)); | ||
| } | ||
|
|
||
| const navNode = findNavNode( | ||
| getNavForVersion(page.latest ? "latest" : page.version).categories, | ||
| (node) => !!node.url && node.url === page.url, | ||
| ); | ||
|
|
||
| const pages: PageEntry[] = await Promise.all( | ||
| (navNode?.pages ?? []) | ||
| // Only docs pages get cards; external links are skipped. | ||
| .filter((node): node is NavNode & { url: string } => | ||
| Boolean(node.url?.startsWith("/docs/")), | ||
| ) | ||
| .map(async (node) => { | ||
| const doc = await getEntry("docs", docIdFromUrl(node.url)); | ||
| if (!doc) { | ||
| throw new Error(`Doc not found: ${node.url}`); | ||
| } | ||
| return { | ||
| url: node.url, | ||
| title: doc.data.title ?? node.name, | ||
| summary: doc.data.summary, | ||
| readTime: getReadTime(doc.body, 1), | ||
| }; | ||
| }), | ||
| ); | ||
| --- | ||
|
|
||
| <NewDocsLayout {page} {dirname}> | ||
| <CategoryHeader {...page} /> | ||
| <CategoryCards pages={pages} /> | ||
| </NewDocsLayout> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some nav items have links pointing to non-docs pages, mb we should filter them out or add a fallback for such items?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jeff-bruemmer Do you know of any cases where we'd have one of these category landing pages with a card that's an external link? Or have an opinion on what should happen if that ever comes up?
I didn't want to just guess at the behavior so I just have it failing loudly if it ever happens. We could leave that as is and cross that bridge if we come to it. I'm also happy to implement some kind of a fallback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GH failed to post Jeff's comment, but I DM'd him. We'll just show cards for links to actual docs. I updated the code to filter out external links in 96220c2.