2025-10-03 19:09:23 +03:00
|
|
|
import './style.css';
|
2025-10-03 19:22:58 +03:00
|
|
|
import { FALLBACK_STARGAZERS_COUNT, getRepoStargazersCount } from './github-utils.js';
|
2025-09-26 22:54:56 +03:00
|
|
|
import { Header } from './components/Header.jsx';
|
|
|
|
|
import { Home } from './pages/Home/index.jsx';
|
2025-10-25 18:54:24 +03:00
|
|
|
import { LocationProvider, Router, Route, hydrate, prerender as ssr, useLocation } from 'preact-iso';
|
2025-09-26 22:54:56 +03:00
|
|
|
import { NotFound } from './pages/_404.jsx';
|
2025-09-26 23:24:28 +03:00
|
|
|
import Footer from './components/Footer.js';
|
2025-09-27 17:01:54 +03:00
|
|
|
import GetStarted from './pages/GetStarted/get-started.js';
|
2025-09-27 17:03:39 +03:00
|
|
|
import SupportUs from './pages/SupportUs/SupportUs.js';
|
2025-10-25 18:54:24 +03:00
|
|
|
import { createContext } from 'preact';
|
|
|
|
|
|
|
|
|
|
export const LocaleContext = createContext('en');
|
2025-09-26 22:54:56 +03:00
|
|
|
|
2025-10-03 19:09:23 +03:00
|
|
|
export function App(props: {repoStargazersCount: number}) {
|
2025-09-26 22:54:56 +03:00
|
|
|
return (
|
|
|
|
|
<LocationProvider>
|
2025-10-25 18:54:24 +03:00
|
|
|
<LocaleProvider>
|
|
|
|
|
<Header repoStargazersCount={props.repoStargazersCount} />
|
|
|
|
|
<main>
|
|
|
|
|
<Router>
|
|
|
|
|
<Route path="/:locale:/" component={Home} />
|
|
|
|
|
<Route default component={NotFound} />
|
|
|
|
|
<Route path="/:locale:/get-started" component={GetStarted} />
|
|
|
|
|
<Route path="/:locale:/support-us" component={SupportUs} />
|
|
|
|
|
</Router>
|
|
|
|
|
</main>
|
|
|
|
|
<Footer />
|
|
|
|
|
</LocaleProvider>
|
2025-09-26 22:54:56 +03:00
|
|
|
</LocationProvider>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-25 18:54:24 +03:00
|
|
|
export function LocaleProvider({ children }) {
|
|
|
|
|
const { path } = useLocation();
|
|
|
|
|
const locale = path.split('/')[1] || 'en';
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<LocaleContext.Provider value={locale}>
|
|
|
|
|
{children}
|
|
|
|
|
</LocaleContext.Provider>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-26 22:54:56 +03:00
|
|
|
if (typeof window !== 'undefined') {
|
2025-10-03 19:22:58 +03:00
|
|
|
hydrate(<App repoStargazersCount={FALLBACK_STARGAZERS_COUNT} />, document.getElementById('app')!);
|
2025-09-26 22:54:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function prerender(data) {
|
2025-10-03 19:09:23 +03:00
|
|
|
// Fetch the stargazer count of the Trilium's GitHub repo on prerender to pass
|
|
|
|
|
// it to the App component for SSR.
|
|
|
|
|
// This ensures the GitHub API is not called on every page load in the client.
|
|
|
|
|
const stargazersCount = await getRepoStargazersCount();
|
|
|
|
|
|
2025-10-25 18:18:47 +03:00
|
|
|
return await ssr(<App repoStargazersCount={stargazersCount} {...data} />);
|
2025-09-26 22:54:56 +03:00
|
|
|
}
|
2025-10-03 19:09:23 +03:00
|
|
|
|