Skip to content

Commit 0154c56

Browse files
authored
Projects top navigation (#590)
1 parent 2fdba67 commit 0154c56

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+697
-274
lines changed

global.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ declare module "solid:collection/tree" {
44
export default tree;
55
}
66

7-
declare module "solid:collection/entries" {
8-
import entries from ".solid/entries";
7+
declare module "solid:collection/flat-entries" {
8+
import entries from ".solid/flat-entries";
99
// eslint-disable-next-line
1010
export default entries;
1111
}

scripts/collections/index.mjs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { createI18nEntries } from "../create-i18n-entries.mjs";
66
import { createI18nTree } from "../create-i18n-tree.mjs";
77

88
export const languages = ["pt-br"];
9+
const projects = ["solid-router"];
910
export const COLLECTIONS_ROOT = "src/routes";
1011

1112
(async () => {
@@ -16,6 +17,44 @@ export const COLLECTIONS_ROOT = "src/routes";
1617
learn: createFlatEntryList(tree.learn, []),
1718
reference: createFlatEntryList(tree.reference, []),
1819
};
20+
const projectTrees = {};
21+
const projectFlatEntries = {};
22+
23+
for (const project of projects) {
24+
projectTrees[project] = await createNavTree(
25+
`${COLLECTIONS_ROOT}/${project}`
26+
);
27+
28+
projectFlatEntries[project] = {
29+
learn: await createFlatEntryList(projectTrees[project].learn, []),
30+
reference: await createFlatEntryList(projectTrees[project].reference, []),
31+
};
32+
33+
writeFile(`${project}-tree.ts`, projectTrees[project]);
34+
writeFile(`${project}-flat-entries.ts`, projectFlatEntries[project]);
35+
36+
for (const locale of languages) {
37+
const entryTitles = await createI18nEntries(
38+
projectFlatEntries[project],
39+
locale,
40+
project
41+
);
42+
43+
writeFile(`${project}-flat-entries-${locale}.ts`, entryTitles);
44+
writeFile(`${project}-tree-${locale}.ts`, {
45+
learn: await createI18nTree(
46+
projectTrees[project].learn,
47+
locale,
48+
project
49+
),
50+
reference: await createI18nTree(
51+
projectTrees[project].reference,
52+
locale,
53+
project
54+
),
55+
});
56+
}
57+
}
1958

2059
for (const locale of languages) {
2160
const entryTitles = await createI18nEntries(defaultFlatEntries, locale);
@@ -29,6 +68,9 @@ export const COLLECTIONS_ROOT = "src/routes";
2968
await Promise.all([
3069
writeFile("tree.ts", tree),
3170
writeFile("entriesList.js", defaultFlatEntries, true),
32-
writeFile("entries.ts", defaultFlatEntries),
71+
writeFile("flat-entries.ts", defaultFlatEntries),
72+
Object.keys(projectTrees).forEach((project) =>
73+
writeFile(`${project}-entries.ts`, projectTrees[project])
74+
),
3375
]);
3476
})();

scripts/create-i18n-entries.mjs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ import { getFrontMatterData } from "./collections/utils/get-frontamtter.mjs";
2121
/**
2222
*
2323
* @param {DocsEntry[]} entryList
24+
* @param {string} locale
25+
* @param {string | undefined} project
2426
*/
25-
async function buildSectionList(entryList = [], locale) {
27+
async function buildSectionList(entryList = [], locale, project = "") {
2628
const sectionList = [];
2729

2830
for (const entry of entryList) {
@@ -32,6 +34,7 @@ async function buildSectionList(entryList = [], locale) {
3234
const i18nEntryPath = path.join(
3335
process.cwd(),
3436
COLLECTIONS_ROOT,
37+
project,
3538
locale,
3639
entryPath
3740
);
@@ -58,11 +61,12 @@ async function buildSectionList(entryList = [], locale) {
5861
/**
5962
* @param {DefaultEntries} defaultEntries
6063
* @param {string} locale
64+
* @param {string} project
6165
*/
62-
export async function createI18nEntries(defaultEntries, locale) {
66+
export async function createI18nEntries(defaultEntries, locale, project) {
6367
const referenceLearn = await Promise.all([
64-
buildSectionList(defaultEntries.learn, locale),
65-
buildSectionList(defaultEntries.reference, locale),
68+
buildSectionList(defaultEntries.learn, locale, project),
69+
buildSectionList(defaultEntries.reference, locale, project),
6670
]);
6771

6872
return {

scripts/create-i18n-tree.mjs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ function traverseTree(children) {
4848
*
4949
* @param {Tree["reference" | "learn"]} entryList
5050
* @param {string} locale
51+
* @param {string | undefined} project
5152
*/
52-
export async function createI18nTree(entryList, locale) {
53+
export async function createI18nTree(entryList, locale, project = "") {
5354
const entries = [];
5455

5556
for (const entry of entryList) {
5657
if (entry.type === "section") {
57-
const nested = await createI18nTree(entry.children, locale);
58+
const nested = await createI18nTree(entry.children, locale, project);
5859
entries.push({
5960
...entry,
6061
children: nested.filter(Boolean),
@@ -63,9 +64,11 @@ export async function createI18nTree(entryList, locale) {
6364
const i18nEntryPath = path.join(
6465
process.cwd(),
6566
COLLECTIONS_ROOT,
67+
project,
6668
locale,
67-
entry.path.endsWith("/") ? entry.path + "index" : entry.path
69+
entry?.path?.endsWith("/") ? entry?.path + "index" : entry.path
6870
);
71+
6972
if (existsSync(i18nEntryPath + ".mdx")) {
7073
const { title } = await getFrontMatterData(i18nEntryPath + ".mdx");
7174
entries.push({

src/app.tsx

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Layout } from "~/ui/layout";
1010
import "~/styles.css";
1111
import { ThemeProvider, useThemeContext } from "./data/theme-provider";
1212
import { I18nProvider } from "@kobalte/core";
13+
import { NotFound } from "./ui/not-found";
1314

1415
export default function App() {
1516
return (
@@ -30,24 +31,7 @@ export default function App() {
3031
<I18nProvider>
3132
<MetaProvider>
3233
<Title>Solid Docs</Title>
33-
<ErrorBoundary
34-
fallback={(e) => {
35-
return (
36-
<>
37-
<Title>404 - SolidDocs</Title>
38-
<Layout isError={Boolean(e)}>
39-
<HttpStatusCode code={404} />
40-
<div class="flex flex-col items-center">
41-
<h1 class="inline pb-1 bg-gradient-to-r from-indigo-200 via-blue-400 to-indigo-200 bg-clip-text font-display text-5xl tracking-tight text-transparent">
42-
Page Not Found
43-
</h1>
44-
<A href="/">Take me back.</A>
45-
</div>
46-
</Layout>
47-
</>
48-
);
49-
}}
50-
>
34+
<ErrorBoundary fallback={<NotFound />}>
5135
<Layout>
5236
<MDXProvider components={Md}>
5337
<Suspense>{props.children}</Suspense>

src/entry-server.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,32 @@ export default createHandler(() => (
1010
const ctx = useThemeContext();
1111

1212
return (
13-
<html lang="en" class={ctx.selectedTheme().value} data-theme={ctx.selectedTheme().theme}>
13+
<html
14+
lang="en"
15+
class={ctx.selectedTheme().value}
16+
data-theme={ctx.selectedTheme().theme}
17+
>
1418
<head>
1519
<meta charset="utf-8" />
1620
<meta
1721
name="viewport"
1822
content="width=device-width, initial-scale=1"
1923
/>
2024
<link rel="icon" href="/favicon.ico" />
21-
<link rel="alternate icon" href="/favicon.svg" type="image/svg+xml" />
25+
<link
26+
rel="alternate icon"
27+
href="/favicon.svg"
28+
type="image/svg+xml"
29+
/>
2230
<script src="/scripts/browser-specific.js" type="module" />
2331
{assets}
2432
</head>
25-
<body>
33+
<body class="min-h-screen dark:bg-slate-900 bg-slate-50">
2634
<div id="app">{children}</div>
2735
{scripts}
2836
</body>
2937
</html>
30-
)
38+
);
3139
})()}
3240
</ThemeProvider>
3341
);

src/i18n/dictionaries/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import ptbr from "./pt-br/ui";
33

44
export const dictionaries = {
55
default: english,
6-
"pt-br": ptbr,
6+
// "pt-br": ptbr,
77
};
88

99
export const languages: { [key: string]: string } = {
1010
en: "English",
11-
"pt-br": "Português do Brasil",
11+
// "pt-br": "Português do Brasil",
1212
};

src/i18n/helpers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useMatch } from "@solidjs/router";
12
import { SUPPORTED_LOCALES } from "./config";
23

34
export function getLocaleFromPathname(pathname: string) {

src/routes/[...404].tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import { useI18n } from "~/i18n/i18n-context";
1+
import { NotFound } from "~/ui/not-found";
22

33
export default function NoEntry() {
4-
const i18n = useI18n();
5-
6-
return <p>{i18n.t("missing.translation")}</p>;
4+
throw new Error("404");
75
}

src/routes/data.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"index.mdx",
55
"quick-start.mdx",
66
"concepts",
7-
"routing",
87
"advanced-concepts",
98
"guides",
109
"configuration"

0 commit comments

Comments
 (0)