Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support an option to add .html suffixes to the generated sites #13

Merged
merged 3 commits into from
May 18, 2023

Conversation

epaulson
Copy link
Contributor

@epaulson epaulson commented May 18, 2023

[As usual this is kind of a hack and I'm not at all offended if you want to do this in a different way]

In the 'rdf serve' command, the server process automatically maps incoming URLs to a matching static .html file, e.g. 'http://localhost:8000/rdf/Property' becomes 'http://localhost:8000/rdf/Property.html' under the covers. If you're not using the 'rdf serve' command, you can still host the resulting static site with most webservers that have some sort of automatic rule that does a similar rewriting.

Alas, not all web servers support that option - notably github pages but also some other content management systems - so as-is out of the box the default URLs won't match what the webserver is looking for and some systems can't serve the site.

With this patch, there's a new option in rdfconfig.json that generates a URL with a .html attached to it:

{
  "siteOptions": {
    "title": "Explorer",
    "icons": [ {}
    ],
    "assets": {
      "favicon.ico": "favicon.ico",
      "robots.txt": "robots.txt"
    },
    "outDir": "public",
    "appendHtmlSuffix": true
  }
}

We probably want a .html suffix instead of just changing the filename to not have a suffix to make it more likely the webserver serves the file with the right MIME type, though most of the pages do have enough of a header that hopefully most browsers figure out that the file should be an HTML file.

Long term hopefully more providers support something like Cloudflare's redirect - https://developers.cloudflare.com/pages/platform/redirects/
(this has been a longstanding github ask - see isaacs/github#408, you can play some games with a custom 404.html to match any missing URL and look at the request and re-serve something up)

We might not also care about this if we do something more with a single-page-app and do some javascript magic to grab the right data regardless of what the URL is, but this might be an OK interim option.

But, with this option, you can serve the site just by running python3 -m http.server 8000 in the explorer/public/ directory

@ektrah ektrah force-pushed the static-hosting-1 branch from c28bd06 to 6bc44d2 Compare May 18, 2023 06:21
@ektrah ektrah merged commit 1663243 into ektrah:main May 18, 2023
@ektrah
Copy link
Owner

ektrah commented May 18, 2023

Thanks! I've made some small tweaks and inverted the configuration option, renaming it from appendHtmlSuffix to cleanUrls to, similar to how Firebase does it. The default is false, so you now have to opt-in to drop the .html extension from URLs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants