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

feat(curriculum): integrate MDN Curriculum #10433

Merged
merged 113 commits into from
Feb 27, 2024
Merged

Conversation

fiji-flo
Copy link
Contributor

@fiji-flo fiji-flo commented Jan 31, 2024

Summary

Integrate https://github.com/mdn/curriculum content into MDN.

Mainly adds two parts:

  • a build step, run via yarn build:curriculum which is similar to the regular content and blog build step.
  • the react code to render the curriculum content.

Fixes and changes along the way:

  • Changes the breadcrumb into real links instead of router links
  • Support custom title for the ToC

How did you test this change?

It's deployed to stage and QAed

@github-actions github-actions bot added python Pull requests that update Python code deployer Deployment (currently using AWS S3 and AWS Lambda) github-actions cloud-function labels Jan 31, 2024
build/curriculum.ts Fixed Show fixed Hide fixed
build/curriculum.ts Fixed Show fixed Hide fixed
build/utils.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@caugner caugner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First review pass until client/src/curriculum/utils.ts

.github/workflows/stage-build.yml Show resolved Hide resolved
build/build-curriculum.ts Show resolved Hide resolved
build/curriculum.ts Outdated Show resolved Hide resolved
// @ts-ignore
import { renderHTML } from "../ssr/dist/main.js";

export const allFiles = memoize(async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would indeed be helpful to merge #10567 first.

build/curriculum.ts Outdated Show resolved Hide resolved
client/src/curriculum/overview.tsx Outdated Show resolved Hide resolved
client/src/curriculum/prev-next.tsx Outdated Show resolved Hide resolved
client/src/curriculum/prev-next.tsx Outdated Show resolved Hide resolved
client/src/curriculum/prev-next.tsx Show resolved Hide resolved
client/src/curriculum/sidebar.tsx Outdated Show resolved Hide resolved
.github/workflows/stage-build.yml Show resolved Hide resolved
build/curriculum.ts Outdated Show resolved Hide resolved
build/curriculum.ts Outdated Show resolved Hide resolved
build/curriculum.ts Outdated Show resolved Hide resolved
build/curriculum.ts Outdated Show resolved Hide resolved
build/curriculum.ts Outdated Show resolved Hide resolved
build/curriculum.ts Outdated Show resolved Hide resolved
build/curriculum.ts Outdated Show resolved Hide resolved
build/utils.ts Outdated Show resolved Hide resolved
build/utils.ts Outdated Show resolved Hide resolved
Comment on lines 30 to 31
property="item"
typeof="WebPage"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are property and typeof here leftovers from the PreloadingDocumentLink component?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not straight forward and didn't want to break things.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like property and typeof refer to https://schema.org/BreadcrumbList, but is the information actually used by any tool?

@github-actions github-actions bot added the macros tracking issues related to kumascript macros label Feb 23, 2024
client/src/curriculum/landing.scss Show resolved Hide resolved
client/src/curriculum/landing.tsx Outdated Show resolved Hide resolved
client/src/curriculum/module.scss Outdated Show resolved Hide resolved
Copy link
Member

@LeoMcA LeoMcA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, no idea what vscode was doing with my review comments (and why it kept submitting them), but done now - overall mostly looks like some typing nits from me

Comment on lines 3 to 4
.curriculum-content-container.with-sidebar,
.curriculum-content-container {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, selectors feel a bit redundant here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CSS specificity. changed it to .curriculum-content-container.curriculum-overview to narrow it down.

Comment on lines +42 to +43
? `${doc.title} | ${CURRICULUM_TITLE}`
: CURRICULUM_TITLE;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
? `${doc.title} | ${CURRICULUM_TITLE}`
: CURRICULUM_TITLE;
? `${doc.title} | ${TITLE_SUFFIX}`
: TITLE_SUFFIX;

client/src/curriculum/utils.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@caugner caugner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { renderHTML } from "../ssr/dist/main.js";
import { CheerioAPI } from "cheerio";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: move to 2nd group.

Comment on lines +115 to +117
const index = await buildCurriculumIndex(({ url, slug, title }) => {
return { url, slug, title };
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI

Suggested change
const index = await buildCurriculumIndex(({ url, slug, title }) => {
return { url, slug, title };
});
const index = await buildCurriculumIndex(({ url, slug, title }) => ({ url, slug, title }));

Comment on lines 129 to 130
prev && "children" in prev && delete prev.children;
next && "children" in next && delete next.children;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we modify index (via prev/next) as a side-effect of this function? It looks like a separate concern.

Comment on lines 151 to 153
cur: CurriculumIndexEntry[]
): DocParent[] | null {
for (const entry of cur) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cur: CurriculumIndexEntry[]
): DocParent[] | null {
for (const entry of cur) {
entries: CurriculumIndexEntry[]
): DocParent[] | null {
for (const entry of entries) {

return prevNextFromIndex(i, index);
}

function breadPath(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Maybe rename to breadcrumbPath()?

Comment on lines 13 to 16
module = "module",
overview = "overview",
landing = "landing",
about = "about",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Would be better to uppercase the first letter to avoid mistaking these for object properties.

Suggested change
module = "module",
overview = "overview",
landing = "landing",
about = "about",
Module = "module",
Overview = "overview",
Landing = "landing",
About = "about",

export function fileToSlug(file: string) {
return file
.replace(`${CURRICULUM_ROOT}/`, "")
.replace(/(\d+-|\.md$|\/0?-?README)/g, "");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering if \d+- should be removed anywhere in the name or just at the beginning of the filename?

Comment on lines 97 to 100
const currentLvl = meta.slug.split("/").length;
const last = item.length ? item[item.length - 1] : null;
const entry = mapper(meta);
if (currentLvl > 2) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const currentLvl = meta.slug.split("/").length;
const last = item.length ? item[item.length - 1] : null;
const entry = mapper(meta);
if (currentLvl > 2) {
const currentLevel = meta.slug.split("/").length;
const last = item.length ? item[item.length - 1] : null;
const entry = mapper(meta);
if (currentLevel > 2) {

options?: {
previousNext?: boolean;
forIndex?: boolean;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe declare a default value to avoid having to null coalesce (options?) below?

Suggested change
}
} = { previousNext: false, forIndex: false }

Comment on lines 206 to 212
modules = (await buildCurriculumIndex())?.filter(
(x) => x.children?.length
);
} else if (attributes.template === Template.overview) {
modules = (await buildCurriculumIndex())?.find(
(x) => x.slug === slug
)?.children;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we build the index once to avoid duplicate work, even if buildIndex() inside is memoized?

Comment on lines +220 to +223
if doc["mdn_url"].startswith("/en-US/curriculum/"):
# Skip curriculum content for now.
return

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Would have been better to move this behind line 224 (locale, slug = doc["mdn_url"].split("/docs/", 1)), so it works independent of en-US (DEFAULT_LOCALE).

@@ -74,7 +74,7 @@ router.get(
proxyContent
);
router.get(
"/[^/]+/blog($|/*)",
["/[^/]+/blog($|/*)", "/[^/]+/curriculum($|/*)"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Does this not work?

Suggested change
["/[^/]+/blog($|/*)", "/[^/]+/curriculum($|/*)"],
"/[^/]+/(blog|curriculum)($|/*)",

@@ -207,6 +207,71 @@
--baseline-limited-check: #1e8e3e;
--baseline-limited-cross: #ea8600;

--cur-bg-color: #fcefe2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'm not a big fan of the cur prefix, because it can be mistaken for "current". I think it would have been okay to use curriculum-.

"star-filled", "star", "theme-os-default", "thumbs-down", "thumbs-up", "trash",
"trash-filled", "twitter", "unknown", "warning", "webview", "yes",
"yes-circle";
"chrome", "critical", "cur-next", "cur-prev", "deno", "deprecated", "desktop",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Especially here, cur-prev sounds like current-previous.

name="selected"
type="radio"
checked={i === tab}
onChange={() => setTab(i)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fiji-flo Should we not record the tab changes with Glean?

Copy link
Contributor

@caugner caugner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! 🚀

@fiji-flo fiji-flo merged commit 5fd4800 into main Feb 27, 2024
18 checks passed
@fiji-flo fiji-flo deleted the MP-739-curriculum-builder branch February 27, 2024 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cloud-function deployer Deployment (currently using AWS S3 and AWS Lambda) github-actions macros tracking issues related to kumascript macros python Pull requests that update Python code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants