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';
|
2025-10-27 17:17:37 +02:00
|
|
|
import { useLayoutEffect, useRef, useState } from 'preact/hooks';
|
2025-10-25 20:27:42 +03:00
|
|
|
import { default as i18next, changeLanguage } from 'i18next';
|
2025-10-27 17:17:37 +02:00
|
|
|
import { extractLocaleFromUrl, initTranslations, LOCALES, mapLocale } from './i18n';
|
2025-10-25 20:27:42 +03:00
|
|
|
import HttpApi from 'i18next-http-backend';
|
|
|
|
|
import { initReactI18next } from "react-i18next";
|
2025-10-25 18:54:24 +03:00
|
|
|
|
|
|
|
|
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 (
|
2025-10-27 16:45:52 +02:00
|
|
|
<LocationProvider>
|
|
|
|
|
<LocaleProvider>
|
|
|
|
|
<Header repoStargazersCount={props.repoStargazersCount} />
|
|
|
|
|
<main>
|
|
|
|
|
<Router>
|
|
|
|
|
<Route path="/" component={Home} />
|
|
|
|
|
<Route path="/get-started" component={GetStarted} />
|
|
|
|
|
<Route path="/support-us" component={SupportUs} />
|
2025-10-25 21:39:02 +03:00
|
|
|
|
2025-10-27 16:45:52 +02:00
|
|
|
<Route path="/:locale:/" component={Home} />
|
|
|
|
|
<Route path="/:locale:/get-started" component={GetStarted} />
|
|
|
|
|
<Route path="/:locale:/support-us" component={SupportUs} />
|
2025-10-25 21:39:02 +03:00
|
|
|
|
2025-10-27 16:45:52 +02:00
|
|
|
<Route default component={NotFound} />
|
|
|
|
|
</Router>
|
|
|
|
|
</main>
|
|
|
|
|
<Footer />
|
|
|
|
|
</LocaleProvider>
|
|
|
|
|
</LocationProvider>
|
2025-09-26 22:54:56 +03:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-25 18:54:24 +03:00
|
|
|
export function LocaleProvider({ children }) {
|
|
|
|
|
const { path } = useLocation();
|
2025-10-25 23:11:02 +03:00
|
|
|
const localeId = mapLocale(extractLocaleFromUrl(path) || navigator.language);
|
2025-10-27 17:17:37 +02:00
|
|
|
const loadedRef = useRef(false);
|
2025-10-25 20:27:42 +03:00
|
|
|
|
2025-10-27 17:17:37 +02:00
|
|
|
if (!loadedRef.current) {
|
|
|
|
|
initTranslations(localeId);
|
|
|
|
|
loadedRef.current = true;
|
|
|
|
|
} else {
|
|
|
|
|
changeLanguage(localeId);
|
|
|
|
|
}
|
2025-10-25 18:54:24 +03:00
|
|
|
|
|
|
|
|
return (
|
2025-10-25 19:58:31 +03:00
|
|
|
<LocaleContext.Provider value={localeId}>
|
2025-10-27 16:29:44 +02:00
|
|
|
{children}
|
2025-10-25 18:54:24 +03:00
|
|
|
</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-27 18:04:49 +02:00
|
|
|
const { html, links } = await ssr(<App repoStargazersCount={stargazersCount} {...data} />);
|
|
|
|
|
const lang = extractLocaleFromUrl(data.url);
|
|
|
|
|
return {
|
|
|
|
|
html,
|
|
|
|
|
links,
|
|
|
|
|
head: {
|
|
|
|
|
lang
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-26 22:54:56 +03:00
|
|
|
}
|
2025-10-03 19:09:23 +03:00
|
|
|
|