servuscms / servus

Self-contained CMS, Personal Nostr Relay & Blossom server
GNU General Public License v3.0
65 stars 1 forks source link

Error { kind: Msg("Variable `page.date` not found in context while rendering 'post.html #4

Closed georgkaser closed 1 year ago

georgkaser commented 1 year ago

Servus :)

I stuck at following message:

$ ./target/debug/servus dev
Found site: servus.page
Loading layouts...
Loaded 3 templates!
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { kind: Msg("Failed to render 'post.html'"), source: Some(Error { kind: Msg("Variable `page.date` not found in context while rendering 'post.html'"), source: None }) }', src/main.rs:1034:37
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I copied the contents of the hidden .servus folder into the servus.page folder and edited the _config.toml. Was this right? My structure looks like this:

image

ibz commented 1 year ago

Whoops, I renamed some stuff here and there, notably page.date should be page.published_at - forgot to rename these in the default site I generate.

georgkaser commented 1 year ago

Okay - now Error { kind: Msg("Variablepage.meta.titlenot found in context while rendering 'post.html

ibz commented 1 year ago

Also I changed the structure quite a bit, no more hidden folder, , so yes, _config.toml is in the site directory now. I figured, after all, that Jekyll didn't do a bad job at defining a structure, and I can stay with that as much as possible, if not just for simplicity of migration...

ibz commented 1 year ago

page.meta.title

page.front_matter.title

Though I think I will change it again and just have it page.title - but for now everything that comes from the front matter is under .front_matter.

georgkaser commented 1 year ago

Hehehe, okay, so I better wait until you changed that?

Now I am at

$ ./target/debug/servus dev
Found site: servus.page
Loading layouts...
Loaded 3 templates!
Loaded post /posts/servus from ./sites/servus.page/_posts/2022-12-30-servus.md
Loaded page /index from ./sites/servus.page/index.md
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { kind: Msg("Failed to render '__tera_one_off'"), source: Some(Error { kind: Msg("Variable `post.meta.title` not found in context while rendering '__tera_one_off'"), source: None }) }', src/main.rs:1013:40
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
ibz commented 1 year ago

Rename post.meta.title to page.front_matter.title and it should move on to the next error... :-/

ibz commented 1 year ago

Hehehe, okay, so I better wait until you changed that?

Depends what you are up to. This is still very experimental, although I do use it to run 2 live sites with it already, but I keep tweaking it... I should just better document the variables passed to the templates, and then stick with it, at least between major versions or something, but I am still trying out stuff. :)

georgkaser commented 1 year ago

I would love to see it run - your solution to generate static pages from nostr is really a great idea.

Now I did a folder search/replace. Result:

$ ./target/debug/servus dev
Found site: servus.page
Loading layouts...
Loaded 3 templates!
Loaded post /posts/servus from ./sites/servus.page/_posts/2022-12-30-servus.md
Loaded page /index from ./sites/servus.page/index.md
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { kind: Msg("Failed to render '__tera_one_off'"), source: Some(Error { kind: Msg("Variable `page.front_matter.title` not found in context while rendering '__tera_one_off'"), source: None }) }', src/main.rs:1013:40
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

😂

georgkaser commented 1 year ago

It seems that I changed everything on the right places - I managed it to get it run. BUT: When I call the Address in my Browser, I got this response:

image

$ ./target/debug/servus dev
Found site: servus.page
Loading layouts...
Loaded 3 templates!
Loaded post /posts/servus from ./sites/servus.page/_posts/2022-12-30-servus.md
Loaded page /index from ./sites/servus.page/index.md
Loaded page /posts from ./sites/servus.page/posts.md
Loaded resource /atom.xml from ./sites/servus.page/atom.xml (application/xml;charset=utf-8 bytes=615)
Loaded resource /sitemap.xml from ./sites/servus.page/sitemap.xml (application/xml;charset=utf-8 bytes=525)
Loaded resource /robots.txt from ./sites/servus.page/robots.txt (text/plain;charset=utf-8 bytes=55)
Open http://localhost:4884 in your browser!
tide::server Server listening on http://0.0.0.0:4884
tide::log::middleware <-- Request received
    method GET
    path /
thread 'async-std/runtime' panicked at 'no entry found for key', src/main.rs:98:6
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Do you know why? I added my public key in the _config.toml:

pubkey = "6ee9299b9b688748e187f92a5ac02208108ffe4dfc8c669e86dc16485acde8d5"

ibz commented 1 year ago

This happens because your site servus.page doesn't match the URL in your browser. Rename your site to default, in which case it will work regardless of the URL.

georgkaser commented 1 year ago

You are right, it works now. But my demo posts from nostr will not shown - do I need some extra work to do except to add the pubkey? Or will it only work via https?

ibz commented 1 year ago

How are you posting to Nostr? You need to use a NIP-23 compatible client, such as habla.news, add your Servus instance as a relay, and post. If you post to other relays, you won't see the posts.

georgkaser commented 1 year ago

I did this one on habla.news: https://habla.news/a/naddr1qqxnzd3cxy6rqvp3xyer2dejqys8wumn8ghj7mn0wd68ytn9d9h82mny0fmkzmn6d9njuumsv93k2tcppemhxue69uhkummn9ekx7mp0qythwumn8ghj7un9d3shjtnwdaehgu3wvfskuep0qgsxa6ffnwdk3p6guxrlj2j6cq3qsyy0lexlerrxn6rdc9jgttx734grqsqqqa28t4ec2v

ibz commented 1 year ago

What relays did you post to? Did you post to your Servus instance? Note that you can configure the relays you want to post to in Habla.

georgkaser commented 1 year ago

Oh, no - I didn't know yet that I am able to use this as a relay. I'am working locally on my laptop - so I need to put it into live mode that ist reachable from outside and after that I post again to this address? Is there some documentation about this fantastic feature?

ibz commented 1 year ago

It only works as a relay. That is what it is - a personal relay where you post, it keeps your posts forever, and generates a website.

You should be able to test locally, open habla.news and set your local address as a relay. Habla runs in your browser, so it doesn't need to be reachable from the outside. You could even set some hostname in /etc/hosts so you can access it by hostname rather than by IP. The only downside with testing locally is that it can't obtain the SSL certificates from Let's Encrypt - you would need to run it on a VPS first to get the certificates, but after that you can use these certificates to test locally using Habla and with your host in /etc/hosts.

georgkaser commented 1 year ago

oooookay :D I was thinking that it takes my posts from nostr and makes some static website of it. But this is even better... Maybe you should change your description a little bit to explain the relay function.

I tried now (locally and via the ip address from my router with open port on my router), with open port on my laptop via iptables. No luck. There are also no debug messages:

image

UPDATE: some more information:

image

Maybe it's my browser (Ungoogled Chrome). I will try standard Firefox. One moment... :D

ibz commented 1 year ago

image

I thought this was pretty clear. But hey, I should probably explain in more detail how it works.

The fact that you are going through these steps now actually really helps, since I at least know what issues others face. For me it just works, because I know where to look if it doesn't, but I am the only user so far.

I think the issue is...

Habla is served over https://, therefore it will try to open a wss:// connection rather than a ws:// connection. And a wss:// connection is impossible without the certificates.

I did play with it locally and with Habla, but I did the /etc/hosts trick and copied over the certificates from my VPS.

So I guess you are out of luck at this point, unless you can spin up a VPS and run the executable there in "live" mode, so it will get SSL certificates.

georgkaser commented 1 year ago

Hehe, yes - you know, I am an old school web developer (PHP, MySQL etc.) - I read this, but even I need a little bit more explanation :))

But, no problem - I will try it with an subdomain but maybe not today. I WANT TO GET THIS THING TO WORK :)))

If it's working, I can nerve you even more - after that I will try to develop a nice theme we can share with others if you want. I will have a lot of questions I think.

You will hear from me - is it okay to contact you on nostr? I follow you now there...

ibz commented 1 year ago

Yes, themes is the next thing to come, after I standardize, freeze and document the variables passed to the templates.

I want to decouple the functionality from the themes, so one will be able to change themes at any time while keeping content intact.

What I have now is a proof-of-concept that works well enough for me, but in order for it to work for others, it really needs themes. Nobody sane tweaks CSS by hand just to have a website. Should be able to pick a theme and go.

ibz commented 1 year ago

OK, so I:

1) got rid of .front_matter and just flattened everything under page (so use page.title rather than page.front_matter.title) 2) renamed published_at to date

(these are for simplicity and more consistency with Jekyll templates)

3) documented the variables passed to the templates (see README) 4) moved the default site that is generated if no sites are found under themes/blank (now we could in theory have additional themes under themes/) 5) fixed the "blank theme" to use the correct template variables - works on the first run now, if no sites are found, a site using the "blank" theme is generated, and it works