-
Notifications
You must be signed in to change notification settings - Fork 534
/
Permissions.astro
49 lines (40 loc) · 1.04 KB
/
Permissions.astro
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
---
/**
* Usage:
* <Permissions plugin="authenticator" />
*/
import { createMarkdownProcessor } from '@astrojs/markdown-remark';
import fs from 'fs/promises';
import path from 'path';
import { fileURLToPath } from 'url';
interface Props {
plugin: string;
}
const { plugin } = Astro.props;
async function importMDX(p: string): Promise<string> {
console.log(import.meta.url)
const base = fileURLToPath(import.meta.url);
const dirname = path.dirname(base);
const dir = path.join(
dirname,
'../../packages/plugins-workspace/plugins',
p,
'permissions/autogenerated',
'reference.md'
);
try {
const content = await fs.readFile(dir, 'utf-8');
return content;
} catch (err) {
console.error(`Error reading file ${dir}: ${err}`);
throw err;
}
}
const md = await createMarkdownProcessor();
const pageContent: string = await importMDX(plugin);
const content = await md.render(pageContent);
const code = `<code dir="auto">${plugin}: </code>`;
const prefix = `Prefix: ${code}`;
---
<p set:html={prefix} />
<Fragment set:html={content.code} />