ikeikeikeike / go-sitemap-generator

go-sitemap-generator is the easiest way to generate Sitemaps in Go
https://github.com/ikeikeikeike/go-sitemap-generator
MIT License
218 stars 65 forks source link

Alternates are not generated, and no docs for that functionality #41

Open yznts opened 3 years ago

yznts commented 3 years ago

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:

image

It's not working at all, and I can't find any functionality in the code related to alternates generation.

nlappe commented 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 tags

yznts commented 3 years ago

@nlappe Not yet. Going to make PR in a while if there would be no updates on that

nlappe commented 3 years ago

@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.

yznts commented 3 years ago

@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:

Final usage:

// Alternates are []Attr (!!!)
sm.Add(stm.URL{{"loc", url}, {"xhtml:link", alternates}})
nlappe commented 3 years ago

@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.

yznts commented 3 years ago

@nlappe used this package to avoid direct work with XML, but... 😄 Thanks for notes!