forked from ionic-team/ionic-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.mjs
87 lines (75 loc) · 2.51 KB
/
utils.mjs
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
import {unified} from 'unified';
import markdown from 'remark-parse';
import html from 'remark-html';
function renderMarkdown(markdownString) {
return unified().use(markdown).use(html).processSync(markdownString);
}
// a String equivalent to this component
// https://github.com/ionic-team/ionic-docs/blob/master/src/components/reference/reference.tsx
function renderReference(data, methodKeys) {
return `
${data
.map((item) => {
const { Head, ...keys } = methodKeys;
return `
### ${Head(item)}
${Object.keys(keys)
.map((name) => {
const content = keys[name](item);
if (content) {
return `
- \`${name}\`: ${content}
`;
}
})
.join(' ')}
`;
})
.join('')}
`;
}
function renderList(title, data) {
return `
${data
.map((item) => {
return `
### ${item.name}
${item.summary}
`;
})
.join('')}
`;
}
function renderOptions(title, data) {
return `
### ${title}
${data
.map((item) => {
const alias = item.aliases.length > 0 ? '(or ' + item.aliases.map((alias) => `\`-${alias}\``).join(' ') + ')' : '';
let name = item.type === 'boolean' && item.default === true ? `no-${item.name}` : item.name;
if (item.type === 'string') name += `=<${item.spec.value}>`;
return `
- \`--${name}\`: ${item.summary} ${alias}
`;
})
.join('')}
`;
}
function gitBranchSVG() {
return `<svg viewBox="0 0 512 512"><path d="M416 160c0-35.3-28.7-64-64-64s-64 28.7-64 64c0 23.7 12.9 44.3 32 55.4v8.6c0 19.9-7.8 33.7-25.3 44.9-15.4 9.8-38.1 17.1-67.5 21.5-14 2.1-25.7 6-35.2 10.7V151.4c19.1-11.1 32-31.7 32-55.4 0-35.3-28.7-64-64-64S96 60.7 96 96c0 23.7 12.9 44.3 32 55.4v209.2c-19.1 11.1-32 31.7-32 55.4 0 35.3 28.7 64 64 64s64-28.7 64-64c0-16.6-6.3-31.7-16.7-43.1 1.9-4.9 9.7-16.3 29.4-19.3 38.8-5.8 68.9-15.9 92.3-30.8 36-22.8 55-57 55-98.8v-8.6c19.1-11.1 32-31.7 32-55.4zM160 56c22.1 0 40 17.9 40 40s-17.9 40-40 40-40-17.9-40-40 17.9-40 40-40zm0 400c-22.1 0-40-17.9-40-40s17.9-40 40-40 40 17.9 40 40-17.9 40-40 40zm192-256c-22.1 0-40-17.9-40-40s17.9-40 40-40 40 17.9 40 40-17.9 40-40 40z"></path></svg>`;
}
function getHeadTag({ title: metaTitle, description: metaDescription } = {}) {
if (!metaTitle && !metaDescription) return '';
return `<head>
${metaTitle ? `<title>${metaTitle}</title>` : ''}
${metaDescription ? `<meta name="description" content="${metaDescription}" />` : ''}
</head>`;
}
export {
gitBranchSVG,
renderMarkdown,
renderReference,
renderOptions,
renderList,
getHeadTag,
};