From ceca45e8196fd6a56cd68a676cc5c61d8b98af1a Mon Sep 17 00:00:00 2001 From: Tim Condon <0xTim@users.noreply.github.com> Date: Sun, 9 Jul 2023 11:22:40 +0100 Subject: [PATCH] Update Search Index Script for new languages (#854) --- README.md | 2 +- fixSearchIndex.swift | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 3bf964e4..7c38bd46 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ You can check it out by running `mkdocs serve` in the terminal. Once you are sat > NOTE: If a file isn't translated, it will just default to the default language file. So you don't have to translate everything all at once. -Finally, you should add the new language to the [issue template](https://github.com/vapor/docs/blob/main/.github/workflows/translation-issue-template.md) to ensure that any future changes are applied to the new translation. +Finally, you should add the new language to the [issue template](https://github.com/vapor/docs/blob/main/.github/workflows/translation-issue-template.md) to ensure that any future changes are applied to the new translation and to the [search index script](https://github.com/vapor/docs/blob/main/fixSearchIndex.swift) to ensure search works correctly. diff --git a/fixSearchIndex.swift b/fixSearchIndex.swift index ac8f6654..86346f8c 100755 --- a/fixSearchIndex.swift +++ b/fixSearchIndex.swift @@ -37,13 +37,22 @@ let searchIndex = try JSONDecoder().decode(SearchIndex.self, from: indexData) var newSearchIndex = searchIndex var searchIndexDocs = [SearchIndexDocs]() +let knownLanguages = [ + "en", + "de", + "es", + "fr", + "it", + "ko", + "nl", + "pl", + "zh", + ].map { "\($0)/" } + + for doc in newSearchIndex.docs { - if !doc.location.starts(with: "en/") - && !doc.location.starts(with: "zh/") - && !doc.location.starts(with: "de/") - && !doc.location.starts(with: "fr/") - && !doc.location.starts(with: "nl/") { - searchIndexDocs.append(doc) + if !knownLanguages.contains(where: { doc.location.starts(with: $0) }) { + searchIndexDocs.append(doc) } }