Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into client-syntax-highl…
Browse files Browse the repository at this point in the history
…ight
  • Loading branch information
fiji-flo committed Sep 5, 2024
2 parents 998111b + 5adb9eb commit 2280c7e
Show file tree
Hide file tree
Showing 29 changed files with 697 additions and 664 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
auto-merge:
runs-on: ubuntu-latest
if: github.actor == 'dependabot[bot]'
if: github.event.pull_request.user.login == 'dependabot[bot]'

steps:
- name: Dependabot metadata
Expand Down
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "2.60.1"
".": "2.62.0"
}
156 changes: 156 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

69 changes: 54 additions & 15 deletions build/spas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { fdir, PathsOutput } from "fdir";
import got from "got";

import { m2h } from "../markdown/index.js";
import * as kumascript from "../kumascript/index.js";

import {
VALID_LOCALES,
Expand All @@ -24,26 +25,28 @@ import {
} from "../libs/env/index.js";
import { isValidLocale } from "../libs/locale-utils/index.js";
import { DocFrontmatter, DocParent, NewsItem } from "../libs/types/document.js";
import { getSlugByBlogPostUrl, splitSections } from "./utils.js";
import { getSlugByBlogPostUrl, makeTOC } from "./utils.js";
import { findByURL } from "../content/document.js";
import { buildDocument } from "./index.js";
import { findPostBySlug } from "./blog.js";
import { buildSitemap } from "./sitemaps.js";
import { type Locale } from "../libs/types/core.js";
import { HydrationData } from "../libs/types/hydration.js";
import { extractSections } from "./extract-sections.js";
import { wrapTables } from "./wrap-tables.js";

const FEATURED_ARTICLES = [
"blog/mdn-scrimba-partnership/",
"blog/learn-javascript-console-methods/",
"blog/introduction-to-web-sustainability/",
"docs/Web/API/CSS_Custom_Highlight_API",
"docs/Web/CSS/color_value",
];

const LATEST_NEWS: (NewsItem | string)[] = [
"blog/mdn-scrimba-partnership/",
"blog/mdn-http-observatory-launch/",
"blog/mdn-curriculum-launch/",
"blog/baseline-evolution-on-mdn/",
"blog/introducing-the-mdn-playground/",
];

const PAGE_DESCRIPTIONS = Object.freeze({
Expand All @@ -59,17 +62,31 @@ async function buildContributorSpotlight(
) {
const prefix = "community/spotlight";
const profileImg = "profile-image.jpg";
let featuredContributorFrontmatter: DocFrontmatter;

for (const contributor of fs.readdirSync(contributorSpotlightRoot)) {
const markdown = fs.readFileSync(
`${contributorSpotlightRoot}/${contributor}/index.md`,
"utf-8"
);
const file = `${contributorSpotlightRoot}/${contributor}/index.md`;
const markdown = fs.readFileSync(file, "utf-8");
const url = `/${locale}/${prefix}/${contributor}`;

const frontMatter = frontmatter<DocFrontmatter>(markdown);
const contributorHTML = await m2h(frontMatter.body, { locale });
const d = {
url,
rawBody: contributorHTML,
metadata: {
locale: DEFAULT_LOCALE,
slug: `${prefix}/${contributor}`,
url,
},

const { sections } = splitSections(contributorHTML);
isMarkdown: true,
fileInfo: {
path: file,
},
};
const [$] = await kumascript.render(url, {}, d);
const [sections] = await extractSections($);

const hyData = {
sections: sections,
Expand Down Expand Up @@ -102,14 +119,19 @@ async function buildContributorSpotlight(
if (options.verbose) {
console.log("Wrote", jsonFilePath);
}

if (frontMatter.attributes.is_featured) {
return {
contributorName: frontMatter.attributes.contributor_name,
url: `/${locale}/${prefix}/${frontMatter.attributes.folder_name}`,
quote: frontMatter.attributes.quote,
};
featuredContributorFrontmatter = frontMatter.attributes;
}
}

return featuredContributorFrontmatter
? {
contributorName: featuredContributorFrontmatter.contributor_name,
url: `/${locale}/${prefix}/${featuredContributorFrontmatter.folder_name}`,
quote: featuredContributorFrontmatter.quote,
}
: undefined;
}

export async function buildSPAs(options: {
Expand Down Expand Up @@ -277,9 +299,26 @@ export async function buildSPAs(options: {
const frontMatter = frontmatter<DocFrontmatter>(markdown);
const rawHTML = await m2h(frontMatter.body, { locale });

const { sections, toc } = splitSections(rawHTML);

const url = `/${locale}/${slug}/${page}`;
const d = {
url,
rawBody: rawHTML,
metadata: {
locale: DEFAULT_LOCALE,
slug: `${slug}/${page}`,
url,
},

isMarkdown: true,
fileInfo: {
path: file,
},
};
const [$] = await kumascript.render(url, {}, d);
wrapTables($);
const [sections] = await extractSections($);
const toc = makeTOC({ body: sections });

const hyData = {
id: page,
...frontMatter.attributes,
Expand Down
34 changes: 0 additions & 34 deletions build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,40 +148,6 @@ export function getImageminPlugin(fileName: string) {
throw new Error(`No imagemin plugin for ${extension}`);
}

export function splitSections(rawHTML) {
const $ = cheerio.load(`<div id="_body">${rawHTML}</div>`);
const blocks = [];
const toc = [];

const section = cheerio
.load("<div></div>", { decodeEntities: false })("div")
.eq(0);

const iterable = [...($("#_body")[0] as cheerio.Element).childNodes];
let c = 0;
iterable.forEach((child) => {
if ("tagName" in child && child.tagName === "h2") {
if (c) {
blocks.push(section.clone());
section.empty();
c = 0;
}
const text = $(child).text();
const id = text.replace(/[ .,!?]+/g, "-").toLowerCase();
toc.push({ id, text });
child.attribs = { ...(child.attribs || {}), id };
}
c++;
section.append(child);
});
if (c) {
blocks.push(section.clone());
}

const sections = blocks.map((block) => block.html().trim());
return { sections, toc };
}

/**
* Return an array of all images that are inside the documents source folder.
*
Expand Down
4 changes: 2 additions & 2 deletions client/pwa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
"dev": "webpack-cli --watch"
},
"dependencies": {
"@zip.js/zip.js": "2.7.51",
"@zip.js/zip.js": "2.7.52",
"dexie": "4.0.8"
},
"devDependencies": {
"@types/dexie": "1.3.1",
"ts-loader": "^9.5.1",
"typescript": "^5.5.4",
"webpack": "^5.93.0",
"webpack": "^5.94.0",
"webpack-cli": "^5.1.4",
"workers-preview": "^1.0.6"
}
Expand Down
61 changes: 22 additions & 39 deletions client/pwa/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,12 @@
dependencies:
dexie "*"

"@types/eslint-scope@^3.7.3":
version "3.7.3"
resolved "https://registry.yarnpkg.com/@types/eslint-scope/-/eslint-scope-3.7.3.tgz#125b88504b61e3c8bc6f870882003253005c3224"
integrity sha512-PB3ldyrcnAicT35TWPs5IcwKD8S333HMaa2VVv4+wdvebJkjWuW/xESoB8IwRcog8HYVYamb1g/R31Qv5Bx03g==
dependencies:
"@types/eslint" "*"
"@types/estree" "*"

"@types/eslint@*":
version "8.4.1"
resolved "https://registry.yarnpkg.com/@types/eslint/-/eslint-8.4.1.tgz#c48251553e8759db9e656de3efc846954ac32304"
integrity sha512-GE44+DNEyxxh2Kc6ro/VkIj+9ma0pO0bwv9+uHSyBrikYOHr8zYcdPvnBOp1aw8s+CjRvuSx7CyWqRrNFQ59mA==
dependencies:
"@types/estree" "*"
"@types/json-schema" "*"

"@types/estree@*", "@types/estree@^1.0.5":
"@types/estree@^1.0.5":
version "1.0.5"
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.5.tgz#a6ce3e556e00fd9895dd872dd172ad0d4bd687f4"
integrity sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==

"@types/json-schema@*", "@types/json-schema@^7.0.8":
"@types/json-schema@^7.0.8":
version "7.0.9"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.9.tgz#97edc9037ea0c38585320b28964dde3b39e4660d"
integrity sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ==
Expand Down Expand Up @@ -249,10 +233,10 @@
resolved "https://registry.yarnpkg.com/@xtuc/long/-/long-4.2.2.tgz#d291c6a4e97989b5c61d9acf396ae4fe133a718d"
integrity sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==

"@zip.js/[email protected].51":
version "2.7.51"
resolved "https://registry.yarnpkg.com/@zip.js/zip.js/-/zip.js-2.7.51.tgz#a434e285048b951a5788d3d2d59aa68f209e7141"
integrity sha512-RKHaebzZZgQkUuzb49/qweN69e8Np9AUZ9QygydDIrbG1njypSAKwkeqIVeuf2JVGBDyB7Z9HKvzPgYrSlv9gw==
"@zip.js/[email protected].52":
version "2.7.52"
resolved "https://registry.yarnpkg.com/@zip.js/zip.js/-/zip.js-2.7.52.tgz#bc11de93b41f09e03155bc178e7f9c2e2612671d"
integrity sha512-+5g7FQswvrCHwYKNMd/KFxZSObctLSsQOgqBSi0LzwHo3li9Eh1w5cF5ndjQw9Zbr3ajVnd2+XyiX85gAetx1Q==

acorn-import-attributes@^1.9.5:
version "1.9.5"
Expand Down Expand Up @@ -286,7 +270,7 @@ ansi-styles@^4.1.0:
dependencies:
color-convert "^2.0.1"

braces@^3.0.1:
braces@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.3.tgz#490332f40919452272d55a8480adc0c441358789"
integrity sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==
Expand Down Expand Up @@ -381,10 +365,10 @@ electron-to-chromium@^1.4.601:
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.645.tgz#117f964252eb2f0ff00fc7360cb3080e2cf66e3c"
integrity sha512-EeS1oQDCmnYsRDRy2zTeC336a/4LZ6WKqvSaM1jLocEk5ZuyszkQtCpsqvuvaIXGOUjwtvF6LTcS8WueibXvSw==

enhanced-resolve@^5.0.0, enhanced-resolve@^5.17.0:
version "5.17.0"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.17.0.tgz#d037603789dd9555b89aaec7eb78845c49089bc5"
integrity sha512-dwDPwZL0dmye8Txp2gzFmA6sxALaSvdRDjPH0viLcKrtlOL3tw62nWWweVD1SdILDTJrbrL6tdWVN58Wo6U3eA==
enhanced-resolve@^5.0.0, enhanced-resolve@^5.17.1:
version "5.17.1"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.17.1.tgz#67bfbbcc2f81d511be77d686a90267ef7f898a15"
integrity sha512-LMHl3dXhTcfv8gM4kEzIUeTQ+7fpdA0l2tUf34BddXPkz2A5xJ5L/Pchd5BL6rdccM9QGvu0sWZzK1Z1t4wwyg==
dependencies:
graceful-fs "^4.2.4"
tapable "^2.2.0"
Expand Down Expand Up @@ -587,12 +571,12 @@ merge-stream@^2.0.0:
integrity sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==

micromatch@^4.0.0:
version "4.0.4"
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.4.tgz#896d519dfe9db25fce94ceb7a500919bf881ebf9"
integrity sha512-pRmzw/XUcwXGpD9aI9q/0XOwLNygjETJ8y0ao0wdqprrzDa4YnxLcz7fQRZr8voh8V10kGhABbNcHVk5wHgWwg==
version "4.0.8"
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.8.tgz#d66fa18f3a47076789320b9b1af32bd86d9fa202"
integrity sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==
dependencies:
braces "^3.0.1"
picomatch "^2.2.3"
braces "^3.0.3"
picomatch "^2.3.1"

[email protected]:
version "1.51.0"
Expand Down Expand Up @@ -662,7 +646,7 @@ picocolors@^1.0.0:
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c"
integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==

picomatch@^2.2.3:
picomatch@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42"
integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==
Expand Down Expand Up @@ -902,12 +886,11 @@ webpack-sources@^3.2.3:
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.2.3.tgz#2d4daab8451fd4b240cc27055ff6a0c2ccea0cde"
integrity sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==

webpack@^5.93.0:
version "5.93.0"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.93.0.tgz#2e89ec7035579bdfba9760d26c63ac5c3462a5e5"
integrity sha512-Y0m5oEY1LRuwly578VqluorkXbvXKh7U3rLoQCEO04M97ScRr44afGVkI0FQFsXzysk5OgFAxjZAb9rsGQVihA==
webpack@^5.94.0:
version "5.94.0"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.94.0.tgz#77a6089c716e7ab90c1c67574a28da518a20970f"
integrity sha512-KcsGn50VT+06JH/iunZJedYGUJS5FGjow8wb9c0v5n1Om8O1g4L6LjtfxwlXIATopoQu+vOXXa7gYisWxCoPyg==
dependencies:
"@types/eslint-scope" "^3.7.3"
"@types/estree" "^1.0.5"
"@webassemblyjs/ast" "^1.12.1"
"@webassemblyjs/wasm-edit" "^1.12.1"
Expand All @@ -916,7 +899,7 @@ webpack@^5.93.0:
acorn-import-attributes "^1.9.5"
browserslist "^4.21.10"
chrome-trace-event "^1.0.2"
enhanced-resolve "^5.17.0"
enhanced-resolve "^5.17.1"
es-module-lexer "^1.2.1"
eslint-scope "5.1.1"
events "^3.2.0"
Expand Down
11 changes: 11 additions & 0 deletions client/src/contributor-spotlight/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,15 @@
padding: 0.2rem 0.4rem;
}
}

h2 {
a {
color: var(--text-primary);
text-decoration: none;

&:hover {
text-decoration: underline;
}
}
}
}
9 changes: 6 additions & 3 deletions client/src/contributor-spotlight/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import "./index.scss";
import { useLocale } from "../hooks";
import { PageNotFound } from "../page-not-found";
import { Loading } from "../ui/atoms/loading";
import { Prose } from "../document/ingredients/prose";

type ContributorDetails = {
sections: [string];
Expand Down Expand Up @@ -83,12 +84,14 @@ export function ContributorSpotlight(props: HydrationData<ContributorDetails>) {
</a>
</section>
<section
dangerouslySetInnerHTML={{ __html: hyData.sections[0] }}
dangerouslySetInnerHTML={{ __html: hyData.sections[0].value.content }}
></section>
<Quote name={hyData.contributorName}>{hyData.quote}</Quote>

{hyData.sections.slice(1).map((section) => {
return <section dangerouslySetInnerHTML={{ __html: section }} />;
{hyData.sections.slice(1).map((section, index) => {
return (
<Prose key={section.value.id || index} section={section.value} />
);
})}
</main>
<GetInvolved />
Expand Down
2 changes: 2 additions & 0 deletions client/src/curriculum/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@

.curriculum-content-container {
> .curriculum-content {
max-width: 100%;

h1,
h2,
h3,
Expand Down
Loading

0 comments on commit 2280c7e

Please sign in to comment.