Highlight current doc topic in the sidebar identified by their slugs in the index

AI-generated summary

In a Feature discussion titled Highlight current doc topic in the sidebar identified by their slugs in the index, Neil_Evans seeks to define TOC index items using only slugs (not post IDs) to maintain consistency across DEV/PROD environments. While slug-only links work for navigation, the current topic isn’t highlighted in the sidebar unless the post ID is appended. nat acknowledges the use case and confirms work is underway to support slug-based highlighting. Neil_Evans2 clarifies they’re using relative paths (e.g., /t/one-slug), which nat confirms as viable. After an update, Neil_Evans reports it doesn’t yet work, but later finds a workaround using Rails to update post IDs on PROD. pfaffman suggests syncing DEV with PROD’s database to preserve IDs, but Neil_Evans initially misunderstands the direction of the restore. pfaffman clarifies it would overwrite DEV, not PROD. Neil_Evans admits the misreading and explains their DEV is treated as a sandbox, not a staging area, so syncing isn’t urgent. The core issue remains: slug-only links don’t highlight the active topic in the sidebar without post IDs, and while a workaround exists, native support is still pending.

I’m trying to define the TOC index items using only the slugs, rather then adding the topic index at the end of the URL - so I can maintain the same TOC index across environments (DEV/PROD).

This appears to work (as it navigates to the correct topic using the slug only), but the current topic is not highlighted in the menu on the left unless I also add the ID to the end of every URL. Is there a workaround for this?

2 Likes

Oh that’s a cool use-case. I understand about just using the slugs, but how will you get around replacing the site URLs?

e.g. on prod

# Index
- https://prod.discourse.site/t/one-slug

then on dev

# Index
- https://dev.discourse.site/t/one-slug
1 Like

I’m using relative paths for the URL’s (t/one-slug) which seem to work fine?

I see, so something like the following:

## Setup

* [Initial setup of your device](/t/initial-setup-of-your-device)

Gotcha. I’m working on an update for your slug request.

6 Likes

Thanks Natalie! Much appreciated :slight_smile:

I noticed there was an update for this, so I have tried it on my system - but it doesn’t appear to work. Apologies if this is still in progress :slight_smile:

FYI- I found a way to update post-id indexes for all anchor links for every anchor on PROD using rails - so have a workaround for this now.

Why not just restore the prod database to dev so you’ll have the same ids? There must be something I don’t understand

Wouldn’t that wipe all the forum content on PROD?

No. That would wipe all the forum content on dev.

I must not understand how it is you’re using DEV.

Sorry - I misread your initial message (got DEV and PROD the wrong way round!)..

We built the TOC index (and associated topics) on DEV initially, so wanted an easy way to replicate them to PROD. Now that we have everything working on PROD then yes - we could just restore from PROD to DEV to bring them back in sync.

However, we treat our DEV system more like a sandbox (for experimentation) - rather than a pre-prod staging area - so there is no pressing need to do this now..

1 Like