Insert package version number at top of documentation

Hello,

I like to have the version number of the package included in the documentation, so that you can immediately tell if you’re reading the right version of the documentation. To do this, I’ve put the following near the top of my docs/src/index.md (not checked in to github yet):

```@eval
using Markdown
using Pkg
m = Pkg.Operations.Context().env.manifest
v = string(m[findfirst(v->v.name == "MultiGridBarrier", m)].version)
md"# MultiGridBarrier $v"
```

A couple of questions.

  1. Is this really the right way to get the version number? If I had something like Pkg.getversion(MultiGridBarrier), I would be slightly more confident that it got the right package, as opposed to my hand-coded findfirst search. Also, is this part of the Pkg API really public?
  2. The Documenter documentation says that @eval is a sin in the eyes of the lord and that I should feel guilty for using it. Is this so?

Thanks,

S

Since Julia 1.9, there is pkgversion() which does what you need if I understand you right.

1 Like

That’s a huge improvement already, thanks! I’m glad I asked.