create-refrakt 0.9.3 → 0.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,26 +1,21 @@
|
|
|
1
1
|
---
|
|
2
|
-
import '
|
|
3
|
-
import {
|
|
4
|
-
import manifest from '@refrakt-md/lumina/manifest';
|
|
5
|
-
import { layouts } from '@refrakt-md/lumina/layouts';
|
|
6
|
-
import { renderPage, buildSeoHead, hasInteractiveRunes } from '@refrakt-md/astro';
|
|
2
|
+
import { getTransform, getSite, getTheme, getHighlightTransform } from '../setup';
|
|
3
|
+
import { renderPage, buildSeoHead } from '@refrakt-md/astro';
|
|
7
4
|
import type { RendererNode } from '@refrakt-md/types';
|
|
8
5
|
|
|
9
|
-
const theme = { manifest, layouts };
|
|
10
|
-
|
|
11
6
|
export async function getStaticPaths() {
|
|
12
|
-
const [transform, site] = await Promise.all([getTransform(), getSite()]);
|
|
7
|
+
const [transform, site, hl] = await Promise.all([getTransform(), getSite(), getHighlightTransform()]);
|
|
13
8
|
|
|
14
9
|
return site.pages
|
|
15
10
|
.filter((p: any) => !p.route.draft)
|
|
16
11
|
.map((page: any) => {
|
|
17
|
-
const renderable = transform(page.renderable) as RendererNode;
|
|
12
|
+
const renderable = hl(transform(page.renderable)) as RendererNode;
|
|
18
13
|
const regions: Record<string, any> = {};
|
|
19
14
|
for (const [name, region] of page.layout.regions.entries()) {
|
|
20
15
|
regions[name] = {
|
|
21
16
|
name: region.name,
|
|
22
17
|
mode: region.mode,
|
|
23
|
-
content: region.content.map((c: any) => transform(c) as RendererNode),
|
|
18
|
+
content: region.content.map((c: any) => hl(transform(c)) as RendererNode),
|
|
24
19
|
};
|
|
25
20
|
}
|
|
26
21
|
|
|
@@ -47,15 +42,17 @@ export async function getStaticPaths() {
|
|
|
47
42
|
headings: page.headings,
|
|
48
43
|
},
|
|
49
44
|
seo: page.seo,
|
|
45
|
+
highlightCss: hl.css,
|
|
50
46
|
},
|
|
51
47
|
};
|
|
52
48
|
});
|
|
53
49
|
}
|
|
54
50
|
|
|
55
|
-
const { page, seo } = Astro.props;
|
|
51
|
+
const { page, seo, highlightCss } = Astro.props;
|
|
52
|
+
const theme = await getTheme();
|
|
56
53
|
const html = renderPage({ theme, page });
|
|
57
54
|
const head = buildSeoHead({ title: page.title, frontmatter: page.frontmatter, seo });
|
|
58
|
-
const needsBehaviors =
|
|
55
|
+
const needsBehaviors = html.includes('data-layout-behaviors') || html.includes('data-rune=');
|
|
59
56
|
const contextData = JSON.stringify({ pages: page.pages, currentUrl: page.url });
|
|
60
57
|
---
|
|
61
58
|
|
|
@@ -66,6 +63,7 @@ const contextData = JSON.stringify({ pages: page.pages, currentUrl: page.url });
|
|
|
66
63
|
{head.title && <title>{head.title}</title>}
|
|
67
64
|
<Fragment set:html={head.metaTags} />
|
|
68
65
|
<Fragment set:html={head.jsonLd} />
|
|
66
|
+
{highlightCss && <style set:html={highlightCss} />}
|
|
69
67
|
</head>
|
|
70
68
|
<body>
|
|
71
69
|
<Fragment set:html={html} />
|
|
@@ -9,13 +9,32 @@ import * as path from 'node:path';
|
|
|
9
9
|
const config: RefraktConfig = JSON.parse(readFileSync(path.resolve('refrakt.config.json'), 'utf-8'));
|
|
10
10
|
const contentDir = path.resolve(config.contentDir);
|
|
11
11
|
|
|
12
|
+
const routeRules = config.routeRules ?? [{ pattern: '**', layout: 'default' }];
|
|
13
|
+
|
|
12
14
|
let _transform: ((tree: any) => any) | null = null;
|
|
15
|
+
let _hl: { (tree: any): any; css: string } | null = null;
|
|
16
|
+
let _theme: { manifest: any; layouts: any } | null = null;
|
|
13
17
|
let _communityTags: Record<string, Schema> | undefined;
|
|
18
|
+
let _packages: any[] | undefined;
|
|
14
19
|
|
|
15
20
|
async function init() {
|
|
16
21
|
if (_transform) return;
|
|
17
22
|
|
|
18
|
-
const themeModule = await
|
|
23
|
+
const [themeModule, layoutsModule] = await Promise.all([
|
|
24
|
+
import(config.theme + '/transform'),
|
|
25
|
+
import(config.theme + '/layouts'),
|
|
26
|
+
]);
|
|
27
|
+
|
|
28
|
+
// Manifest is a JSON file — resolve its path and read directly
|
|
29
|
+
const { createRequire: cr } = await import('node:module');
|
|
30
|
+
const manifestPath = cr(import.meta.url).resolve(config.theme + '/manifest');
|
|
31
|
+
const manifest = JSON.parse(readFileSync(manifestPath, 'utf-8'));
|
|
32
|
+
|
|
33
|
+
_theme = {
|
|
34
|
+
manifest: { ...manifest, routeRules },
|
|
35
|
+
layouts: layoutsModule.layouts,
|
|
36
|
+
};
|
|
37
|
+
|
|
19
38
|
const themeConfig = themeModule.themeConfig ?? themeModule.luminaConfig ?? themeModule.default;
|
|
20
39
|
|
|
21
40
|
let transformConfig = themeConfig;
|
|
@@ -29,6 +48,7 @@ async function init() {
|
|
|
29
48
|
const merged = mergePackages(loaded, coreRuneNames, config.runes?.prefer);
|
|
30
49
|
|
|
31
50
|
_communityTags = Object.keys(merged.tags).length > 0 ? merged.tags : undefined;
|
|
51
|
+
_packages = loaded.map((l: any) => l.pkg);
|
|
32
52
|
|
|
33
53
|
const { config: assembledConfig } = assembleThemeConfig({
|
|
34
54
|
coreConfig: themeConfig,
|
|
@@ -50,7 +70,19 @@ export async function getTransform() {
|
|
|
50
70
|
return _transform!;
|
|
51
71
|
}
|
|
52
72
|
|
|
73
|
+
export async function getTheme() {
|
|
74
|
+
await init();
|
|
75
|
+
return _theme!;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function getHighlightTransform() {
|
|
79
|
+
if (_hl) return _hl;
|
|
80
|
+
const { createHighlightTransform } = await import('@refrakt-md/highlight');
|
|
81
|
+
_hl = await createHighlightTransform((config as any).highlight);
|
|
82
|
+
return _hl;
|
|
83
|
+
}
|
|
84
|
+
|
|
53
85
|
export async function getSite() {
|
|
54
86
|
await init();
|
|
55
|
-
return loadContent(contentDir, '/', {}, _communityTags);
|
|
87
|
+
return loadContent(contentDir, '/', {}, _communityTags, _packages);
|
|
56
88
|
}
|