Sources/OrgstarSpotlight/ImportExtension.swift

5bb13b85656f8b0461eb4d7208602b9838ef3eb3
orgstar/Sources/OrgstarSpotlight/ImportExtension.swift

17 lines · 815 bytes

 1import CoreSpotlight
 2import Foundation
 3import OrgCore
 4
 5/// Spotlight's importer for org files: the text, plus the title, author, tags and headings.
 6@objc(ImportExtension)
 7final class ImportExtension: CSImportExtension {
 8    override func update(_ attributes: CSSearchableItemAttributeSet, forFileAt contentURL: URL) throws {
 9        let text = try String(contentsOf: contentURL, encoding: .utf8)
10        let summary = FileSummary(text)
11        attributes.textContent = text
12        attributes.title = summary.title ?? contentURL.deletingPathExtension().lastPathComponent
13        if let author = summary.author { attributes.authorNames = [author] }
14        if let description = summary.description { attributes.contentDescription = description }
15        attributes.keywords = summary.tags + summary.headings
16    }
17}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form