Skip to content

Commit

Permalink
Update Permissions.astro
Browse files Browse the repository at this point in the history
  • Loading branch information
vasfvitor committed Jun 24, 2024
1 parent 55c3855 commit c44291f
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions src/components/Permissions.astro
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
* <Permissions plugin="authenticator" />
*/
import type { MarkdownInstance } from 'astro';
import { createMarkdownProcessor } from '@astrojs/markdown-remark';
import fs from 'fs/promises';
import path from 'path';
import { fileURLToPath } from 'url';
interface Props {
plugin: string;
Expand All @@ -13,14 +16,34 @@ interface Props {
const { plugin } = Astro.props;
async function importMDX(p: string): Promise<string> {
/* @vite-ignore */
// Apparently, this is working, but Vite is complaining https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#limitations
const dir = `../../packages/plugins-workspace/plugins/${p}/permissions/autogenerated/reference.md`;
return import(dir).then((a: MarkdownInstance<String>) => {
return a.compiledContent();
});
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}`;
---

<Fragment set:html={pageContent} />
<p set:html={prefix} />
<Fragment set:html={content.code} />

0 comments on commit c44291f

Please sign in to comment.