Skip to content

Commit 49fed51

Browse files
committed
the great typeinfo unfuckening
1 parent db63f56 commit 49fed51

File tree

15 files changed

+236
-368
lines changed

15 files changed

+236
-368
lines changed

src/components/Header.astro

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,18 @@
11
---
22
import { ThemeSelect } from "@components/hooks/ThemeSwitch";
3-
import { getTypeData } from "@config/io/generateTypeData";
3+
import type { TypeData } from "@config/io/types";
44
import Nav from "@components/navigation/sidebars/nav/index.astro";
55
import TOC from "@components/navigation/sidebars/TOC.astro";
6-
import type { TypeTOC } from "./navigation/sidebars/types";
6+
import type { ConfigHeading } from "@components/navigation/sidebars/types";
77
import Search from "./navigation/Search.astro";
88
9-
const routes = await getTypeData();
10-
11-
const url = Astro.url.pathname.split("/");
12-
const currentClass = url[4];
13-
const currentData = routes.find(
14-
item => item.name === currentClass
15-
);
16-
17-
const data = currentData?.data;
18-
const tocFunctions =
19-
data?.functions?.map(item => item.name) || null;
20-
21-
const propsKeys = data?.properties
22-
? Object.keys(data.properties)
23-
: null;
24-
const signalKeys = data?.signals
25-
? Object.keys(data.signals)
26-
: null;
27-
const variantKeys = data?.variants
28-
? Object.keys(data.variants)
29-
: null;
30-
31-
let sidebarData: TypeTOC | undefined = {
32-
properties: propsKeys,
33-
functions: tocFunctions,
34-
signals: signalKeys,
35-
variants: variantKeys,
36-
};
37-
38-
if (!data) {
39-
sidebarData = undefined;
9+
interface Props {
10+
title?: string;
11+
headings?: ConfigHeading[];
12+
type?: TypeData;
4013
}
4114
42-
const {
43-
title = null,
44-
headings = [],
45-
} = Astro.props;
15+
const { title, headings, type } = Astro.props;
4616
---
4717
<div class="header">
4818
<div class="header-item header-left">
@@ -54,6 +24,6 @@ const {
5424
<div class="header-item header-right">
5525
<Search/>
5626
<ThemeSelect client:load />
57-
<TOC title={title} headings={headings} types={sidebarData} mobile={true}/>
27+
<TOC title={title} headings={headings} type={type} mobile={true}/>
5828
</div>
5929
</div>

src/components/navigation/sidebars/TOC.astro

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
---
22
import TableOfContents from "./toc";
33
import type { ConfigHeading, TypeTOC } from "./types.d.ts";
4+
import type { TypeData } from "@config/io/types";
45
56
export interface Props {
67
title?: string;
78
headings?: ConfigHeading[];
8-
types?: TypeTOC;
9+
type?: TypeData;
910
mobile: boolean;
1011
}
1112
12-
const { title, headings, types, mobile } = Astro.props;
13+
const { title, headings, type, mobile } = Astro.props;
14+
15+
const types: TypeTOC | null = type ? {
16+
properties: Object.keys(type.properties ?? {}),
17+
functions: (type.functions ?? []).map(f => f.name),
18+
signals: Object.keys(type.signals ?? {}),
19+
variants: Object.keys(type.variants ?? {}),
20+
} : null;
1321
---
1422
{((headings?.length ?? 0) != 0 || types) &&
1523
<div id="toc" aria-mobile={mobile} class=`toc-wrapper${mobile ? "-mobile":""}`>

src/components/navigation/sidebars/nav/RootNav.astro

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@ export interface Props {
77
88
const { currentRoute, currentModule, currentClass } = Astro.props;
99
10-
import { getTypeData } from "@config/io/generateTypeData";
11-
import { groupRoutes } from "@config/io/helpers";
10+
import { getModulesData } from "@config/io/generateTypeData";
1211
import type { TreeEntry } from "./Tree.astro";
1312
import Tree from "./Tree.astro";
1413
import Link from "./Link.astro";
1514
import VersionSelector from "./VersionSelector.astro"
1615
17-
const routes = await getTypeData();
18-
const groupedRoutes = groupRoutes(routes);
16+
const modules = await getModulesData();
1917
2018
import { getCollection } from "astro:content";
2119
const guidePages = await getCollection("guide");
@@ -45,18 +43,16 @@ const types = {
4543
title: "Quickshell Types",
4644
link: "/docs/types",
4745
current: currentRoute?.startsWith("types") ?? false,
48-
entries: Object.entries(groupedRoutes.types).map(
49-
([module, items]) => ({
50-
title: module,
51-
link: `/docs/types/${module}`,
52-
current: currentModule === module,
53-
entries: items.map(type => ({
54-
title: type.name,
55-
link: `/docs/types/${module}/${type.name}`,
56-
current: currentClass === type.name,
57-
})),
58-
})
59-
),
46+
entries: modules.map(module => ({
47+
title: module.name,
48+
link: `/docs/types/${module.name}`,
49+
current: currentModule === module.name,
50+
entries: module.types.map(type => ({
51+
title: type.name,
52+
link: `/docs/types/${module.name}/${type.name}`,
53+
current: currentClass === type.name,
54+
}))
55+
}))
6056
};
6157
6258
---

src/components/type/Properties.astro

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,20 @@ import type {
44
QMLTypeLinkObject,
55
QuickshellProps,
66
} from "@config/io/types";
7-
import { Tag, Flag } from "@icons";
7+
import { Tag } from "@icons";
88
import TypeTitle from "./TypeTitle.astro";
99
1010
import TypeDetails from "./TypeDetails.astro";
1111
1212
export interface Props {
13-
propsKeys: string[];
14-
propsData: QuickshellProps;
13+
props: QuickshellProps;
1514
}
1615
17-
const { propsKeys, propsData } = Astro.props;
16+
const { props } = Astro.props;
1817
---
1918
<ul class="typedata typeprops">
2019
{
21-
propsKeys.map(item => {
22-
const propData = propsData[item]
20+
Object.entries(props).map(([name, propData]) => {
2321
let typeLink:string;
2422
let linkText:string;
2523
let genericType:string|undefined;
@@ -37,10 +35,10 @@ const { propsKeys, propsData } = Astro.props;
3735
genericTypeLink = getQMLTypeLink(propData.type.of)
3836
}
3937
return (
40-
<li id={ item } class="typedata-root typeprop-root">
38+
<li id={ name } class="typedata-root typeprop-root">
4139
<TypeTitle
4240
typekind="prop"
43-
typename={item}
41+
typename={name}
4442
typelink={typeLink}
4543
typelink_text={linkText}
4644
typename_generic={genericType}

src/components/type/Signals.astro

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
11
---
22
import type { QuickshellSignal } from "@config/io/types";
3-
import { Tag, PowerCord } from "@icons";
3+
import { Tag } from "@icons";
44
import TypeDetails from "./TypeDetails.astro";
55
import TypeTitle from "./TypeTitle.astro";
66
77
export interface Props {
8-
signalKeys: string[];
9-
signalsData: QuickshellSignal;
8+
signals: QuickshellSignal;
109
}
1110
12-
const { signalKeys, signalsData } = Astro.props;
11+
const { signals } = Astro.props;
1312
---
1413
<ul class="typedata typesignals">
1514
{
16-
signalKeys.map(item => {
17-
const signalData = signalsData[item];
15+
Object.entries(signals).map(([name, signalData]) => {
1816
const paramKeys = signalData.params.length > 0 ? signalData.params.map((param,index) => `${param.name}${index !== signalData.params.length -1 ? ", ":""}`) : []
1917
let genericType:string|undefined;
2018
let genericTypeLink:string|undefined;
2119
return (
22-
<li id={ item } class="typedata-root typesignal-root">
20+
<li id={ name } class="typedata-root typesignal-root">
2321
<TypeTitle
2422
typekind="signal"
25-
typename={item}
23+
typename={name}
2624
typelink="/docs/configuration/qml-overview#-signals"
27-
typelink_text={"?"}
25+
typelink_text=""
2826
typename_generic={genericType}
2927
typelink_generic={genericTypeLink}
3028
typedata_params={paramKeys}

src/components/type/Variants.astro

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
11
---
22
import type { QuickshellVariant } from "@config/io/types";
3-
import { FourDiamonds } from "../icons";
43
import TypeDetails from "./TypeDetails.astro";
54
import TypeTitle from "./TypeTitle.astro";
65
76
export interface Props {
8-
variantKeys: string[];
9-
variantsData: QuickshellVariant;
7+
variants: QuickshellVariant;
108
}
119
12-
const { variantKeys, variantsData } = Astro.props;
10+
const { variants } = Astro.props;
1311
---
1412
<ul class="typedata typevariants">
1513
{
16-
variantKeys.map(item => {
17-
const variantData = variantsData[item];
14+
Object.entries(variants).map(([name, variantData]) => {
1815
const paramKeys = variantData.params && variantData.params.length > 0
1916
? variantData.params.map(param => param.name)
2017
: [];
2118
return (
22-
<li id={ item } class="typedata-root typevariant-root">
19+
<li id={ name } class="typedata-root typevariant-root">
2320
<TypeTitle
2421
typekind="variant"
25-
typename={item}
22+
typename={name}
2623
typelink=""
2724
typelink_text=""
2825
/>

src/config/io/generateTypeData.ts

Lines changed: 36 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,41 @@
11
import { promises as fs } from "node:fs";
22
import path from "node:path";
33

4-
import type { RouteData, dirData } from "./types";
5-
6-
async function readSubdir(basePath: string, subdir: string): Promise<dirData[]> {
7-
const fullpath = path.join(basePath, subdir);
8-
const filenames = await fs.readdir(fullpath);
9-
10-
const data = await Promise.all(
11-
filenames.map(async filename => {
12-
const filepath = path.join(fullpath, filename);
13-
const content = await fs.readFile(filepath, "utf8");
14-
const data = JSON.parse(content);
15-
if (typeof data.module === "undefined") {
16-
data.module = "index";
17-
data.contains = filenames
18-
.filter(filename => filename !== "index.json")
19-
.map(filename => filename.replace(".json", ""));
20-
}
21-
const returnValue = {
22-
fullpath: path.join(fullpath, filename),
23-
filename: filename.replace(".json", ""),
24-
category: subdir,
25-
data: data,
26-
};
27-
return returnValue;
28-
})
29-
);
30-
return data;
31-
}
4+
import type { VersionsData, ModuleData } from "./types";
5+
6+
async function readModulesData(basePath: string): Promise<ModuleData[]> {
7+
const moduleDirs = await fs.readdir(basePath);
8+
9+
const modules = await Promise.all(moduleDirs.map(async moduleDir => {
10+
const modulePath = path.join(basePath, moduleDir);
11+
12+
const indexPromise = async () => {
13+
const indexPath = path.join(modulePath, "index.json");
14+
const indexContent = await fs.readFile(indexPath, "utf8");
15+
return JSON.parse(indexContent);
16+
};
3217

33-
async function generateTypeData(basePath: string): Promise<RouteData[]> {
34-
const subdirs = await fs.readdir(basePath, {
35-
withFileTypes: true,
36-
});
37-
const routes: RouteData[] = [];
38-
39-
for (const subdir of subdirs) {
40-
const data = await readSubdir(basePath, subdir.name);
41-
const returnValue = data.map(entry => {
42-
return {
43-
type: entry.category,
44-
name: entry.filename,
45-
path: entry.fullpath,
46-
data: entry.data,
47-
};
18+
const typeNames = (await fs.readdir(modulePath)).filter(name => name !== "index.json");
19+
const typePromises = typeNames.map(async fileName => {
20+
const typePath = path.join(modulePath, fileName);
21+
const fileContent = await fs.readFile(typePath, "utf8");
22+
return JSON.parse(fileContent);
4823
});
49-
routes.push(...returnValue);
50-
}
51-
return routes;
24+
25+
const [index, ...types] = await Promise.all([indexPromise(), ...typePromises]);
26+
27+
return {
28+
name: index.name,
29+
description: index.description,
30+
details: index.details,
31+
types,
32+
}
33+
}));
34+
35+
return modules;
5236
}
5337

54-
async function generateVersionsData(): Promise<VersionsData> {
38+
async function readVersionsData(): Promise<VersionsData> {
5539
const versionsPath = import.meta.env.VERSION_FILE_PATH;
5640

5741
if (!versionsPath || versionsPath === "") {
@@ -63,9 +47,9 @@ async function generateVersionsData(): Promise<VersionsData> {
6347
const content = await fs.readFile(versionsPath, "utf8");
6448
const data = JSON.parse(content);
6549

66-
const versions = await Promise.all(data.versions.map(async d => ({
50+
const versions = await Promise.all(data.versions.map(async (d: { name: string, types: any }) => ({
6751
name: d.name,
68-
modules: await generateTypeData(d.types),
52+
modules: await readModulesData(d.types),
6953
})))
7054

7155
return {
@@ -78,13 +62,13 @@ let globalVersionsData: Promise<VersionsData>;
7862

7963
export function getVersionsData(): Promise<VersionsData> {
8064
if (!globalVersionsData) {
81-
globalVersionsData = generateVersionsData();
65+
globalVersionsData = readVersionsData();
8266
}
8367

8468
return globalVersionsData;
8569
}
8670

87-
export async function getTypeData(): RouteData[] {
71+
export async function getModulesData(): Promise<ModuleData[]> {
8872
const versions = await getVersionsData();
89-
return versions.versions.find(v => v.name == versions.default).modules;
73+
return versions.versions.find(v => v.name == versions.default)!.modules;
9074
}

0 commit comments

Comments
 (0)