Skip to content

Commit 9444421

Browse files
authored
Merge pull request #2688 from XRPLF/chore/migrate-to-realm-latest-with-perf
Upgrade to Realm v0.91.3 (copy of #2687)
2 parents faa08ed + e84ced0 commit 9444421

File tree

10 files changed

+444
-396
lines changed

10 files changed

+444
-396
lines changed

@i18n/ja/docs/tutorials/javascript/modular-tutorials/index.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

@i18n/ja/docs/tutorials/python/modular-tutorials/index.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

@theme/plugins/blog-posts.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,32 @@ import moment from "moment";
99
export function blogPosts() {
1010
/** @type {import("@redocly/realm/dist/server/plugins/types").PluginInstance } */
1111
const instance = {
12-
processContent: async (contentProvider, actions) => {
12+
processContent: async (actions, { fs, cache }) => {
1313
try {
1414
const posts = [];
15-
const allBlogFiles = Array.from(contentProvider.fsFilesList.values());
1615

17-
const markdownFiles = allBlogFiles.filter(file => file.match(/blog[\/\\]([^\\\/]*)[\/\\].*\.md$/));
16+
const allFiles = await fs.scan()
17+
const markdownFiles = allFiles
18+
.filter(file => file.relativePath
19+
.match(/^blog[\/\\]([^\\\/]*)[\/\\].*\.md$/));
1820

19-
for (const relativePath of markdownFiles) {
20-
const record = contentProvider.loadContent(relativePath, 'frontmatter');
21-
const ast = markdoc.parse(record.content);
21+
for (const { relativePath } of markdownFiles) {
22+
const { data: { ast } } = await cache.load(relativePath, 'markdown-ast');
23+
const { data: { frontmatter } } = await cache.load(relativePath, 'markdown-frontmatter');
2224

2325
const dirPath = dirname(relativePath);
2426
const title = extractFirstHeading(ast) || '';
25-
const category = extractCategory(record.parsed.data.labels);
27+
const category = extractCategory(frontmatter.labels);
2628
const year = `${relativePath.split("/")[1]}`
2729

2830
posts.push({
2931
path: dirPath,
30-
author: record.parsed.data.author || "",
32+
author: frontmatter.author || "",
3133
title: title || toTitleCase(dirname(dirPath)),
3234
description: getInnerText([ast.children[1]]).replace(title, '').trim(),
3335
year: year,
34-
date: record.parsed.data.date
35-
? moment(record.parsed.data.date).format("YYYY-MM-DD")
36+
date: frontmatter.date
37+
? moment(frontmatter.date).format("YYYY-MM-DD")
3638
: moment(year).format("YYYY-MM-DD"),
3739
category: category || "General",
3840
category_id: category ? category.toLowerCase().replace(/ /g, "_") : "general",

@theme/plugins/code-samples.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,45 @@
33
import { getInnerText } from '@redocly/realm/dist/shared/markdoc.js';
44

55
import { dirname, relative, join as joinPath } from 'path';
6-
import markdoc from '@markdoc/markdoc';
76

87
export function codeSamples() {
98
/** @type {import("@redocly/realm/dist/server/plugins/types").PluginInstance } */
109
const instance = {
11-
processContent: async (contentProvider, actions) => {
10+
processContent: async (actions, { fs, cache }) => {
1211
try {
1312
const samples = [];
1413
const allLands = new Set();
15-
const allCodeSampleFiles = Array.from(contentProvider.fsFilesList.values());
14+
const allCodeSampleFiles = await fs.scan();
1615

17-
const readmes = allCodeSampleFiles.filter(file => file.match(/_code-samples[\/\\]([^\\\/]*)[\/\\]README\.md$/));
16+
const readmes = allCodeSampleFiles.filter((file) => file.relativePath.match(/^_code-samples[\/\\]([^\\\/]*)[\/\\]README\.md$/));
1817

19-
for (const relativePath of readmes) {
20-
const record = contentProvider.loadContent(relativePath, 'frontmatter');
18+
for (const { relativePath } of readmes) {
19+
const { data } = await cache.load(relativePath, 'markdown-ast');
2120

22-
const ast = markdoc.parse(record.content);
23-
24-
const dirPath = dirname(relativePath)
21+
const dirPath = dirname(relativePath);
2522
const langs = unique(
2623
allCodeSampleFiles
27-
.filter(file => file.startsWith(dirPath) && !file.endsWith('README.md'))
28-
.map(file => relative(dirPath, file).split('/')[0])
24+
.filter((file) => file.relativePath.startsWith(dirPath) && !file.relativePath.endsWith('README.md'))
25+
.map((file) => relative(dirPath, file.relativePath).split('/')[0])
2926
);
30-
const title = extractFirstHeading(ast) || '';
27+
const title = extractFirstHeading(data.ast) || '';
3128
samples.push({
3229
path: dirPath,
3330
title: title || toTitleCase(dirname(dirPath)),
34-
description: getInnerText([ast.children[1]]).replace(title, '').trim(),
31+
description: getInnerText([data.ast.children[1]]).replace(title, '').trim(),
3532
href: joinPath('content', dirPath),
3633
langs,
3734
});
3835

39-
langs.forEach(l => allLands.add(l));
36+
langs.forEach((l) => allLands.add(l));
4037
}
4138

4239
const sortedSamples = samples.sort((a, b) => normalizeTitleForSort(a).localeCompare(normalizeTitleForSort(b)));
4340

44-
actions.createSharedData('code-samples', { codeSamples: sortedSamples, langs: Array.from(allLands) });
41+
actions.createSharedData('code-samples', {
42+
codeSamples: sortedSamples,
43+
langs: Array.from(allLands),
44+
});
4545
actions.addRouteSharedData('/resources/code-samples/', 'code-samples', 'code-samples');
4646
actions.addRouteSharedData('/ja/resources/code-samples/', 'code-samples', 'code-samples');
4747
} catch (e) {
@@ -64,8 +64,8 @@ const WORDS_TO_CAPS = ['xrp'];
6464
function toTitleCase(s) {
6565
const words = s.split(/_|[^\w']/);
6666
return words
67-
.filter(word => word)
68-
.map(word => (WORDS_TO_CAPS.includes(word) ? word.toUpperCase() : word.charAt(0).toUpperCase() + word.slice(1)))
67+
.filter((word) => word)
68+
.map((word) => (WORDS_TO_CAPS.includes(word) ? word.toUpperCase() : word.charAt(0).toUpperCase() + word.slice(1)))
6969
.join(' ')
7070
.replace("'S", "'s")
7171
.replace(' A ', ' a ');
@@ -78,7 +78,7 @@ function unique(array) {
7878
function extractFirstHeading(ast) {
7979
let heading;
8080

81-
visit(ast, node => {
81+
visit(ast, (node) => {
8282
if (!isNode(node)) {
8383
return;
8484
}

@theme/plugins/index-pages.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ export function indexPages() {
66
/** @type {import("@redocly/realm/dist/server/plugins/types").PluginInstance } */
77
const instance = {
88
// hook that gets executed after all routes were created
9-
async afterRoutesCreated(contentProvider, actions) {
9+
async afterRoutesCreated(actions, { cache }) {
1010
// get all the routes that are ind pages
11-
const indexRoutes = actions.getAllRoutes().filter(route => route.metadata?.indexPage);
11+
const indexRoutes = actions
12+
.getAllRoutes()
13+
.filter((route) => route.metadata?.indexPage);
1214

1315
for (const route of indexRoutes) {
1416
// @ts-ignore this uses some internals, we will expose them in nicer way in the future releases
@@ -22,27 +24,38 @@ export function indexPages() {
2224
}
2325

2426
const item = findItemDeep(sidebar.items, route.fsPath);
25-
const childrenPaths = (item.items || []).map(item => item.fsPath).filter(Boolean);
27+
const childrenPaths = (item.items || [])
28+
.map((item) => item.fsPath)
29+
.filter(Boolean);
2630

27-
const childRoutes = childrenPaths.map(fsPath => actions.getRouteByFsPath(fsPath));
31+
const childRoutes = childrenPaths.map((fsPath) =>
32+
actions.getRouteByFsPath(fsPath),
33+
);
2834
const childRoutesData = await Promise.all(
29-
childRoutes.map(async route => {
30-
const { parsed } = contentProvider.loadContent(route.fsPath, 'frontmatter');
35+
childRoutes.map(async (route) => {
36+
const { data } = await cache.load(
37+
route.fsPath,
38+
'markdown-frontmatter',
39+
);
3140
const slug = route.slug;
3241
const title = await route.getNavText();
3342
return {
34-
...parsed?.data,
43+
...data?.frontmatter,
3544
slug,
3645
title,
3746
};
38-
})
47+
}),
3948
);
4049

4150
const sharedDataId = await actions.createSharedData(
4251
route.slug + '_' + INDEX_PAGE_INFO_DATA_KEY,
43-
childRoutesData
52+
childRoutesData,
53+
);
54+
actions.addRouteSharedData(
55+
route.slug,
56+
INDEX_PAGE_INFO_DATA_KEY,
57+
sharedDataId,
4458
);
45-
actions.addRouteSharedData(route.slug, INDEX_PAGE_INFO_DATA_KEY, sharedDataId);
4659
}
4760
},
4861
};

0 commit comments

Comments
 (0)