Skip to content

Update index page links

Moving to Hugo requires us to rename all index.md files to _index.md.

We've handled renaming the files themselves in this script, but we also need to update all links that end in index.md to instead point to _index.md.

I've tried a few regex-based commands to do this, but without any success:

  • find "$DOCS_PATH" -type f -name '*.md' -exec perl -i -pe 's/\]\((index\.md)\)/\](_index.md)/g' {} +
    • Problem: Doesn't catch links to pages in subdirectories
  • find "$DOCS_PATH" -type f -name '*.md' -exec perl -i -pe 's|(\]\()(.+/)index\.md|\1\2_index.md|g' {} +
    • Problem: Doesn't catch links with extra formatting (e.g, a link that contains backticks to format it as code)
  • find "$DOCS_PATH" -type f -name '*.md' -exec perl -i -pe 's|\]\s*\(?([^\)]*index\.md[^\)]*)\)?|\]\s*\(\1_index.md\)|g' {} +
    • Problem: Mangles links with anchors

This may be a case where we need to parse the Markdown AST (Abstract Syntax Tree) rather than use a regex.

Note:

We are doing some of the work to support renaming in advance by allowing Nanoc and /help to work with either _index.md or index.md files. The change to Nanoc (gitlab-org/gitlab-docs!4616 (merged)) needs to be available in Docker images before we update the actual source content. See gitlab-org/gitlab-docs!4616 (comment 1784109421).

Related: #55 (closed)

Edited by Sarah German