forked from vapor/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixSearchIndex.swift
executable file
·52 lines (42 loc) · 1.29 KB
/
fixSearchIndex.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/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/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: "zh/")
&& !doc.location.starts(with: "de/")
&& !doc.location.starts(with: "fr/")
&& !doc.location.starts(with: "nl/") {
searchIndexDocs.append(doc)
}
}
newSearchIndex.docs = searchIndexDocs
try JSONEncoder().encode(newSearchIndex).write(to: fileURL)