diff options
| author | Christian Cleberg <[email protected]> | 2026-08-07 03:45:47 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-08-07 03:45:47 -0500 |
| commit | db40d346c28800a1eec384a5e4f3d7d090198e4d (patch) | |
| tree | cebd9fb63f26e402b85f5db4192f5dc844c48a27 /Hutch/Views/More/ManPageCatalog.swift | |
| parent | 6c26cf048119bf4ff6af039991d3e34d76bac2ad (diff) | |
| parent | f9f86b9681909b14304909b1286b9b50362625d7 (diff) | |
| download | hutch-db40d346c28800a1eec384a5e4f3d7d090198e4d.tar.gz hutch-db40d346c28800a1eec384a5e4f3d7d090198e4d.tar.bz2 hutch-db40d346c28800a1eec384a5e4f3d7d090198e4d.zip | |
Merge pull request #32 from krazywarez/sync-man-pages
Sync bundled man page catalog from man.sr.ht (#7)
Diffstat (limited to 'Hutch/Views/More/ManPageCatalog.swift')
| -rw-r--r-- | Hutch/Views/More/ManPageCatalog.swift | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Hutch/Views/More/ManPageCatalog.swift b/Hutch/Views/More/ManPageCatalog.swift new file mode 100644 index 0000000..faff0c5 --- /dev/null +++ b/Hutch/Views/More/ManPageCatalog.swift @@ -0,0 +1,43 @@ +import Foundation + +struct ManPageCatalogEntry: Decodable, Hashable, Identifiable { + let title: String + let url: URL + + var id: String { title } +} + +enum ManPageCatalog { + /// Official sr.ht man pages, loaded from the bundled `man-pages.json` that + /// the scheduled sync workflow keeps in step with man.sr.ht. Falls back to a + /// built-in list if the resource is missing or unreadable, so the browser is + /// never empty. + static func load(bundle: Bundle = .main) -> [ManPageCatalogEntry] { + guard let url = bundle.url(forResource: "man-pages", withExtension: "json"), + let data = try? Data(contentsOf: url), + let entries = try? JSONDecoder().decode([ManPageCatalogEntry].self, from: data), + !entries.isEmpty else { + return fallback + } + return entries + } + + static let fallback: [ManPageCatalogEntry] = [ + entry("builds.sr.ht", "https://man.sr.ht/builds.sr.ht/"), + entry("chat.sr.ht", "https://man.sr.ht/chat.sr.ht/"), + entry("git.sr.ht", "https://man.sr.ht/git.sr.ht/"), + entry("hg.sr.ht", "https://man.sr.ht/hg.sr.ht/"), + entry("hub.sr.ht", "https://man.sr.ht/hub.sr.ht/"), + entry("lists.sr.ht", "https://man.sr.ht/lists.sr.ht/"), + entry("man.sr.ht", "https://man.sr.ht/man.sr.ht/"), + entry("meta.sr.ht", "https://man.sr.ht/meta.sr.ht/"), + entry("paste.sr.ht", "https://man.sr.ht/paste.sr.ht/"), + entry("sr.ht", "https://man.sr.ht/sr.ht/"), + entry("srht.site", "https://srht.site/"), + entry("todo.sr.ht", "https://man.sr.ht/todo.sr.ht/") + ] + + private static func entry(_ title: String, _ urlString: String) -> ManPageCatalogEntry { + ManPageCatalogEntry(title: title, url: URL(string: urlString)!) + } +} |
