Skip to content

Add support for rendering DataHarmonizer instances on GitHub pages #491

@jfy133

Description

@jfy133

Hello,

Thank you very much for DataHarmonizer, it is a really great tool - particularly that it doesn't need a standalone server to render.

I have two projects where I would like to host an instance of DataHarmonizer on our project website, which is hosted on GitHub pages.

Background

So far I've been able to make it work with two versions of DataHarmonizer, but with different levels of 'tweaks'.

  1. Older version:
  2. Newer version:

The older one worked almost out of the box, I just had to:

  1. Run yarn build:web
  2. Copy web/dist/ to a docs/ directory at the root of the repository
  3. Activate Github pages, and set on this page to Source: Deploy from Branch , then Branch master and directory docs/

However since commit b31a061 something appears to have changed in the main.js so that this no longer works out of the box in my fork from commit b31a061.

Seemingly this is something to do with how the generated scripts/main.js file in picks up the paths to the schema.json.

Investigation

After a lot of trial error, inspecting the GitHub Pages page with browser tools, and a little bit of AI help with Claude Sonnet - it pointed me to the fact that there is a function:

            : await (async function (e) {
                for (const n of Object.values(oe.menu))
                  if (n.folder === e) {
                    var t = await se(`/templates/${e}/schema.json`);
                    const r = { name: e, default: { schema: t }, locales: {} };
                    if (n.locales)
                      for (const [i, o] of n.locales.entries())
                        if (i > 0) {
                          let n = B(
                            t,
                            await se(`/templates/${e}/locales/${o}/schema.json`)
                          );
                          r.locales[o] = { schema: n };
                        }
                    return r;
                  }
                return null;
              })(e)),

Which hard codes the two locations of the schema.json to starting with a root of /templates/ . However when hosting this on GitHub pages directly, this fails because this page results in a 404, as it tries to find the file in the root of our domain, rather in the specific GitHub repository the website is coming from, i.e. in this case https://mix-minas.org/templates/miaard/schema.json rather than https://mixs-minas-org/miaard-Daharmonizer/templates/miaard/schema.json

Instead, if I manually edit the generated main.js to include the suffix of the GitHub repostiory to two paths, then the page will successfully render on GitHub page, i.e.

            : await (async function (e) {
                for (const n of Object.values(oe.menu))
                  if (n.folder === e) {
                    var t = await se(`/miaard-DataHarmonizer/templates/${e}/schema.json`);
                    const r = { name: e, default: { schema: t }, locales: {} };
                    if (n.locales)
                      for (const [i, o] of n.locales.entries())
                        if (i > 0) {
                          let n = B(
                            t,
                            await se(`/miaard-DataHarmonizer/templates/${e}/locales/${o}/schema.json`)
                          );
                          r.locales[o] = { schema: n };
                        }
                    return r;
                  }
                return null;
              })(e)),

Request

I was wondering if it would be possible to update the more recent main.js script to again support more dynamic root domains somehow.

I don't know what has changed exactly between the two commits, but given it was possible before in the older version of DataHarmonizer, I wonder if somehow this area of the file could be reverted - however I 0 javascript experience, so I am unable to myself inspect/work out what impact of these changes are nor how feasible it would be to do so.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions