Skip to content

Commit

Permalink
Merge branch 'main' into fix/translations-dashboard-column-sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
leon-win committed Nov 7, 2023
2 parents 64e78b8 + ef5800a commit 795cc5b
Show file tree
Hide file tree
Showing 67 changed files with 1,471 additions and 1,282 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ module.exports = {
"warn",
{ ignoreRestSiblings: true },
],
"n/no-deprecated-api": "off",
"n/no-extraneous-import": [
"error",
{
Expand Down
61 changes: 61 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,66 @@
# Changelog

## [2.33.1](https://github.com/mdn/yari/compare/v2.33.0...v2.33.1) (2023-11-03)


### Bug Fixes

* **links:** revert distinguish visited links ([3bae299](https://github.com/mdn/yari/commit/3bae2998df7296591368004fd06d5b6b5358bb2f))


### Miscellaneous

* **deps-dev:** bump postcss-preset-env from 9.2.0 to 9.3.0 ([#9923](https://github.com/mdn/yari/issues/9923)) ([e095444](https://github.com/mdn/yari/commit/e0954449274a5225e56a6bd84afec280b14b378d))
* **deps-dev:** bump react-router-dom from 6.17.0 to 6.18.0 ([#9925](https://github.com/mdn/yari/issues/9925)) ([cd21c6d](https://github.com/mdn/yari/commit/cd21c6dcc0d2855e9e38759300ac805368e50dd5))
* **deps-dev:** bump stylelint-config-recommended-scss from 13.0.0 to 13.1.0 ([#9935](https://github.com/mdn/yari/issues/9935)) ([ca191b0](https://github.com/mdn/yari/commit/ca191b0211a7162e18f0504b2605a44eedbf880e))
* **deps-dev:** bump the types group with 1 update ([#9928](https://github.com/mdn/yari/issues/9928)) ([414cc21](https://github.com/mdn/yari/commit/414cc21e5b1b06bbf828478d983f4c66ce7c15d5))
* **deps:** bump @mdn/browser-compat-data from 5.3.27 to 5.3.28 ([#9926](https://github.com/mdn/yari/issues/9926)) ([48c8ce0](https://github.com/mdn/yari/commit/48c8ce03141eefde73bd8110772ddad90b45959f))
* **deps:** bump @stripe/stripe-js from 2.1.10 to 2.1.11 ([#9933](https://github.com/mdn/yari/issues/9933)) ([8054bbd](https://github.com/mdn/yari/commit/8054bbd1f3fffba02eab8dd8928d856977baf7be))
* **deps:** bump file-type from 18.5.0 to 18.6.0 ([#9924](https://github.com/mdn/yari/issues/9924)) ([ecd9779](https://github.com/mdn/yari/commit/ecd9779409c5de32d20839c45bb4c745350fd324))
* **deps:** bump mdn-data from 2.1.0 to 2.2.0 ([#9934](https://github.com/mdn/yari/issues/9934)) ([32c0c00](https://github.com/mdn/yari/commit/32c0c00815ac5d1efeca63d17c236266906d4a17))
* **macros/JsSidebar:** update zh-CN translation ([#9849](https://github.com/mdn/yari/issues/9849)) ([9867d52](https://github.com/mdn/yari/commit/9867d52abdebea25beb6e4d4878bd902a03664c4))
* **macros/LearnSidebar:** add some pages under MathML ([#9937](https://github.com/mdn/yari/issues/9937)) ([060e53a](https://github.com/mdn/yari/commit/060e53a002761656bbad954a1675ee0a8b8ef109))
* **macros/WebAssemblySidebar:** add zh-CN translation ([#9932](https://github.com/mdn/yari/issues/9932)) ([870285a](https://github.com/mdn/yari/commit/870285aed1e0218adbc4abf1660ccd519413496c))
* **telemetry:** measure menu clicks ([#9918](https://github.com/mdn/yari/issues/9918)) ([c4c5d79](https://github.com/mdn/yari/commit/c4c5d79f201cd2fe3844414dcaf5edc8b9bd5246))

## [2.33.0](https://github.com/mdn/yari/compare/v2.32.0...v2.33.0) (2023-10-31)


### Features

* **links:** distinguish visited links ([#9907](https://github.com/mdn/yari/issues/9907)) ([8f84da3](https://github.com/mdn/yari/commit/8f84da3bcc0bc6e1b87c15078c14a1d140925688))
* **theme:** sync body background-color with theme-color meta tag ([#9325](https://github.com/mdn/yari/issues/9325)) ([5001b04](https://github.com/mdn/yari/commit/5001b04890f796b388024b2d23c4c5b0caf88f73))


### Bug Fixes

* **client:** rendering locale in column header on /translations/dashboard ([24bf873](https://github.com/mdn/yari/commit/24bf8738815cc0884eb47e3ae0f4ce1973906389))
* correct some typos ([#9858](https://github.com/mdn/yari/issues/9858)) ([925538e](https://github.com/mdn/yari/commit/925538e166bd71d2befb3fb46741d7b6624a4978))
* **docs:** link first child of every description term in post-processing ([#9862](https://github.com/mdn/yari/issues/9862)) ([0295813](https://github.com/mdn/yari/commit/029581391fa2a57f843d55f47390ec8c0c4b6732))
* **images:** avoid blurry images ([#9591](https://github.com/mdn/yari/issues/9591)) ([0829b7e](https://github.com/mdn/yari/commit/0829b7ee43815d86f9c91ef6797cedc7d4f1e1f3))
* **mandala:** remove rotation and color animation ([#9916](https://github.com/mdn/yari/issues/9916)) ([e687a03](https://github.com/mdn/yari/commit/e687a03e2354412f4dad45e80d4ebaa9d7926d5a))
* **plus:** load stripe.js for fraud prevention ([#9318](https://github.com/mdn/yari/issues/9318)) ([88f000e](https://github.com/mdn/yari/commit/88f000e037fbad71ed2779159aa4e7f47568cadc))
* **translations/dashboard:** fix Popularity rank column header ([#9908](https://github.com/mdn/yari/issues/9908)) ([24bf873](https://github.com/mdn/yari/commit/24bf8738815cc0884eb47e3ae0f4ce1973906389))


### Miscellaneous

* **deps-dev:** bump {react-router,react-router-dom} from 6.16.0 to 6.17.0 ([#9832](https://github.com/mdn/yari/issues/9832)) ([fd72a19](https://github.com/mdn/yari/commit/fd72a19b394e9c4123b4670deae140b6549ec93f))
* **deps-dev:** bump eslint-plugin-unicorn from 48.0.1 to 49.0.0 ([#9904](https://github.com/mdn/yari/issues/9904)) ([0de918b](https://github.com/mdn/yari/commit/0de918bcc291a48299dce76c8f251224705e86eb))
* **deps-dev:** bump stylelint-scss from 5.2.1 to 5.3.0 ([#9905](https://github.com/mdn/yari/issues/9905)) ([5efd040](https://github.com/mdn/yari/commit/5efd04052a81c7d145dc8b7f1d212dbbfc5b0211))
* **deps-dev:** bump the types group with 1 update ([#9913](https://github.com/mdn/yari/issues/9913)) ([3b2dc06](https://github.com/mdn/yari/commit/3b2dc06f522bbdf0e730fe054f588d3bbc46b204))
* **deps:** bump [@zip](https://github.com/zip).js/zip.js from 2.7.29 to 2.7.30 in /client/pwa ([#9823](https://github.com/mdn/yari/issues/9823)) ([a19c79c](https://github.com/mdn/yari/commit/a19c79ced150ca79f54dbd55781488124b5e8b0d))
* **deps:** bump openai from 3.3.0 to 4.14.0 ([#9888](https://github.com/mdn/yari/issues/9888)) ([607c938](https://github.com/mdn/yari/commit/607c9385f804bdb8c25e4a66870444516aa59b3f))
* **deps:** bump openai from 4.14.0 to 4.14.1 ([#9903](https://github.com/mdn/yari/issues/9903)) ([101b682](https://github.com/mdn/yari/commit/101b68220aa0ec8d264d37fd7050669613e72655))
* **deps:** bump openai from 4.14.1 to 4.14.2 ([#9914](https://github.com/mdn/yari/issues/9914)) ([b60d0c0](https://github.com/mdn/yari/commit/b60d0c0e4b204993b4ded647d0256e6692b92195))
* **deps:** bump the dependencies group in /deployer with 3 updates ([#9900](https://github.com/mdn/yari/issues/9900)) ([fe6c535](https://github.com/mdn/yari/commit/fe6c535a812511c57faa6ce722bc66d50e7c6c76))
* **deps:** bump the dependencies group in /testing/integration with 2 updates ([#9902](https://github.com/mdn/yari/issues/9902)) ([521b8af](https://github.com/mdn/yari/commit/521b8af6bb26cd0370f845fc32d6e63b88eb97ff))
* **deps:** bump the sentry group with 2 updates ([#9901](https://github.com/mdn/yari/issues/9901)) ([881e66c](https://github.com/mdn/yari/commit/881e66c4c648f776d314ed8d2bfe1fdf2d61c5ef))
* **deps:** bump the sentry group with 2 updates ([#9912](https://github.com/mdn/yari/issues/9912)) ([3c371ce](https://github.com/mdn/yari/commit/3c371ce6ae1cfdf853b309a9a1d6d150bb26f0ef))
* **macros/MathMLRef:** update zh-CN translation ([#9915](https://github.com/mdn/yari/issues/9915)) ([d7f3e7d](https://github.com/mdn/yari/commit/d7f3e7d6859d4742a42481af842c045691ec8268))
* **macros/Non-standard_Header:** remove "Firefox OS" ([#9827](https://github.com/mdn/yari/issues/9827)) ([fd2a66e](https://github.com/mdn/yari/commit/fd2a66e5eeed6174872e5ce98b8d114d621072a3))
* **telemetry:** measure TOC clicks ([#9919](https://github.com/mdn/yari/issues/9919)) ([69a0276](https://github.com/mdn/yari/commit/69a02760b76e017bc7017252d9a60f598b154b56))

## [2.32.0](https://github.com/mdn/yari/compare/v2.31.0...v2.32.0) (2023-10-27)


Expand Down
2 changes: 1 addition & 1 deletion build/blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ export async function buildPost(
postProcessSmallerHeadingIDs($);
wrapTables($);
try {
const [sections] = extractSections($);
const [sections] = await extractSections($);
doc.body = sections;
} catch (error) {
console.error(
Expand Down
11 changes: 8 additions & 3 deletions build/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ async function buildDocuments(
cliProgress.Presets.shades_grey
);

const docPerLocale = {};
const docPerLocale: Record<string, { slug: string; modified: string }[]> = {};
const searchIndex = new SearchIndex();

if (!documents.count) {
Expand Down Expand Up @@ -307,12 +307,17 @@ async function buildDocuments(
}

for (const [locale, meta] of Object.entries(metadata)) {
const sortedMeta = meta
.slice()
.sort((a, b) => a.mdn_url.localeCompare(b.mdn_url));
fs.writeFileSync(
path.join(BUILD_OUT_ROOT, locale.toLowerCase(), "metadata.json"),
JSON.stringify(meta)
JSON.stringify(sortedMeta)
);
}

// allBrowserCompat.txt is used by differy, see:
// https://github.com/search?q=repo%3Amdn%2Fdiffery+allBrowserCompat&type=code
const allBrowserCompat = new Set<string>();
Object.values(metadata).forEach((localeMeta) =>
localeMeta.forEach(
Expand All @@ -322,7 +327,7 @@ async function buildDocuments(
);
fs.writeFileSync(
path.join(BUILD_OUT_ROOT, "allBrowserCompat.txt"),
[...allBrowserCompat].join(" ")
[...allBrowserCompat].sort().join(" ")
);

return { slugPerLocale: docPerLocale, peakHeapBytes, totalFlaws };
Expand Down
33 changes: 20 additions & 13 deletions build/extract-sections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { extractSpecifications } from "./extract-specifications.js";

type SectionsAndFlaws = [Section[], string[]];

export function extractSections($: cheerio.CheerioAPI): [Section[], string[]] {
export async function extractSections(
$: cheerio.CheerioAPI
): Promise<[Section[], string[]]> {
const flaws: string[] = [];
const sections: Section[] = [];
const section = cheerio
Expand All @@ -17,13 +19,13 @@ export function extractSections($: cheerio.CheerioAPI): [Section[], string[]] {
const iterable = [...(body.childNodes as cheerio.Element[])];

let c = 0;
iterable.forEach((child) => {
for (const child of iterable) {
if (
(child as cheerio.Element).tagName === "h2" ||
(child as cheerio.Element).tagName === "h3"
) {
if (c) {
const [subSections, subFlaws] = addSections(section.clone());
const [subSections, subFlaws] = await addSections(section.clone());
sections.push(...subSections);
flaws.push(...subFlaws);
section.empty();
Expand All @@ -35,10 +37,11 @@ export function extractSections($: cheerio.CheerioAPI): [Section[], string[]] {
// That might make the DOM nodes more compact and memory efficient.
c++;
section.append(child);
});
}

if (c) {
// last straggler
const [subSections, subFlaws] = addSections(section);
const [subSections, subFlaws] = await addSections(section);
sections.push(...subSections);
flaws.push(...subFlaws);
}
Expand Down Expand Up @@ -160,7 +163,9 @@ export function extractSections($: cheerio.CheerioAPI): [Section[], string[]] {
* specifications: {....}
* }]
*/
function addSections($: cheerio.Cheerio<cheerio.Element>): SectionsAndFlaws {
async function addSections(
$: cheerio.Cheerio<cheerio.Element>
): Promise<SectionsAndFlaws> {
const flaws: string[] = [];

const countPotentialSpecialDivs = $.find("div.bc-data, div.bc-specs").length;
Expand Down Expand Up @@ -215,7 +220,7 @@ function addSections($: cheerio.Cheerio<cheerio.Element>): SectionsAndFlaws {
const iterable = [...(div.childNodes as cheerio.Element[])];
let c = 0;
let countSpecialDivsFound = 0;
iterable.forEach((child) => {
for (const child of iterable) {
if (
child.tagName === "div" &&
child.attribs &&
Expand All @@ -237,13 +242,15 @@ function addSections($: cheerio.Cheerio<cheerio.Element>): SectionsAndFlaws {
// XXX That `_addSingleSpecialSection(section.clone())` might return a
// and empty array and that means it failed and we should
// bail.
subSections.push(..._addSingleSpecialSection(section.clone()));
subSections.push(
...(await _addSingleSpecialSection(section.clone()))
);
section.empty();
} else {
section.append(child);
c++;
}
});
}
if (c) {
const [proseSections, proseFlaws] = _addSectionProse(section.clone());
subSections.push(...proseSections);
Expand All @@ -258,7 +265,7 @@ function addSections($: cheerio.Cheerio<cheerio.Element>): SectionsAndFlaws {
}
return [subSections, flaws];
}
const specialSections = _addSingleSpecialSection($);
const specialSections = await _addSingleSpecialSection($);

// The _addSingleSpecialSection() function will have sucked up the <h2> or <h3>
// and the `div.bc-data` or `div.bc-specs` to turn it into a special section.
Expand All @@ -282,9 +289,9 @@ function addSections($: cheerio.Cheerio<cheerio.Element>): SectionsAndFlaws {
return [proseSections, flaws];
}

function _addSingleSpecialSection(
async function _addSingleSpecialSection(
$: cheerio.Cheerio<cheerio.Element>
): Section[] {
): Promise<Section[]> {
let id: string | null = null;
let title: string | null = null;
let isH3 = false;
Expand Down Expand Up @@ -347,7 +354,7 @@ function _addSingleSpecialSection(
},
];
} else if (specialSectionType === "specifications") {
const specifications = extractSpecifications(query, specURLsString);
const specifications = await extractSpecifications(query, specURLsString);

return [
{
Expand Down
56 changes: 25 additions & 31 deletions build/extract-specifications.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { packageBCD } from "./resolve-bcd.js";
import bcd from "@mdn/browser-compat-data/types";
import { Specification } from "../libs/types/document.js";
import specs from "web-specs/index.json" assert { type: "json" };
import web from "../kumascript/src/api/web.js";
import { getWebSpec } from "./web-specs.js";

export function extractSpecifications(
export async function extractSpecifications(
query: string | undefined,
specURLsString: string
): Specification[] {
): Promise<Specification[]> {
if (query === undefined && specURLsString === "") {
return [];
}
Expand Down Expand Up @@ -92,36 +92,30 @@ export function extractSpecifications(

// Use BCD specURLs to look up more specification data
// from the web-specs package
const specifications = specURLs
.map((specURL) => {
const spec = specs.find(
(spec) =>
specURL.startsWith(spec.url) ||
specURL.startsWith(spec.nightly.url) ||
spec.nightly.alternateUrls.some((s) => specURL.startsWith(s)) ||
// When grabbing series nightly, make sure we're grabbing the latest spec version
(spec.shortname === spec.series.currentSpecification &&
specURL.startsWith(spec.series.nightlyUrl))
);
const specificationsData = {
bcdSpecificationURL: specURL,
title: "Unknown specification",
};
if (spec) {
specificationsData.title = spec.title;
} else {
const specList = web.getJSONData("SpecData");
const titleFromSpecData = Object.keys(specList).find(
(key) => specList[key]["url"] === specURL.split("#")[0]
);
if (titleFromSpecData) {
specificationsData.title = titleFromSpecData;
const specifications = (
await Promise.all(
specURLs.map(async (specURL) => {
const spec = await getWebSpec(specURL);
const specificationsData = {
bcdSpecificationURL: specURL,
title: "Unknown specification",
};
if (spec) {
specificationsData.title = spec.title;
} else {
const specList = web.getJSONData("SpecData");
const titleFromSpecData = Object.keys(specList).find(
(key) => specList[key]["url"] === specURL.split("#")[0]
);
if (titleFromSpecData) {
specificationsData.title = titleFromSpecData;
}
}
}

return specificationsData;
})
.filter(Boolean);
return specificationsData;
})
)
).filter(Boolean);

return specifications;
}
23 changes: 8 additions & 15 deletions build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import path from "node:path";

import chalk from "chalk";
import * as cheerio from "cheerio";
import webFeatures from "web-features/index.json" assert { type: "json" };
import * as Sentry from "@sentry/node";

import {
Expand All @@ -12,7 +11,7 @@ import {
MacroRedirectedLinkError,
} from "../kumascript/src/errors.js";

import { Doc, WebFeature, WebFeatureStatus } from "../libs/types/document.js";
import { Doc, WebFeatureStatus } from "../libs/types/document.js";
import { Document, execGit, slugToFolder } from "../content/index.js";
import { CONTENT_ROOT, REPOSITORY_URLS } from "../libs/env/index.js";
import * as kumascript from "../kumascript/index.js";
Expand Down Expand Up @@ -44,6 +43,7 @@ import {
postProcessExternalLinks,
postProcessSmallerHeadingIDs,
} from "./utils.js";
import { getWebFeatureStatus } from "./web-features.js";
export { default as SearchIndex } from "./search-index.js";
export { gather as gatherGitHistory } from "./git-history.js";
export { buildSPAs } from "./spas.js";
Expand Down Expand Up @@ -380,7 +380,7 @@ export async function buildDocument(
browserCompat &&
(Array.isArray(browserCompat) ? browserCompat : [browserCompat]);

doc.baseline = addBaseline(doc);
doc.baseline = await addBaseline(doc);

// If the document contains <math> HTML, it will set `doc.hasMathML=true`.
// The client (<Document/> component) needs to know this for loading polyfills.
Expand Down Expand Up @@ -484,7 +484,7 @@ export async function buildDocument(
// section blocks are of type "prose" and their value is a string blob
// of HTML.
try {
const [sections, sectionFlaws] = extractSections($);
const [sections, sectionFlaws] = await extractSections($);
doc.body = sections;
if (sectionFlaws.length) {
injectSectionFlaws(doc, sectionFlaws, options);
Expand Down Expand Up @@ -558,18 +558,11 @@ export async function buildDocument(
return { doc: doc as Doc, liveSamples, fileAttachmentMap };
}

function addBaseline(doc: Partial<Doc>): WebFeatureStatus | undefined {
async function addBaseline(
doc: Partial<Doc>
): Promise<WebFeatureStatus | undefined> {
if (doc.browserCompat) {
for (const feature of Object.values<WebFeature>(webFeatures)) {
if (
feature.status &&
feature.compat_features?.some(
(query) => doc.browserCompat?.includes(query)
)
) {
return feature.status;
}
}
return await getWebFeatureStatus(...doc.browserCompat);
}
}

Expand Down
Loading

0 comments on commit 795cc5b

Please sign in to comment.