The number 827823 is a unique identifier for the question. The /in-hugo-how-... part is optional and ignored by the web server, however it is included for better SEO.
(Ignored? Yes, try removing it, or altering it. The SO web server ignores that part as long as the number is a valid question number.)
My first attempt is to set the id as the “slug” and then use a permalink format like "/:year/:month/:slug/#:title" but the URLs that are generated omit the # and anything that follows. I used /# instead of # because as a static site, I didn’t want to have to create a rewrite rule on Apache that would ignore anything after the id.
Is this a bug in how permalinks work or am I doing this wrong?
“/” is the path separator and kind of “goes without saying”. Let’s just say that what you want to do isn’t currently supported, and I have no good suggestions for a workaround, either.
What you are asking is to be able to have both of those URLs resolve (or redirect) to the same content. The point of optional parts of a URL is so that you can pass around the shorter URL and have it work just as if the longer has been used.
But I don’t see the need to name content as 123, or why I would ever have someone use the shorter URL when I have the longer URL available.
Issue #2 can be solved with an alias today. However, if you really want it to act like SO where “/123/fragment” would redirect to “/123/fragment-of-my-title”, you’ll need to rely on your web server for that.
An anchored URL should point to something that exists, I don’t see that in your example
The current permalink maps to a physical location on disk, so a “patch” should start by doing some analyse of how involved such a change will be – and sketch up a proposal/design.
But we should first decide if this is something we want. You are the first user asking for it, so unless the hordes are chiming in with a “me want this, too”, I don’t see the greater value in spending time on it.