Allow Arbitrary Homepage (by Jay Pfaffman)

https://github.com/pfaffman/discourse-allow-arbitrary-homepage

Well, @hellekin thought that this deserved its own topic. I’m not quite sure it’s ready for such, but here it is. I’ll have a look at stuff early next week and try to make sure that it looks like something that other people could really use. :wink:

As he said:

12 Likes

@pfaffman I tried to use the following setup:

  1. install your theme component
  2. set home_url_override to TransHack ·Xist·nce…
  3. add some Nginx configuration to match the HTML file:
        location = /TransHack_·Xist·nce… {
                default_type text/html;
                alias /srv/www/zoethical.org/thx/home.html;
        }

Calling the file directly works, but calling https://thx.zoethical.org breaks. As I noticed a check on permalinks, I tried to add a permalink for /. But it did not work either. Might this be an issue with cache?

FYI, here is the content of the home.html file:

<!DOCTYPE html>
<html>
        <head>
                <meta charset="UTF-8">
                <title> TransHack ·Xist·nce… </title>
                <link rel="stylesheet" href="/thx.css">
        </head>
        <body class="thx home">
                <header>
                        <h1>THX</h1>
                </header>
                <section id="agora">
                        <h2><a href="https://thx.zoethical.org/c/agora/1">Agora</a></h2>
                        <d-topics-list discourse-url="https://thx.zoethical.org" per-page="5" category="1"></d-topics-list>
                </section>
                <section id="fonderie-de-fiction">
                        <h2><a href="https://thx.zoethical.org/c/fonderie-de-fiction/7">Fonderie de fiction</a></h2>
                        <d-topics-list discourse-url="https://thx.zoethical.org" per-page="5" category="7"></d-topics-list>
                </section>
                <script src="https://thx.zoethical.org/javascripts/embed-topics.js"></script>
        </body>
</html>

Edit: I guess it might be due to the fact the instance requires login (SSO), then there’s a dysfunction in this case. I might be willing to make more tests including opening the instance a bit more. After rendering the site public, I still get " Oops! That page doesn’t exist or is private." when hitting the homepage. Any idea why?

2 Likes

Is the home page you’re setting on your discourse site? I think you want to put just the url starting with the /.

2 Likes

Oh, so the file should be the default – usually index.html?

Indeed it works! The component expects the URL to be an index file, right?

I simply had to rename my home.html to index.html and change the Nginx configuration to:

        # more config...
        root   /srv/www/zoethical.org/thx;
        index  index.html; # <- this is important

        location = /TransHack_·Xist·nce… {
                default_type text/html;
                alias /srv/www/zoethical.org/thx/index.html; # <- and matches
        }
        location / {
                # nginx magic to try the local file before proxying...
                try_files $uri $uri/ $uri.html @discourse;
        }
        location @discourse {
                # normal discourse proxy
        }

So, to summarize…

If you’re using a static page on the same site as the Discourse instance, make sure your Web server reads the static file(s) – e.g., related CSS – before proxying the requests to the Discourse. Tadaa!

Thank you @pfaffman!

3 Likes

Actually a bug remains: although calling the URL https://thx.zoethical.org works from outside, once in the Discourse, clicking the logo does not result in bringing back the overridden page. I noticed a permalink check, so I tried several options, which all failed:

  1. create a permalink from https://thx.zoethical.org to /index.html
  2. create a permalink from https://thx.zoethical.org to /TransHack_·Xist·nce…
  3. combine those with a permalink from /index.html to /TransHack_·Xist·nce…
  4. remove the redirect to /TransHack_·Xist·nce… in the frontend configuration
  5. create a custom_url permalink and point it to an external URL

I guess the issue comes from the fact the script does not try to reload the whole application when clicking on the logo but expects an internal link to be attached to the top path.

I would expect that when either the homepage_url_override or the (e.g., custom_url) permalink points to an absolute URL, then the page is fully reloaded.

2 Likes