Open yznts opened 3 years ago
Can confirm. i just stumbled into the same situation.
Could you solve the issue?
using alternates doesnt throw an error but rather is completely ignored and the XML is rendered fine - just without the
@nlappe Not yet. Going to make PR in a while if there would be no updates on that
@yuriizinets Thanks for the update. I had to fall back to another library and decided to just build the XML myself. If you're in a hurry (which i was for the sitemap) you can look into the dependencies of this lib - the required github.com/beevik/etree package is super easy to use.
@nlappe Sorry, I'm not going to make a PR because I'm not so familiar with this codebase and project is not maintained, as I see now. I contacted with project owner without success.
As a possible solution/workaround:
go-sitemap-generator
into your project directory and make it local module with replace
feature of go.mod
go-sitemap-generator/stm/builder_url.go
method XML()
add SetBuilderElementValue(url, su.data, "xhtml:link")
above SetBuilderElementValue(url, su.data, "expires")
validate()
method and add this after the line 72
. In that way we will allow xhtml:link
keyword (I had 2 approaches: replace alternates
with xhtml:link
inside of library in runtime, or just use xhtml:link
everywhere, so I've implemented second option)
if key == "xhtml:link" {
invalid = false
break
}
Final usage:
// Alternates are []Attr (!!!)
sm.Add(stm.URL{{"loc", url}, {"xhtml:link", alternates}})
@yuriizinets Thanks for your Feedback. As time did matter i chose to implement the feature myself with the help of github.com/beevik/etree. (which is a dependency of this package)
You can do something like
alternate := [instsance of an *etree.Element].CreateElement("xhtml:link")
alternate.CreateAttr("rel", "alternate")
alternate.CreateAttr("hreflang", "<lang>")
alternate.CreateAttr("href", "<url>")
to achieve the same.
It works like a Charme :)
If you ever have to work with XML type data in go its a nice starting point.
This approach also offers a bit more flexibility for future things.
@nlappe used this package to avoid direct work with XML, but... 😄 Thanks for notes!
I'm trying to handle language routes in my generator script.
Checked your sources and found that "alternates" keyword, so tried to do in that way:
It's not working at all, and I can't find any functionality in the code related to alternates generation.