forked from NEARBuilders/bos-workspace-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
145 lines (131 loc) · 3.75 KB
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// const { normalize } = VM.require("${alias_devs}/widget/lib.stringUtils") || {
// normalize: (str) => str,
// };
/**
* Transform input into a consistent and standardized format
*
* @param {string} text - The input to normalize.
* @param {string} delimiter - The delimiter to use between words.
* @returns {string} - normalized input
*/
const normalize = (text, delimiter) => {
// If no delimiter is provided, default to an underscore
delimiter = delimiter || "-";
return (
text
// Convert to lowercase
.toLowerCase()
// Replace spaces with dashes
.replace(/\s+/g, delimiter)
// Replace any non-alphanumeric characters (excluding dashes) with nothing
.replace(`/[^a-z0-9${delimiter}]/g`, "")
// Replace multiple consecutive dashes with a single dash
.replace(`/${delimiter}+/g`, "-")
// Trim dashes from the start and end of the string
.replace(`/^${delimiter}+|${delimiter}+$/g`, "")
);
};
let github = VM.require("${config_account}/widget/PR.adapter.github") || {
github: () => {},
};
const data = {
"": JSON.stringify({
title: "My Documentation",
sections: [
{
title: "Getting Started",
content: "",
subsections: [
{
title: "Migration Guide",
content: "# Instructions for installing the software.",
},
{
title: "Installation",
content: "# Instructions for installing the software.",
},
{
title: "Setup",
content: "Guidelines for setting up the environment.",
},
],
},
{
title: "Usage",
content: "Hello 2",
subsections: [
{
title: "Aliases",
content: "Instructions for basic usage.",
},
{
title: "Deploy",
content: "Instructions for advanced usage.",
},
],
},
{
title: "Examples",
content: "Hello 3",
subsections: [
{
title: "Example 1",
content: "Description and usage of Example 1.",
},
{
title: "Example 2",
content: "Description and usage of Example 2.",
},
],
},
{
title: "Blocks",
content: {},
subsections: [
{
title: "Template",
content: "Description and usage of Example 1.",
},
],
},
],
}),
metadata: {
name: "bos-workspace",
description: `bos-workspace is a comprehensive toolset designed to simplify the
development and deployment of NEAR components and applications. With
support for hot reload, TypeScript, and multiple app management, it caters
to developers looking for an efficient and scalable developer environment.`,
},
};
const documentation = JSON.parse(data[""] || "null");
const contentMap = {};
// Iterate over sections and subsections to populate content map
documentation.sections.forEach((section) => {
const sectionPath = normalize(section.title, "_");
contentMap[sectionPath] = { title: section.title, content: section.content };
section.subsections.forEach((subsection) => {
const subsectionPath = `${sectionPath}/${normalize(subsection.title, "_")}`;
contentMap[subsectionPath] = {
title: subsection.title,
content: subsection.content,
};
});
});
return {
get: (params) => {
if (params) {
let path = params.path;
let parts = path.split("/");
if (parts.length === 1) {
parts.push("index");
path = parts.join("/");
}
return github.get(path + ".md");
}
return contentMap; // index
},
create: (k, v) => {
console.log("create");
},
};