forked from keepandroidopen/keepandroidopen.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegulators.astro
More file actions
76 lines (67 loc) · 2.25 KB
/
Copy pathRegulators.astro
File metadata and controls
76 lines (67 loc) · 2.25 KB
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
---
import { resolve } from '../i18n/resolve';
import { marked } from 'marked';
import regulators from '../data/regulators.yaml';
interface Props {
locale: string;
}
const { locale } = Astro.props;
/** Parse inline markdown and add target="_blank" to http/https links */
function renderInline(md: string): string {
let html = marked.parseInline(md) as string;
html = html.replace(/<a href="(https?:\/\/[^"]*)">/g, '<a href="$1" target="_blank">');
return html;
}
/** Parse block markdown and add target="_blank" to http/https links */
function renderBlock(md: string): string {
let html = marked.parse(md) as string;
html = html.replace(/<a href="(https?:\/\/[^"]*)">/g, '<a href="$1" target="_blank">');
return html;
}
const countries = regulators.countries.filter((c: any) =>
!c.locales || c.locales.includes(locale)
);
// Korean locale puts South Korea first
const orderedCountries = locale === 'ko'
? [
...countries.filter((c: any) => c.id === 'south-korea'),
...countries.filter((c: any) => c.id !== 'south-korea'),
]
: countries;
---
<h3 id="consumers">{resolve(regulators.heading, locale)}</h3>
<Fragment set:html={renderBlock(resolve(regulators.intro, locale))} />
<Fragment set:html={renderBlock(resolve(regulators.follow_up, locale))} />
{orderedCountries.map((country: any) => {
const items = country.items.filter((item: any) =>
!item.locales || item.locales.includes(locale)
);
const children = (country.children || []).filter((c: any) =>
!c.locales || c.locales.includes(locale)
);
return (
<details id={country.id}>
<summary><h4>{resolve(country.name, locale)}</h4></summary>
<ul>
{items.map((item: any) => (
<li set:html={renderInline(resolve(item.text, locale))} />
))}
</ul>
{children.map((child: any) => {
const childItems = child.items.filter((item: any) =>
!item.locales || item.locales.includes(locale)
);
return (
<>
<h5 id={child.id}>{resolve(child.name, locale)}</h5>
<ul>
{childItems.map((item: any) => (
<li set:html={renderInline(resolve(item.text, locale))} />
))}
</ul>
</>
);
})}
</details>
);
})}