From 2967397019486af76013e11da37a0f4c4a6ad6ea Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Sun, 8 May 2022 00:56:04 +0100 Subject: [PATCH] Add script to fix search index --- 4.0/mkdocs.yml | 6 ++---- fixSearchIndex.swift | 50 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 4 deletions(-) create mode 100755 fixSearchIndex.swift diff --git a/4.0/mkdocs.yml b/4.0/mkdocs.yml index ca400d18..93adc0e8 100644 --- a/4.0/mkdocs.yml +++ b/4.0/mkdocs.yml @@ -16,9 +16,8 @@ copyright: "Copyright © Vapor Community" theme: name: material custom_dir: theme/ - - # Language language: en + locale: en palette: primary: black @@ -46,8 +45,6 @@ extra: link: https://discord.gg/vapor - icon: fontawesome/brands/github link: https://github.com/vapor - search: - language: 'en' # Custom code highlighting syntax (uncomment if you want to use this. css is in `docs/stylesheets/extra.css`) extra_css: @@ -73,6 +70,7 @@ plugins: - i18n: default_language: 'en' search_reconfigure: false + material_alternate: true # Add the new languages here. DON'T CHANGE THE DEFAULT LANGUAGE languages: en: diff --git a/fixSearchIndex.swift b/fixSearchIndex.swift new file mode 100755 index 00000000..de5e9077 --- /dev/null +++ b/fixSearchIndex.swift @@ -0,0 +1,50 @@ +#!/usr/bin/swift + +import Foundation + +struct SearchIndex: Codable { + let config: SearchIndexConfig + var docs: [SearchIndexDocs] +} + +struct SearchIndexConfig: Codable { + let indexing: String + let lang: [String] + let minSearchLength: Int + let prebuildIndex: Bool + let separator: String + + enum CodingKeys: String, CodingKey { + case indexing + case lang + case minSearchLength = "min_search_length" + case prebuildIndex = "prebuild_index" + case separator + } +} + +struct SearchIndexDocs: Codable { + let location: String + let text: String + let title: String +} + +let searchIndexPath = "site/4.0/search/search_index.json" + +let fileURL = URL(fileURLWithPath: searchIndexPath) +let indexData = try Data(contentsOf: fileURL) +let searchIndex = try JSONDecoder().decode(SearchIndex.self, from: indexData) +var newSearchIndex = searchIndex +var searchIndexDocs = [SearchIndexDocs]() + +for doc in newSearchIndex.docs { + if !doc.location.starts(with: "en/") + && !doc.location.starts(with: "fr/") + && !doc.location.starts(with: "nl/") { + searchIndexDocs.append(doc) + } +} + +newSearchIndex.docs = searchIndexDocs + +try JSONEncoder().encode(newSearchIndex).write(to: fileURL) \ No newline at end of file