From 5836ea21339a427b52112deaaaede72ca3a2f994 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemek=20Wi=C4=99ch?= Date: Mon, 28 Aug 2023 23:08:19 +0200 Subject: [PATCH] Add "single tree mode" when building --- README.md | 15 +++++++++++++++ src/app.tsx | 36 +++++++++++++++++++++++++++++------- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ea114ac..3985e78 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,21 @@ https://github.com/PeWu/topola-viewer/archive/refs/heads/gh-pages.zip These are the exact files that are hosted on GitHub pages. +### Build for your own data only + +You can run Topola Viewer in a "single tree mode" that displays only the GEDCOM you specify. Specify the URL to a GEDCOM file in the `REACT_APP_STATIC_URL` environment variable when building and running the application. + +Run locally with the specified data URL: +``` +REACT_APP_STATIC_URL=https://example.org/sample.ged npm start +``` + +Build with the specified data URL: +``` +REACT_APP_STATIC_URL=https://example.org/sample.ged npm run build +``` +The `build/` folder will contain files that can be hosted on a Web server. + ### Alternative build The [topola-webpack](https://github.com/develancer/topola-webpack) tool can build a Topola Genealogy Viewer package bundled together with a GEDCOM file. diff --git a/src/app.tsx b/src/app.tsx index 8c5f957..26315a6 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -48,6 +48,14 @@ import { WikiTreeSourceSpec, } from './datasource/wikitree'; +/** + * Load GEDCOM URL from REACT_APP_STATIC_URL environment variable. + * + * If this environment variable is provided, the viewer is switched to + * single-tree mode without the option to load other data. + */ +const staticUrl = process.env.REACT_APP_STATIC_URL; + /** Shows an error message in the middle of the screen. */ function ErrorMessage(props: {message?: string}) { return ( @@ -135,7 +143,13 @@ function getArguments(location: H.Location): Arguments { const url = getParam('url'); const embedded = getParam('embedded') === 'true'; // False by default. var sourceSpec: DataSourceSpec | undefined = undefined; - if (getParam('source') === 'wikitree') { + if (staticUrl) { + sourceSpec = { + source: DataSourceEnum.GEDCOM_URL, + url: staticUrl, + handleCors: false, + }; + } else if (getParam('source') === 'wikitree') { sourceSpec = { source: DataSourceEnum.WIKITREE, authcode: getParam('authcode'), @@ -170,7 +184,7 @@ function getArguments(location: H.Location): Arguments { chartType: chartTypes.get(view) || ChartType.Hourglass, showSidePanel: getParam('sidePanel') !== 'false', // True by default. - standalone: getParam('standalone') !== 'false' && !embedded, + standalone: getParam('standalone') !== 'false' && !embedded && !staticUrl, showWikiTreeMenus: getParam('showWikiTreeMenus') !== 'false', // True by default. freezeAnimation: getParam('freeze') === 'true', // False by default config: argsToConfig(search), @@ -559,11 +573,19 @@ export function App() { /> )} /> - - - - - + {staticUrl ? ( + + + + + ) : ( + + + + + + )} ); } +