Skip to content

Commit 7341a56

Browse files
committed
fix(biome): exclude translations
1 parent a7e02ab commit 7341a56

File tree

1 file changed

+48
-40
lines changed

1 file changed

+48
-40
lines changed

scripts/manual-docs-searches/biome-docs-search.js

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,59 +10,67 @@ function alfredMatcher(str) {
1010
return [camelCaseSeparated, str].join(" ") + " ";
1111
}
1212

13+
/** @param {string} url @return {string} */
14+
function httpRequest(url) {
15+
const queryURL = $.NSURL.URLWithString(url);
16+
const data = $.NSData.dataWithContentsOfURL(queryURL);
17+
return $.NSString.alloc.initWithDataEncoding(data, $.NSUTF8StringEncoding).js;
18+
}
19+
1320
//──────────────────────────────────────────────────────────────────────────────
1421

1522
/** @type {AlfredRun} */
1623
// biome-ignore lint/correctness/noUnusedVariables: Alfred run
1724
function run() {
1825
const docsUrl = "https://api.github.com/repos/biomejs/website/git/trees/main?recursive=1";
1926
const baseUrl = "https://biomejs.dev";
20-
const docPathRegex = /^src\/content\/docs\/(.*)\.mdx?$/i;
2127

22-
const workArray = JSON.parse(app.doShellScript(`curl -sL "${docsUrl}"`)).tree.map(
23-
(/** @type {{ path: string; }} */ entry) => {
24-
const path = entry.path;
28+
// `\w{3,}` excludes translations of the docs, which are in folders like
29+
// `/ja/` or `/zh-CN/` https://github.com/biomejs/website/tree/main/src/content/docs
30+
const docPathRegex = /^src\/content\/docs\/(\w{3,}.*)\.mdx?$/;
2531

26-
// GUARD
27-
const translatedDocs =
28-
path.includes("/zh-cn/") || path.includes("/ja/") || path.includes("/pt-br/");
29-
const isDocsSite = docPathRegex.test(path) && !path.endsWith("404.md");
30-
if (translatedDocs || !isDocsSite) return {};
32+
const response = JSON.parse(httpRequest(docsUrl));
33+
if (!response) return JSON.stringify({ items: [{ title: "Could not load.", valid: false }] });
3134

32-
const subsite = path.replace(docPathRegex, "$1");
33-
const parts = subsite.split("/");
34-
let title = parts.pop() || "??";
35-
let category = parts.join("/");
36-
let url = `${baseUrl}/${subsite}`;
35+
const workArray = response.tree.map((/** @type {{ path: string; }} */ entry) => {
36+
const path = entry.path;
37+
const [_, subsite] = path.match(docPathRegex) || [];
3738

38-
if (subsite.endsWith("index")) {
39-
title = category;
40-
category = "";
41-
url = `${baseUrl}/${subsite.slice(0, -5)}`;
42-
}
39+
if (!subsite) return {};
40+
if (path.endsWith("404.md")) return {};
4341

44-
if (category.endsWith("rules")) {
45-
// camelCase to conform to rule-casing the user expects
46-
title = title.replace(/-\w/g, (match) => match.slice(-1).toUpperCase());
47-
} else {
48-
// capitalize
49-
title = title.replaceAll("-", " ");
50-
title = title.charAt(0).toUpperCase() + title.slice(1); // capitalize
51-
}
42+
const parts = subsite.split("/");
43+
let title = parts.pop() || "??";
44+
let category = parts.join("/");
45+
let url = `${baseUrl}/${subsite}`;
5246

53-
return {
54-
title: title,
55-
subtitle: category,
56-
match: alfredMatcher(title),
57-
arg: url,
58-
mods: {
59-
cmd: { arg: title }, // copy entry
60-
},
61-
quicklookurl: url,
62-
uid: title,
63-
};
64-
},
65-
);
47+
if (subsite.endsWith("index")) {
48+
title = category;
49+
category = "";
50+
url = `${baseUrl}/${subsite.slice(0, -5)}`;
51+
}
52+
53+
if (category.endsWith("rules")) {
54+
// camelCase to conform to rule-casing the user expects
55+
title = title.replace(/-\w/g, (match) => match.slice(-1).toUpperCase());
56+
} else {
57+
// capitalize
58+
title = title.replaceAll("-", " ");
59+
title = title.charAt(0).toUpperCase() + title.slice(1); // capitalize
60+
}
61+
62+
return {
63+
title: title,
64+
subtitle: category,
65+
match: alfredMatcher(title),
66+
arg: url,
67+
mods: {
68+
cmd: { arg: title }, // copy entry
69+
},
70+
quicklookurl: url,
71+
uid: title,
72+
};
73+
});
6674

6775
return JSON.stringify({
6876
items: workArray,

0 commit comments

Comments
 (0)