Issue with adding widgets to content pages.
Describe the bug
I've been having some trouble attempting to add widgets to embedded content pages. It appears that the behavior when setting htmlcore.Context ElementHandlers func is inconsistent.
How to reproduce
As a test, I've created the following three files which are embedded with the other content
content/ab.md
+++
URL = "/ab"
Title = "ab"
Categories = ["diode"]
+++
<ab>
template text
content/ab1.md
+++
URL = "/ab1"
Title = "ab1"
Categories = ["diode"]
+++
<ab1>
template text
content/1ab.md
+++
URL = "/1ab"
Title = "1ab"
Categories = ["diode"]
+++
<1ab>
template text
I set the element handlers in order to add a button to each one in an identical way
log.Println("setting ab element handler")
ctx.ElementHandlers["ab"] = func(ctx *htmlcore.Context) bool {
f := core.NewFrame(ctx.BlockParent)
tree.AddChild(f, func(w *core.Button) {
w.SetText("test1234")
})
return true
}
log.Println("setting 1ab element handler")
ctx.ElementHandlers["1ab"] = func(ctx *htmlcore.Context) bool {
f := core.NewFrame(ctx.BlockParent)
tree.AddChild(f, func(w *core.Button) {
w.SetText("test1234")
})
return true
}
log.Println("setting ab1 element handler")
ctx.ElementHandlers["ab1"] = func(ctx *htmlcore.Context) bool {
f := core.NewFrame(ctx.BlockParent)
tree.AddChild(f, func(w *core.Button) {
w.SetText("test1234")
})
return true
}
Then I do core build web or go run . the application ; the result is the same either way:
-
It seems as though I'm unable to add the a widget as expected via setting ctx.ElementHandlers for that content page when the markdown content filename starts with a number.(?!)
-
I also note that unwanted spaces are added between numbers and letters for content pages as shown in the category menu in the images above
-
I also note that the content pages listed in the categories menu on the left are prepended with
Content/in an undesired way.
Example code
Relevant output
Platform
Linux
Thank you for filing this issue.
- This issue is likely caused not by the filename but by the element name. HTML element names cannot start with a number: https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements#name. I would recommend using an attribute if you need to add such information (ex:
<my-button id="1ab">), which you can then access withhtmlcore.GetAttrusingctx.Node. - You can set
Name = ...in the front matter in the same way you are settingTitleto customize the name in the tree. - It is critical to call
SetContentwhen you make a content widget, which as you can see from its code automatically callsfsx.Sub, which goes into the content directory so that the pages are not nested. If you callSetSourceor otherwise are doing something strange with your folders, everything will be in a content subdirectory, which causes both theContent/in the name and potentially other issues.//go:embed content/*puts a content directory at the root with everything nested underneath it, which is why SetContent goes into the subdirectory so that everything is at the root level.
Apologies for not getting back to you on some of your other issues; I am busy and they are difficult problems, whereas this is easier to address. I will respond to your other issues soon.
Sincere thanks for your insights on this. I understand the errors now from your explanation, and what I can do to address them. I suppose I will leave this ticket open as it's a potential area where documentation may be improved.
Apologies for not getting back to you on some of your other issues; I am busy and they are difficult problems, whereas this is easier to address.
Not to worry! On the other issues, I mainly just wanted to make you aware.
I trust things like font setting for web and fullscreen CPU usage will be fixed at some point going forward. And it's easy enough to do without these for now.
As long as that is not some error on my part or some aspect of the documentation I've overlooked, I'll just leave it to you to fix it when you can, and reiterate my appreciation for your support in these matters.
Also FYI in #1608 I just fixed an issue with the default Title setting, so now you can just set Name and then Title will automatically follow.